Skip to content

Refactor search code #5197

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

Merged
merged 52 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
47e3c1a
Reactor search code
ericholscher Jan 29, 2019
a84bb15
Show more results in JS search results
ericholscher Jan 29, 2019
6f36acd
Fix docstring
ericholscher Jan 29, 2019
0bfa998
Fix lint
ericholscher Jan 29, 2019
936465d
Fix tests
ericholscher Jan 29, 2019
0496cf6
Small fixes for search
ericholscher Jan 29, 2019
ab28491
Fix comment.
ericholscher Jan 29, 2019
617f47f
Move to pformat and real logging.
ericholscher Jan 29, 2019
d0f6082
Standardize search result listings
ericholscher Jan 29, 2019
af8a28f
Only request 3 fragments, as that’s all we display
ericholscher Jan 29, 2019
5f197ec
Fix pytest test logic.
ericholscher Jan 29, 2019
465628e
Handle changing newlines to periods.
ericholscher Jan 30, 2019
e3e245c
Fix tests.
ericholscher Jan 30, 2019
e909759
Check for content to highlight
ericholscher Jan 30, 2019
49098d7
Attempt to fix tests agian.
ericholscher Jan 30, 2019
07dc26b
Delete some old code, and remove single function/class files.
ericholscher Jan 30, 2019
e9f3f3f
Fix lint error.
ericholscher Jan 30, 2019
d6d02da
Keep all search views in the search app
ericholscher Jan 30, 2019
336e674
remove need to pass around an index_name
ericholscher Jan 30, 2019
eb65817
Properly filter project search
ericholscher Jan 30, 2019
144ed0e
Refactor the Document and FacetedSearch classes
ericholscher Jan 31, 2019
d314f58
Merge remote-tracking branch 'origin/master' into readd-search-signals
ericholscher Jan 31, 2019
03ad482
Fix lint
ericholscher Jan 31, 2019
5dfc17a
Add TODO for signal handling
ericholscher Feb 4, 2019
fcc9620
Use old value for ELASTICSEARCH_DSL_AUTOSYNC in tests
ericholscher Feb 4, 2019
701ecdb
Update JS file
ericholscher Feb 5, 2019
f636737
Add logging to our search JS to debug
ericholscher Feb 5, 2019
7583f9a
Make log a bit better
ericholscher Feb 5, 2019
747da90
Show the actual result length instead of the API count, since it’s wr…
ericholscher Feb 5, 2019
6c317f1
Update bundle with this change.
ericholscher Feb 5, 2019
e2655de
Remove use of signals in favor of SettingsOverrideObject
ericholscher Feb 5, 2019
f457ff7
Simpler super's
ericholscher Feb 5, 2019
7b2013c
Docstring for some methods/functions and small linting
humitos Feb 5, 2019
0741a25
Fix search lint
ericholscher Feb 5, 2019
85956e0
Comment the proper place
ericholscher Feb 5, 2019
6ac2f35
Merge branch 'readd-search-signals' of github.com:rtfd/readthedocs.or…
humitos Feb 5, 2019
e062191
Merge remote-tracking branch 'origin/master' into readd-search-signals
ericholscher Feb 5, 2019
8e4cc2b
Nicer highlight replacement syntax
ericholscher Feb 5, 2019
8c7bda4
Remove search debug logging.
ericholscher Feb 5, 2019
5b9f460
Use normal user object everywhere.
ericholscher Feb 5, 2019
e2e271b
Merge remote-tracking branch 'origin/readd-search-signals' into readd…
ericholscher Feb 5, 2019
a993f08
Fix typo
ericholscher Feb 5, 2019
d52b968
Use classic JS loop
ericholscher Feb 5, 2019
fc277fa
Update docs
ericholscher Feb 5, 2019
417ea45
Cap operators
ericholscher Feb 5, 2019
80c58c7
Fix lint again
ericholscher Feb 5, 2019
72d867f
Once more with the linting
ericholscher Feb 5, 2019
5f118ff
Change API queryset filter to `public(user)`
ericholscher Feb 6, 2019
e263e69
Small doc fixup
ericholscher Feb 6, 2019
1a3e146
Support filter_user argument for not filtering users in corporate sea…
ericholscher Feb 6, 2019
fab9f42
Address review feedback
ericholscher Feb 6, 2019
0a06726
More cleanup.
ericholscher Feb 6, 2019
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
17 changes: 8 additions & 9 deletions docs/development/search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ By default, Auto Indexing is turned off in development mode. To turn it on, chan
After that, whenever a documentation successfully builds, or project gets added,
the search index will update automatically.


Architecture
------------
The search architecture is devided into 2 parts.
One part is responsible for **indexing** the documents and projects and
the other part is responsible for querying the Index to show the proper results to users.
We use the `django-elasticsearch-dsl`_ package mostly to the keep the search working.

* One part is responsible for **indexing** the documents and projects (`documents.py`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to use the `` here instead of the single one.

* The other part is responsible for **querying** the Index to show the proper results to users (`faceted_search.py`)

We use the `django-elasticsearch-dsl`_ package for our Document abstraction.
`django-elasticsearch-dsl`_ is a wrapper around `elasticsearch-dsl`_ for easy configuration
with Django.

Expand Down Expand Up @@ -72,11 +73,11 @@ and index/delete the documentation content from the `HTMLFile` instances.

How we index projects
~~~~~~~~~~~~~~~~~~~~~

We also index project information in our search index so that the user can search for projects
from the main site. `django-elasticsearch-dsl`_ listen `post_create` and `post_delete` signals of
from the main site. We listen to the `post_create` and `post_delete` signals of
`Project` model and index/delete into Elasticsearch accordingly.


Elasticsearch Document
~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -88,9 +89,7 @@ As per requirements of `django-elasticsearch-dsl`_, it is stored in the
`django-elasticsearch-dsl`_ listens to the `post_save` signal of `Project` model and
then index/delete into Elasticsearch.

**PageDocument**: It is used for indexing documentation of projects. By default, the auto
indexing is turned off by `ignore_signals = settings.ES_PAGE_IGNORE_SIGNALS`.
`settings.ES_PAGE_IGNORE_SIGNALS` is `False` both in development and production.
**PageDocument**: It is used for indexing documentation of projects.
As mentioned above, our `Search` app listens to the `bulk_post_create` and `bulk_post_delete`
signals and indexes/deleted documentation into Elasticsearch. The signal listeners are in
the `readthedocs/search/signals.py` file. Both of the signals are dispatched
Expand Down
2 changes: 0 additions & 2 deletions readthedocs/core/static-src/core/js/doc-embed/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function attach_elastic_search_query(data) {
var total_count = data.count || 0;

if (hit_list.length) {
// console.debug('Read the Docs search got a result. Showing results.');
for (var i = 0; i < hit_list.length; i += 1) {
var doc = hit_list[i];
var highlight = doc.highlight;
Expand Down Expand Up @@ -105,7 +104,6 @@ function attach_elastic_search_query(data) {
},
complete: function (resp, status_code) {
if (status_code !== 'success' || resp.responseJSON.count === 0) {
// console.debug('Read the Docs search failed, skipping loading search content.');
return search_def.reject();
}
return search_def.resolve(resp.responseJSON);
Expand Down
1 change: 1 addition & 0 deletions readthedocs/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def get_highlight(self, obj):


class PageSearchAPIView(generics.ListAPIView):

"""Main entry point to perform a search using Elasticsearch."""

pagination_class = SearchPagination
Expand Down
6 changes: 5 additions & 1 deletion readthedocs/search/faceted_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def query(self, search, query):

# need to search for both 'and' and 'or' operations
# the score of and should be higher as it satisfies both or and and
for operator in ['and', 'or']:
for operator in ['AND', 'OR']:
query_string = SimpleQueryString(
query=query, fields=self.fields, default_operator=operator
)
Expand All @@ -84,18 +84,22 @@ def query(self, search, query):


class PageSearch(SettingsOverrideObject):

"""
Allow this class to be overridden based on CLASS_OVERRIDES setting.

This is primary used on the .com to adjust how we filter our search queries
"""

_default_class = PageSearchBase


class ProjectSearch(SettingsOverrideObject):

"""
Allow this class to be overridden based on CLASS_OVERRIDES setting.

This is primary used on the .com to adjust how we filter our search queries
"""

_default_class = ProjectSearchBase