Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search Document: remove unused class methods #7035

Merged
merged 1 commit into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions readthedocs/search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

from django.conf import settings
from django_elasticsearch_dsl import DocType, Index, fields

from elasticsearch import Elasticsearch

from readthedocs.projects.models import HTMLFile, Project


project_conf = settings.ES_INDEXES['project']
project_index = Index(project_conf['name'])
project_index.settings(**project_conf['settings'])
Expand Down Expand Up @@ -50,19 +48,6 @@ class Meta:
fields = ('name', 'slug', 'description')
ignore_signals = True

@classmethod
def faceted_search(cls, query, user, language=None):
from readthedocs.search.faceted_search import ProjectSearch
kwargs = {
'user': user,
'query': query,
}

if language:
kwargs['filters'] = {'language': language}

return ProjectSearch(**kwargs)


@page_index.doc_type
class PageDocument(RTDDocTypeMixin, DocType):
Expand Down Expand Up @@ -148,28 +133,6 @@ def prepare_domains(self, html_file):

return all_domains

@classmethod
def faceted_search(
cls, query, user, projects_list=None, versions_list=None,
filter_by_user=True
):
from readthedocs.search.faceted_search import PageSearch
kwargs = {
'user': user,
'query': query,
'filter_by_user': filter_by_user,
}

filters = {}
if projects_list is not None:
filters['project'] = projects_list
if versions_list is not None:
filters['version'] = versions_list

kwargs['filters'] = filters

return PageSearch(**kwargs)

def get_queryset(self):
"""Overwrite default queryset to filter certain files to index."""
queryset = super().get_queryset()
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/search/tests/test_faceted_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from readthedocs.search.documents import PageDocument
from readthedocs.search.faceted_search import PageSearch


@pytest.mark.django_db
Expand All @@ -21,7 +21,7 @@ def test_search_exact_match(self, client, project, case):
cased_query = getattr(query_text, case)
query = cased_query()

page_search = PageDocument.faceted_search(query=query, user='')
page_search = PageSearch(query=query, user='')
results = page_search.execute()

assert len(results) == 1
Expand All @@ -37,7 +37,7 @@ def test_search_combined_result(self, client, project):
- Where `Foo` or `Bar` is present
"""
query = 'Elasticsearch Query'
page_search = PageDocument.faceted_search(query=query, user='')
page_search = PageSearch(query=query, user='')
results = page_search.execute()
assert len(results) == 3

Expand Down
4 changes: 2 additions & 2 deletions readthedocs/search/tests/test_xss.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from readthedocs.search.documents import PageDocument
from readthedocs.search.faceted_search import PageSearch


@pytest.mark.django_db
Expand All @@ -9,7 +9,7 @@ class TestXSS:

def test_facted_page_xss(self, client, project):
query = 'XSS'
page_search = PageDocument.faceted_search(query=query, user='')
page_search = PageSearch(query=query, user='')
results = page_search.execute()
expected = """
&lt;h3&gt;<span>XSS</span> exploit&lt;&#x2F;h3&gt;
Expand Down