forked from readthedocs/readthedocs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request readthedocs#4292 from safwanrahman/exact_match
[Fix readthedocs#2457] Implement exact match search
- Loading branch information
Showing
7 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import pytest | ||
|
||
from readthedocs.search.documents import PageDocument | ||
|
||
|
||
class TestFileSearch(object): | ||
|
||
@pytest.mark.parametrize('case', ['upper', 'lower', 'title']) | ||
def test_search_exact_match(self, client, project, case): | ||
"""Check quoted query match exact phrase with case insensitively | ||
Making a query with quoted text like ``"foo bar"`` should match | ||
exactly ``foo bar`` or ``Foo Bar`` etc | ||
""" | ||
# `Github` word is present both in `kuma` and `pipeline` files | ||
# But the phrase Github can is available only in kuma docs. | ||
# So search with this phrase to check | ||
query_text = r'"GitHub can"' | ||
cased_query = getattr(query_text, case) | ||
query = cased_query() | ||
|
||
page_search = PageDocument.faceted_search(query=query) | ||
results = page_search.execute() | ||
|
||
assert len(results) == 1 | ||
assert results[0]['project'] == 'kuma' | ||
assert results[0]['path'] == 'documentation' | ||
|
||
def test_search_combined_result(self, client, project): | ||
"""Check search result are combined of both `AND` and `OR` operator | ||
If query is `Foo Bar` then the result should be as following order: | ||
- Where both `Foo Bar` is present | ||
- Where `Foo` or `Bar` is present | ||
""" | ||
query = 'Official Support' | ||
page_search = PageDocument.faceted_search(query=query) | ||
results = page_search.execute() | ||
assert len(results) == 3 | ||
|
||
result_paths = [r.path for r in results] | ||
# ``open-source-philosophy`` page has both ``Official Support`` words | ||
# ``docker`` page has ``Support`` word | ||
# ``installation`` page has ``Official`` word | ||
expected_paths = ['open-source-philosophy', 'docker', 'installation'] | ||
|
||
assert result_paths == expected_paths |
This file contains 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 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