add  field for PageDocument.
This will work after merging of
@@ -6,7 +6,6 @@ from django_elasticsearch_dsl import DocType, Index, fields
from elasticsearch import Elasticsearch
from readthedocs.projects.models import HTMLFile, Project
-from readthedocs.sphinx_domains.models import SphinxDomain
project_conf = settings.ES_INDEXES['project']
@@ -35,46 +34,6 @@ class RTDDocTypeMixin:
super().update(*args, **kwargs)
-@domain_index.doc_type
-class SphinxDomainDocument(RTDDocTypeMixin, DocType):
- project = fields.KeywordField(attr='project.slug')
- version = fields.KeywordField(attr='version.slug')
- role_name = fields.KeywordField(attr='role_name')
-
- # For linking to the URL
- doc_name = fields.KeywordField(attr='doc_name')
- anchor = fields.KeywordField(attr='anchor')
-
- # For showing in the search result
- type_display = fields.TextField(attr='type_display')
- doc_display = fields.TextField(attr='doc_display')
-
- # Simple analyzer breaks on `.`,
- # otherwise search results are too strict for this use case
- name = fields.TextField(attr='name', analyzer='simple')
- display_name = fields.TextField(attr='display_name', analyzer='simple')
-
- modified_model_field = 'modified'
-
- class Meta:
- model = SphinxDomain
- fields = ('commit', 'build')
- ignore_signals = True
-
- def get_queryset(self):
- """Overwrite default queryset to filter certain files to index."""
- queryset = super().get_queryset()
-
- excluded_types = [
- {'domain': 'std', 'type': 'doc'},
- {'domain': 'std', 'type': 'label'},
- ]
-
- for exclude in excluded_types:
- queryset = queryset.exclude(**exclude)
- return queryset
-
-
@project_index.doc_type
class ProjectDocument(RTDDocTypeMixin, DocType):
@@ -128,6 +87,24 @@ class PageDocument(RTDDocTypeMixin, DocType):
'content': fields.TextField(),
}
)
+ domains = fields.NestedField(
+ properties={
+ 'role_name': fields.KeywordField(),
+
+ # For linking to the URL
+ 'doc_name': fields.KeywordField(),
+ 'anchor': fields.KeywordField(),
+
+ # For showing in the search result
+ 'type_display': fields.TextField(),
+ 'doc_display': fields.TextField(),
+
+ # Simple analyzer breaks on `.`,
+ # otherwise search results are too strict for this use case
+ 'name': fields.TextField(analyzer='simple'),
+ 'display_name': fields.TextField(analyzer='simple'),
+ }
+ )
modified_model_field = 'modified_date'
@@ -136,6 +113,24 @@ class PageDocument(RTDDocTypeMixin, DocType):
fields = ('commit', 'build')
ignore_signals = True
+ def prepare_domains(self, html_file):
+ """Prepares and returns the values for domains field."""
+ domains_qs = html_file.sphinx_domains.all()
+ domains_qs = domains_qs.exclude(domain='std', type__in=['doc', 'label'])
+
+ all_domains = [{
+ 'role_name': domain.role_name,
+ 'doc_name': domain.doc_name,
+ 'anchor': domain.anchor,
+ 'type_display': domain.type_display,
+ 'doc_display': domain.doc_display,
+ 'name': domain.name,
+ 'display_name': domain.display_name,
+ } for domain in domains_qs]
+
+ return all_domains
+
+
@classmethod
def faceted_search(
cls, query, user, projects_list=None, versions_list=None,
