class MeetingDoc(Document):
    id = fields.IntegerField()
    title = fields.StringField()
    description = fields.TextField()
    venue = fields.StringField()
    start_date = fields.DateField()
    start_time = fields.KeywordField(attr='start_time_str')
    end_time = fields.KeywordField(attr='end_time_str')
    materials = fields.NestedField(
        properties={
            'id': fields.IntegerField(),
            'download_url': fields.KeywordField(),
            'name': fields.KeywordField(),
        })

    class Index:
        name = mcs.ELASTICSEARCH_INDEX_NAMES['meetings']
        settings = mcs.ELASTICSEARCH_DSL_INDEX_SETTINGS

    class Django:
        model = Meeting
        related_models = [
            MeetingFile,
        ]

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, MeetingFile):
            return related_instance.meeting

    def get_queryset(self):
        return super().get_queryset().published()
Esempio n. 2
0
class SurveyDocument(DocType):
    categories = fields.NestedField(
        properties={
            'name': fields.TextField(),
            'order': fields.IntegerField(),
            'description': fields.TextField(),
        })
    questions = fields.NestedField(
        properties={
            'text': fields.TextField(),
            'order': fields.IntegerField(),
            'required': fields.BooleanField(),
            'type': fields.TextField(),
            'choices': fields.TextField(),
        })
    responses = fields.NestedField(properties={
        'interview_uuid': fields.TextField(),
    })

    class Meta:
        model = Survey
        fields = ['name', 'description', 'is_published', 'need_logged_user']
        related_models = [Category, Question, Response]

    def get_instances_from_related(self, related_instance):
        return self
Esempio n. 3
0
class RaceResult(Document):
    # runner info
    runner_age = fields.IntegerField(attr="runner_age_during_race")
    best_ten_run_in_hours = fields.DoubleField()
    runner_sex = fields.StringField(attr="runner.sex")
    # race info
    itra_point = fields.IntegerField(attr="prediction_race.itra")
    refreshment_points = fields.IntegerField(
        attr="prediction_race.refreshment_points")
    max_time = fields.IntegerField(attr="prediction_race.max_time")
    month_of_the_race = fields.StringField(
        attr="prediction_race.month_of_the_race")
    distance = fields.StringField(attr="prediction_race.distance")
    ascent = fields.StringField(attr="prediction_race.ascent")
    descent = fields.StringField(attr="prediction_race.descent")
    # result info
    time_result_in_hours = fields.DoubleField(attr="time_result_in_hours")
    position = fields.IntegerField(attr="position")

    def prepare_best_ten_run_in_hours(self, instance):
        if instance.best_10km_run_before_prediction_race:
            hours = Decimal(
                instance.best_10km_run_before_prediction_race.seconds / 3600)
            return round(hours, 2)
        else:
            return None

    class Index:
        name = "race_results"
        settings = {"number_of_shards": 1, "number_of_replicas": 0}

    class Django:
        model = models.PredictionRaceResult
def datasets_field(**kwargs):
    return fields.NestedField(properties={
        'id':
        fields.IntegerField(),
        'title':
        TranslatedTextField('title'),
        'notes':
        TranslatedTextField('notes'),
        'category':
        fields.KeywordField(attr='category.title'),
        'formats':
        fields.KeywordField(attr='formats', multi=True),
        'downloads_count':
        fields.IntegerField(attr='computed_downloads_count'),
        'views_count':
        fields.IntegerField(attr='computed_views_count'),
        'openness_scores':
        fields.IntegerField(attr='openness_scores'),
        'modified':
        fields.DateField(),
        'slug':
        TranslatedKeywordField('slug'),
        'verified':
        fields.DateField(),
    },
                              **kwargs)
Esempio n. 5
0
class PersonDocument(BaseDocument):
    profile_image = es_fields.TextField(attr='profile_image_indexing')
    user_reputation = es_fields.IntegerField(attr='user_reputation_indexing')
    author_score = es_fields.IntegerField(attr='author_score')
    description = es_fields.TextField(attr='description',
                                      analyzer=content_analyzer)
    full_name = es_fields.TextField(attr='full_name',
                                    analyzer=content_analyzer)
    person_types = es_fields.KeywordField(attr='person_types_indexing')
    headline = es_fields.ObjectField(attr='headline',
                                     properties={
                                         'title': es_fields.TextField(),
                                     })

    class Index:
        name = 'person'

    class Django:
        model = Author
        fields = [
            'id',
            'first_name',
            'last_name',
        ]

    def should_remove_from_index(self, obj):
        should_delete = False
        try:
            author_user = User.objects.get(id=obj.user_id)
            if author_user.is_suspended:
                should_delete = True
        except Exception as e:
            pass

        return should_delete
Esempio n. 6
0
class UserDocument(Document):
    id = fields.IntegerField()
    username = fields.TextField(fields={
        'raw': fields.KeywordField(),
        'suggest': fields.CompletionField(),
    }, )
    username_color = fields.KeywordField()
    role = fields.IntegerField(attr='role_id')
    role_icon = fields.IntegerField(attr='icon')
    active_badge = fields.IntegerField(attr='badge')
    custom_images = fields.IntegerField(attr='custom_images_indexing',
                                        multi=True)

    class Index:
        name = 'user'

    class Django:
        model = User
        related_models = Image,

    def get_queryset(self):
        return super().get_queryset().select_related(
            'role').prefetch_related_images()

    @staticmethod
    def get_instances_from_related(related_instance) -> (list, None):
        if related_instance.is_icon:
            return related_instance.icon_owners.values_list('id', flat=True)
        if related_instance.is_custom:
            return related_instance.custom_owners.values_list('id', flat=True)
Esempio n. 7
0
class ExperimentDocument(Document):
    class Index:
        name = 'experiments'
        settings = {'number_of_shards': 1, 'number_of_replicas': 0}

    id = fields.IntegerField()
    title = fields.TextField(fields={'raw': fields.KeywordField()},
                             analyzer=analyzer)
    description = fields.TextField(fields={'raw': fields.KeywordField()},
                                   analyzer=analyzer)
    public_access = fields.IntegerField()
    created_time = fields.DateField()
    start_time = fields.DateField()
    end_time = fields.DateField()
    update_time = fields.DateField()
    institution_name = fields.StringField()
    created_by = fields.ObjectField(properties={
        'username':
        fields.StringField(fields={'raw': fields.KeywordField()}, )
    })
    objectacls = fields.ObjectField(properties={
        'pluginId': fields.StringField(),
        'entityId': fields.StringField()
    })

    class Django:
        model = Experiment
        related_models = [User, ObjectACL]

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, User):
            return related_instance.experiment_set.all()
        if isinstance(related_instance, ObjectACL):
            return related_instance.content_object
        return None
Esempio n. 8
0
class ReferenceDocument(DocType):
    pk = fields.IntegerField(attr='pk')
    sid = fields.IntegerField(attr='sid')
    pmid = string_field(attr='pmid')
    study = ObjectField(properties={
        "pk": fields.IntegerField(),
        "name": string_field('name'),
    })
    name = string_field("name")
    doi = string_field("doi")
    title = string_field("title")
    abstract = text_field("abstract")
    journal = text_field("journal")
    date = fields.DateField()
    pdf = fields.FileField(fielddata=True)

    authors = ObjectField(properties={
        'first_name': string_field("first_name"),
        'last_name': string_field("last_name"),
        'pk': fields.IntegerField(),
    })

    class Meta(object):
        model = Reference
        # Ignore auto updating of Elasticsearch when a model is saved
        # or deleted:
        ignore_signals = True
        # Don't perform an index refresh after every update (overrides global setting):
        auto_refresh = False
Esempio n. 9
0
class ApplicationsDoc(DocType):
    id = fields.IntegerField()
    slug = TranslatedKeywordField('slug')
    title = TranslatedTextField(
        'title', common_params={'suggest': fields.CompletionField()})
    notes = TranslatedTextField('notes')

    author = fields.KeywordField()

    url = fields.KeywordField()

    image_url = fields.KeywordField(attr='image_url')
    image_thumb_url = fields.KeywordField(attr='image_thumb_url')

    datasets = datasets_field(attr='published_datasets')
    users_following = fields.KeywordField(attr='users_following_list',
                                          multi=True)

    tags = TranslatedKeywordsList(attr='tags_list')

    views_count = fields.IntegerField()
    status = fields.KeywordField()
    modified = fields.DateField()
    created = fields.DateField()

    class Meta:
        doc_type = 'application'
        model = Application

    def get_queryset(self):
        return self._doc_type.model.objects.filter(status='published')
class ProductDocument(DocType):

  id = fields.IntegerField(attr='id')

  title = fields.StringField(
    analyzer=html_strip,
    fields={
      'raw': fields.StringField(analyzer='keyword'),
    }
  )

  store = fields.IntegerField(
    attr='store_indexing',
    # analyzer=html_strip,
  )

  # store = NestedField(properties={
  #   'id': IntegerField(),
  #   'title': StringField(),
  # })

  class Meta:
    model = Product

    related_models = [Store]
  
  def get_instances_from_related(self, related_instance):
    if isinstance(related_instance, Store):
      return related_instance.product_set.all()
Esempio n. 11
0
class CompanyDocument(DocType):
    # ID
    id = fields.IntegerField(attr='id')
    avatar = fields.TextField()
    slug = fields.StringField()
    name = StringField(analyzer=html_strip, fields={
        'raw': KeywordField(),
    })

    about = fields.TextField()
    headquarter = fields.TextField()
    is_address_public = fields.BooleanField()
    website = fields.StringField()
    since = fields.StringField()
    size_from = fields.IntegerField()
    size_to = fields.IntegerField()
    creator = fields.ObjectField(attr='create_field_indexing',
                                 properties={'id': fields.IntegerField()})
    tags = fields.ObjectField(attr='tag_field_indexing',
                              properties={
                                  'id': fields.IntegerField(),
                                  'name': fields.StringField()
                              })

    class Django:
        model = Company
Esempio n. 12
0
class IndividualDocument(Document):
    """Individual elastic search document"""
    pk = fields.IntegerField(attr='pk')
    name = string_field('name')
    group = ObjectField(
        properties={
            'name': string_field('name'),
            'pk': fields.IntegerField('pk'),
            'count': fields.IntegerField('count')
        })
    study = string_field('study_name')
    ex = ObjectField(properties={'pk': fields.IntegerField('pk')})
    characteristica_all_normed = characteristica_object_field
    access = string_field('access')
    allowed_users = fields.ObjectField(
        attr="allowed_users",
        properties={'username': string_field("username")},
        multi=True)

    class Django:
        model = Individual
        # Ignore auto updating of Elasticsearch when a model is saved/deleted
        ignore_signals = True
        # Don't perform an index refresh after every update
        auto_refresh = False

    class Index:
        name = 'individuals'
        settings = elastic_settings
Esempio n. 13
0
class CompetitionDocument(DocType):
    class Meta:
        model = Competition

    remote_id = fields.IntegerField()
    created_by = fields.TextField()
    title = fields.TextField()
    description = fields.TextField()
    html_text = fields.TextField()

    participant_count = fields.IntegerField()
    is_active = fields.BooleanField()
    prize = fields.IntegerField()
    current_phase_deadline = fields.DateField()
    url = fields.TextField()
    logo = fields.TextField()

    start = fields.DateField()
    end = fields.DateField()

    producer = fields.ObjectField(properties={
        'id': fields.IntegerField(),
        'url': fields.TextField(),
        'name': fields.TextField()
    })

    # TODO: add "active" boolean field so we can add this to queries and not have a special case

    def prepare_created_by(self, instance):
        return instance.created_by
Esempio n. 14
0
class ExperimentDocument(Document):
    """ Our Experiment ElasticSearch Document, which
    corresponds to our Experiment model. """

    # Keyword Fields
    title = fields.TextField(analyzer=html_strip,
                             fielddata=True,
                             fields={"raw": fields.KeywordField()})
    publication_title = fields.TextField(analyzer=html_strip,
                                         fielddata=True,
                                         fields={"raw": fields.KeywordField()})
    description = fields.TextField(analyzer=html_strip,
                                   fielddata=True,
                                   fields={"raw": fields.KeywordField()})
    publication_authors = fields.TextField(
        analyzer=html_strip,
        fielddata=True,
        fields={"raw": fields.KeywordField()})
    technology = fields.TextField(analyzer=html_strip_no_stop,
                                  fielddata=True,
                                  fields={"raw": fields.KeywordField()})
    organism_names = fields.TextField(analyzer=html_strip_no_ngram,
                                      fielddata=True,
                                      fields={"raw": fields.KeywordField()})
    platform_names = fields.TextField(analyzer=standard_keyword,
                                      fielddata=True,
                                      fields={"raw": fields.TextField()})
    platform_accession_codes = fields.TextField(
        analyzer=standard_keyword,
        fielddata=True,
        fields={"raw": fields.TextField()})

    # Basic Fields
    accession_code = fields.KeywordField()
    alternate_accession_code = fields.KeywordField()
    submitter_institution = fields.TextField()
    publication_doi = fields.TextField()
    has_publication = fields.BooleanField()
    sample_metadata_fields = fields.TextField()
    pubmed_id = fields.TextField()
    num_total_samples = fields.IntegerField()
    num_processed_samples = fields.IntegerField()
    num_downloadable_samples = fields.IntegerField()
    source_first_published = fields.DateField()

    # Index all downloadable samples as keywords so that we can calculate unique counts on the facets
    downloadable_samples = fields.ListField(fields.KeywordField())

    class Django:
        model = Experiment
        parallel_indexing = True
        queryset_pagination = 3000

        fields = [
            "id",
        ]

    def get_queryset(self):
        """ Override default queryset """
        return super(ExperimentDocument, self).get_queryset().order_by("id")
Esempio n. 15
0
class HubDocument(BaseDocument):
    auto_refresh = True

    paper_count = es_fields.IntegerField(attr='paper_count')
    subscriber_count = es_fields.IntegerField(attr='subscriber_count')
    discussion_count = es_fields.IntegerField(attr='discussion_count')
    description = es_fields.TextField(attr='description',
                                      analyzer=content_analyzer)
    name = es_fields.TextField(attr='name', analyzer=title_analyzer)

    class Index:
        name = 'hub'

    class Django:
        model = Hub
        fields = [
            'id',
            'acronym',
            'is_locked',
        ]

    def should_remove_from_index(self, obj):
        if obj.is_removed or obj.is_locked:
            return True

        return False
Esempio n. 16
0
class TranscriptionDocument(Document):
    class Index:
        # Name of the Elasticsearch index
        name = "transcriptions"
        # See Elasticsearch Indices API reference for available settings
        settings = {"number_of_shards": 1, "number_of_replicas": 0}

    asset = fields.ObjectField(
        properties={
            "title": fields.TextField(),
            "slug": fields.TextField(),
            "transcription_status": fields.KeywordField(),
            "item": fields.ObjectField(
                properties={
                    "item_id": fields.TextField(),
                    "project": fields.ObjectField(
                        properties={
                            "slug": fields.KeywordField(),
                            "campaign": fields.ObjectField(
                                properties={"slug": fields.KeywordField()}
                            ),
                            "topics": fields.NestedField(
                                properties={"slug": fields.KeywordField()}
                            ),
                        }
                    ),
                }
            ),
        }
    )
    user = fields.ObjectField(properties={"id": fields.IntegerField()})
    reviewed_by = fields.ObjectField(properties={"id": fields.IntegerField()})
    supersedes = fields.ObjectField(properties={"id": fields.IntegerField()})

    class Django:
        model = Transcription

        fields = [
            "id",
            "created_on",
            "updated_on",
            "text",
            "accepted",
            "rejected",
            "submitted",
        ]

    def get_queryset(self):
        return (
            super()
            .get_queryset()
            .order_by("pk")
            .prefetch_related(
                "asset__item",
                "asset__item__project",
                "asset__item__project__topics",
                "asset__item__project__campaign",
            )
        )
Esempio n. 17
0
def files_field(**kwargs):
    return fields.NestedField(properties={
        'download_url': fields.TextField(),
        'file_size': fields.IntegerField(),
        'openness_score': fields.IntegerField(),
        'format': fields.TextField()
    },
                              **kwargs)
Esempio n. 18
0
class GroupDocument(Document):
    city = fields.ObjectField(properties={"id": fields.IntegerField()})
    club = fields.ObjectField(properties={"id": fields.IntegerField()})
    sports = fields.NestedField(properties={"id": fields.IntegerField()})

    class Django:
        model = Group
        fields = ["id", "name", "description", "cover_photo", "contact_email"]
Esempio n. 19
0
class PublicBodyDocument(DocType):
    name = fields.TextField(
        fields={'raw': fields.KeywordField()},
        analyzer=analyzer,
    )
    name_auto = fields.TextField(attr='all_names', analyzer=ngram_analyzer)
    content = fields.TextField(analyzer=analyzer)

    jurisdiction = fields.IntegerField(attr='jurisdiction_id')

    classification = fields.ListField(fields.IntegerField())
    categories = fields.ListField(fields.IntegerField())
    regions = fields.ListField(fields.IntegerField())
    regions_exact = fields.ListField(fields.IntegerField())
    regions_kind = fields.ListField(fields.KeywordField())

    class Meta:
        model = PublicBody
        queryset_chunk_size = 100

    def get_queryset(self):
        """Not mandatory but to improve performance we can select related in one sql request"""
        return super().get_queryset().select_related(
            'jurisdiction').prefetch_related('classification', 'categories',
                                             'regions')

    def prepare_content(self, obj):
        content = [
            obj.name, obj.other_names,
            obj.jurisdiction.name if obj.jurisdiction else '', obj.email or '',
            obj.description, obj.contact, obj.address, obj.url,
            obj.classification.name if obj.classification else ''
        ] + [o.name for o in obj.categories.all()]
        return ' '.join(c for c in content if c)

    def prepare_classification(self, obj):
        if obj.classification is None:
            return []
        return [obj.classification.id
                ] + [c.id for c in obj.classification.get_ancestors()]

    def prepare_categories(self, obj):
        cats = obj.categories.all()
        return [o.id for o in cats
                ] + [c.id for o in cats for c in o.get_ancestors()]

    def prepare_regions(self, obj):
        regs = obj.regions.all()
        return [o.id for o in regs
                ] + [c.id for o in regs for c in o.get_ancestors()]

    def prepare_regions_exact(self, obj):
        regs = obj.regions.all()
        return [o.id for o in regs]

    def prepare_regions_kind(self, obj):
        regs = obj.regions.all()
        return [o.kind for o in regs]
Esempio n. 20
0
class ApplicationsDoc(DocType):
    id = fields.IntegerField()
    slug = fields.KeywordField()
    title = fields.TextField(
        analyzer=polish_analyzer,
        fields={
            'raw': fields.KeywordField(),
            'suggest': fields.CompletionField()
        }
    )
    notes = fields.TextField(
        analyzer=polish_analyzer,
        fields={
            'raw': fields.KeywordField(),
        }
    )

    author = fields.TextField(
        analyzer=standard_analyzer,
        fields={
            'raw': fields.KeywordField(),
            # TODO: fix author data before this
            # 'suggest': fields.CompletionField()
        }
    )

    url = fields.KeywordField()

    image_url = fields.KeywordField(
        attr='image_url'
    )

    datasets = datasets_field(attr='published_datasets')
    users_following = fields.KeywordField(attr='users_following_list', multi=True)

    tags = fields.KeywordField(attr='tags_list', multi=True)

    views_count = fields.IntegerField()
    status = fields.KeywordField()
    modified = fields.DateField()
    created = fields.DateField()

    class Meta:
        doc_type = 'application'
        model = Application
        related_models = [Tag, Dataset, UserFollowingApplication]

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, UserFollowingApplication):
            return related_instance.follower.followed_applications.all()
        if isinstance(related_instance, Dataset):
            return related_instance.applications.all()
        if isinstance(related_instance, Tag):
            return related_instance.applications.all()

    def get_queryset(self):
        return self._doc_type.model.objects.filter(status='published')
Esempio n. 21
0
class ThreadDocument(Document):
    comment_count = es_fields.IntegerField(attr='comment_count_indexing')
    # TODO: Make this a nested user field with author inside
    created_by_author_profile = es_fields.ObjectField(
        attr='created_by_author_profile_indexing',
        properties={
            'id': es_fields.IntegerField(),
            'first_name': es_fields.TextField(),
            'last_name': es_fields.TextField(),
        }
    )
    paper = es_fields.IntegerField(attr='paper_indexing')
    paper_title = es_fields.TextField(
        attr='paper_title_indexing',
        analyzer=title_analyzer
    )
    score = es_fields.IntegerField(attr='score_indexing')
    plain_text = es_fields.TextField()
    title = es_fields.TextField(analyzer=title_analyzer)

    class Index:
        name = 'discussion_thread'

    class Django:
        model = Thread
        fields = [
            'id',
            'created_date',
            'updated_date',
            'is_public',
            'is_removed',
        ]

        # Ignore auto updating of Elasticsearch when a model is saved
        # or deleted (defaults to False):
        ignore_signals = (TESTING is True) or (
            ELASTICSEARCH_AUTO_REINDEX is False
        )

        # Don't perform an index refresh after every update (False overrides
        # global setting of True):
        auto_refresh = (TESTING is False) or (
            ELASTICSEARCH_AUTO_REINDEX is True
        )

        # Paginate the django queryset used to populate the index with the
        # specified size (by default it uses the database driver's default
        # setting)
        # queryset_pagination = 5000

    def update(self, *args, **kwargs):
        try:
            super().update(*args, **kwargs)
        except ConnectionError as e:
            sentry.log_info(e)
        except Exception as e:
            sentry.log_info(e)
Esempio n. 22
0
class ArticleDocument(Document):
    title = fields.TextField(
        fields={'raw': fields.KeywordField()},
        analyzer=analyzer,
    )
    url = fields.TextField(
        fields={'raw': fields.KeywordField()},
        analyzer=analyzer,
    )
    description = fields.TextField(
        fields={'raw': fields.KeywordField()},
        analyzer=analyzer,
    )
    start_publication = fields.DateField()
    author = fields.ListField(fields.IntegerField())
    category = fields.ListField(fields.IntegerField())

    content = fields.TextField(analyzer=analyzer,
                               search_analyzer=search_analyzer,
                               search_quote_analyzer=search_quote_analyzer,
                               index_options='offsets')

    special_signals = True

    class Django:
        model = Article
        queryset_chunk_size = 100

    def get_queryset(self):
        return Article.published.all()

    def prepare_content(self, obj):
        html = obj.get_html_content()
        return ' '.join([obj.title, obj.description,
                         strip_tags(html)] +
                        [o.title for o in obj.categories.all()] +
                        [t.name for t in obj.tags.all()])

    def prepare_description(self, obj):
        return strip_tags(obj.description)

    def prepare_url(self, obj):
        return obj.get_absolute_url()

    def prepare_title(self, obj):
        return obj.title

    def prepare_start_publication(self, obj):
        return obj.start_publication

    def prepare_category(self, obj):
        cats = obj.categories.all()
        return [o.id for o in cats]

    def prepare_author(self, obj):
        authors = obj.authors.all()
        return [o.id for o in authors]
class RepositoryExampleDocument(Document):
    time_based = False

    repository_version_language = fields.ObjectField(
        properties={
            "pk": fields.IntegerField(),
            "language": fields.TextField(fields={"raw": fields.KeywordField()}),
        }
    )
    intent = fields.ObjectField(
        properties={"text": fields.TextField(fields={"raw": fields.KeywordField()})}
    )
    entities = fields.NestedField(
        properties={
            "entity": fields.ObjectField(
                properties={
                    "value": fields.TextField(fields={"raw": fields.KeywordField()}),
                }
            ),
        }
    )
    pk = fields.IntegerField()

    class Django:
        model = RepositoryExample
        fields = [
            "id",
            "text",
        ]
        related_models = [
            RepositoryVersionLanguage,
            RepositoryIntent,
            RepositoryExampleEntity,
        ]

    def get_queryset(self):
        return (
            super(RepositoryExampleDocument, self)
            .get_queryset()
            .select_related(
                "repository_version_language",
                "intent",
            )
            .prefetch_related(
                "entities",
                "translations",
            )
        )

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, RepositoryVersionLanguage):
            return related_instance.added.all()
        elif isinstance(related_instance, RepositoryIntent):
            return related_instance.repositoryexample_set.all()
        elif isinstance(related_instance, RepositoryExampleEntity):
            return related_instance.repository_example
Esempio n. 24
0
class BookDocument(Document):
    """Book Elasticsearch document."""

    id = fields.IntegerField(attr='id')
    title = fields.TextField(fields={
        'raw': fields.KeywordField(),
    })
    description = fields.TextField(fields={
        'raw': fields.KeywordField(),
    })

    summary = fields.TextField(fields={
        'raw': fields.KeywordField(),
    })

    publisher = fields.KeywordField(
        attr='publisher_indexing',
        #analyzer=html_strip,
        # fields={
        #     'raw': fields.KeywordField(analyzer='keyword'),
        # }
    )

    publication_date = fields.DateField()

    state = fields.TextField(fields={
        'raw': fields.KeywordField(),
    })

    isbn = fields.KeywordField(
        #analyzer=html_strip,
        # fields={
        #     'raw': fields.KeywordField(analyzer='keyword'),
        # }
    )

    price = fields.FloatField()

    pages = fields.IntegerField()

    stock_count = fields.IntegerField()

    tags = fields.KeywordField(
        attr='tags_indexing',
        #analyzer=html_strip,
        # fields={
        #     'raw': fields.KeywordField(analyzer='keyword', multi=True),
        #     'suggest': fields.CompletionField(multi=True),
        # },
        multi=True)

    class Django(object):
        """Inner nested class Django."""

        model = Book  # The model associate with this Document
Esempio n. 25
0
class OutputInterventionDocument(Document):
    study_sid = string_field('study_sid')
    study_name = string_field('study_name')
    output_pk = fields.IntegerField('output_pk')
    intervention_pk = fields.IntegerField('intervention_pk')
    group_pk = fields.IntegerField('group_pk')
    individual_pk = fields.IntegerField('individual_pk')

    measurement_type = string_field("measurement_type")
    substance = string_field("substance")
    normed = fields.BooleanField()
    calculated = fields.BooleanField()
    tissue = string_field('tissue')
    time = fields.FloatField('time')
    time_unit = string_field('time_unit')
    unit = string_field('unit')
    choice = string_field('choice')

    # output fields
    value = fields.FloatField('value')
    mean = fields.FloatField('mean')
    median = fields.FloatField('median')
    min = fields.FloatField('min')
    max = fields.FloatField('max')
    se = fields.FloatField('se')
    sd = fields.FloatField('sd')
    cv = fields.FloatField('cv')

    # for permissions
    access = string_field('access')
    allowed_users = fields.ObjectField(
        attr="allowed_users",
        properties={'username': string_field("username")},
        multi=True)

    class Django:
        model = OutputIntervention
        # Ignore auto updating of Elasticsearch when a model is saved/deleted
        ignore_signals = True
        # Don't perform an index refresh after every update
        auto_refresh = False

    class Index:
        name = 'outputs_interventions'
        settings = {
            'number_of_shards': 5,
            'number_of_replicas': 1,
            'max_result_window': 100000
        }

    def get_queryset(self):
        """Not mandatory but to improve performance we can select related in one sql request"""
        return super(OutputInterventionDocument,
                     self).get_queryset().select_related(
                         'intervention', 'output')
Esempio n. 26
0
class ArticleDoc(DocType):
    id = fields.IntegerField()
    slug = fields.KeywordField()
    title = fields.TextField(analyzer=polish_analyzer,
                             fields={
                                 'raw': fields.KeywordField(),
                                 'suggest': fields.CompletionField()
                             })
    notes = fields.TextField(analyzer=polish_analyzer,
                             fields={
                                 'raw': fields.TextField(),
                             })

    author = fields.TextField(
        analyzer=standard_analyzer,
        fields={
            'raw': fields.KeywordField(),
            # TODO: fix author data before this
            # 'suggest': fields.CompletionField()
        })

    datasets = datasets_field(attr='published_datasets')
    license = fields.NestedField(
        properties={
            'id': fields.IntegerField(),
            'name': fields.TextField(),
            'title': fields.TextField(),
            'url': fields.TextField()
        })

    tags = fields.KeywordField(attr='tags_list', multi=True)
    views_count = fields.IntegerField()
    users_following = fields.KeywordField(attr='users_following_list',
                                          multi=True)
    status = fields.TextField()
    modified = fields.DateField()
    created = fields.DateField()

    class Meta:
        doc_type = 'article'
        model = Article
        related_models = [Tag, Dataset, UserFollowingArticle]

    def get_instances_from_related(self, related_instance):
        if isinstance(related_instance, UserFollowingArticle):
            return related_instance.follower.followed_applications.all()
        if isinstance(related_instance, Dataset):
            return related_instance.articles.all()
        if isinstance(related_instance, Tag):
            return related_instance.articles.all()

    def get_queryset(self):
        return self._doc_type.model.objects.filter(
            status__in=['published', 'draft'])
Esempio n. 27
0
class CharacteristicaDocument(DocType):
    """Characteristica elastic search document"""
    id = fields.IntegerField(attr='id')

    group_name = fields.StringField(attr='group_name',
                                    fields={
                                        'raw':
                                        fields.StringField(analyzer='keyword'),
                                    })

    group_pk = fields.IntegerField(attr='group_id')

    individual_name = fields.StringField(
        attr='individual_name',
        fields={
            'raw': fields.StringField(analyzer='keyword'),
        })
    individual_pk = fields.IntegerField(attr='individual_id')

    category = fields.StringField(attr='category_key',
                                  fields={
                                      'raw':
                                      fields.StringField(analyzer='keyword'),
                                  })

    choice = fields.StringField(fields={
        'raw': fields.StringField(analyzer='keyword'),
    })

    unit = fields.StringField(fields={
        'raw': fields.StringField(analyzer='keyword'),
    })

    count = fields.IntegerField()
    value = fields.FloatField(attr='value')
    mean = fields.FloatField(attr='mean')
    median = fields.FloatField(attr='median')
    min = fields.FloatField(attr='min')
    max = fields.FloatField(attr='max')
    se = fields.FloatField(attr='se')
    sd = fields.FloatField(attr='sd')
    cv = fields.FloatField(attr='cv')

    normed = fields.BooleanField()
    raw = ObjectField(properties={'pk': fields.IntegerField()})

    class Meta:
        model = Characteristica
        # Ignore auto updating of Elasticsearch when a model is saved
        # or deleted:
        ignore_signals = True
        # Don't perform an index refresh after every update (overrides global setting):
        auto_refresh = False
Esempio n. 28
0
class ArticleDocument(DocType):
    title = fields.TextField(
        fields={'raw': fields.KeywordField()},
        analyzer=analyzer,
    )
    url = fields.TextField(
        fields={'raw': fields.KeywordField()},
        analyzer=analyzer,
    )
    description = fields.TextField(
        fields={'raw': fields.KeywordField()},
        analyzer=analyzer,
    )
    start_publication = fields.DateField()
    author = fields.ListField(fields.IntegerField())
    category = fields.ListField(fields.IntegerField())

    content = fields.TextField(
        analyzer=analyzer
    )

    special_signals = True

    class Meta:
        model = Article
        queryset_chunk_size = 100

    def get_queryset(self):
        return Article.published.all()

    def prepare_content(self, obj):
        html = obj.get_html_content()
        return strip_tags(html)

    def prepare_description(self, obj):
        return strip_tags(obj.description)

    def prepare_url(self, obj):
        return obj.get_absolute_url()

    def prepare_title(self, obj):
        return obj.title

    def prepare_start_publication(self, obj):
        return obj.start_publication

    def prepare_category(self, obj):
        cats = obj.categories.all()
        return [o.id for o in cats]

    def prepare_author(self, obj):
        authors = obj.authors.all()
        return [o.id for o in authors]
Esempio n. 29
0
class MovieDocument(Document):
    """Movie Elasticsearch document."""

    id = fields.IntegerField(attr="id")

    title = fields.TextField(
        fields={
            "raw": fields.TextField(analyzer="keyword"),
            "suggest": fields.CompletionField(),
        }
    )
    description = fields.TextField(
        fields={
            "raw": fields.TextField(analyzer="keyword"),
        }
    )
    director = fields.TextField(
        fields={
            "raw": fields.TextField(analyzer="keyword"),
        }
    )
    year = fields.IntegerField()
    poster = fields.TextField()
    imdb_rating = fields.FloatField()
    rating_average = fields.FloatField()
    rating_count = fields.IntegerField()
    view_count = fields.IntegerField()
    slug = fields.TextField(
        fields={
            "raw": fields.TextField(analyzer="keyword"),
        }
    )
    genres = fields.TextField(
        attr="genres_indexing",
        fields={
            "raw": fields.TextField(analyzer="keyword", multi=True),
        },
        multi=True,
    )

    class Index:
        # Name of the Elasticsearch index
        name = "movie"
        # See Elasticsearch Indices API reference for available settings
        settings = {"number_of_shards": 1, "number_of_replicas": 0}

    class Django:
        Movie = get_movie_model()
        model = Movie

    class Meta:
        Movie = get_movie_model()
        model = Movie
Esempio n. 30
0
class MessageDocument(Document):
    id = fields.IntegerField()
    broadcast = fields.IntegerField(attr='broadcast_id')
    author = fields.IntegerField(attr='author_id')
    deleter = fields.IntegerField(attr='deleter_id')

    class Index:
        name = 'message'

    class Django:
        model = Message
        fields = 'text', 'created', 'updated'