-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Search: allow to search on different versions of subprojects #7634
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
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9cacb2c
Search: refactor api view
stsewd 765ebec
Search: refactor api view
stsewd c908174
Search: allow to search on different versions of subprojects
stsewd e5c0337
Search: refactor api view
stsewd 2ff01d5
Merge branch 'refactor-search-view' into search-subprojects
stsewd 628edad
Put under feature flag
stsewd 2f4af17
Merge branch 'master' into search-subprojects
stsewd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
MultiMatch, | ||
Nested, | ||
SimpleQueryString, | ||
Term, | ||
Wildcard, | ||
) | ||
|
||
|
@@ -35,12 +36,23 @@ class RTDFacetedSearch(FacetedSearch): | |
'post_tags': ['</span>'], | ||
} | ||
|
||
def __init__(self, query=None, filters=None, user=None, use_advanced_query=True, **kwargs): | ||
def __init__( | ||
self, | ||
query=None, | ||
filters=None, | ||
projects=None, | ||
user=None, | ||
use_advanced_query=True, | ||
**kwargs, | ||
): | ||
""" | ||
Pass in a user in order to filter search results by privacy. | ||
|
||
If `use_advanced_query` is `True`, | ||
force to always use `SimpleQueryString` for the text query object. | ||
:param projects: A dictionary of project slugs mapped to a `VersionData` object. | ||
Results are filter with these values. | ||
|
||
:param use_advanced_query: If `True` forces to always use | ||
`SimpleQueryString` for the text query object. | ||
|
||
.. warning:: | ||
|
||
|
@@ -50,6 +62,7 @@ def __init__(self, query=None, filters=None, user=None, use_advanced_query=True, | |
self.user = user | ||
self.filter_by_user = kwargs.pop('filter_by_user', True) | ||
self.use_advanced_query = use_advanced_query | ||
self.projects = projects or {} | ||
|
||
# Hack a fix to our broken connection pooling | ||
# This creates a new connection on every request, | ||
|
@@ -259,7 +272,12 @@ def total_count(self): | |
return s.hits.total | ||
|
||
def query(self, search, query): | ||
"""Manipulates the query to support nested queries and a custom rank for pages.""" | ||
""" | ||
Manipulates the query to support nested queries and a custom rank for pages. | ||
|
||
If `self.projects` was given, we use it to filter the documents that | ||
match the same project and version. | ||
""" | ||
search = search.highlight_options(**self._highlight_options) | ||
|
||
queries = self._get_queries( | ||
|
@@ -280,8 +298,22 @@ def query(self, search, query): | |
) | ||
|
||
queries.extend([sections_nested_query, domains_nested_query]) | ||
bool_query = Bool(should=queries) | ||
|
||
if self.projects: | ||
versions_query = [ | ||
Bool( | ||
must=[ | ||
Term(project={'value': project}), | ||
Term(version={'value': version}), | ||
] | ||
) | ||
for project, version in self.projects.items() | ||
] | ||
bool_query = Bool(must=[bool_query, Bool(should=versions_query)]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I"m a little worried about this as you noted, but lets see how it performs in prod. |
||
|
||
final_query = FunctionScore( | ||
query=Bool(should=queries), | ||
query=bool_query, | ||
script_score=self._get_script_score(), | ||
) | ||
search = search.query(final_query) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.