-
Notifications
You must be signed in to change notification settings - Fork 57
Search in multivalue fields #6
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 all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| [MESSAGES CONTROL] | ||
| disable=too-many-lines | ||
| # https://bitbucket.org/logilab/pylint/issue/214/the-duplicate-code-r0801-cant-be-disabled | ||
| disable=duplicate-code | ||
|
|
||
| [FORMAT] | ||
| max-line-length=120 |
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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """ Tests for MockSearchEngine specific features """ | ||
| from datetime import datetime | ||
| from django.test import TestCase | ||
| from django.test.utils import override_settings | ||
| from search.tests.mock_search_engine import _find_field, _filter_intersection, json_date_to_datetime | ||
|
|
||
|
|
||
| # Any class that inherits from TestCase will cause too-many-public-methods pylint error | ||
| # pylint: disable=too-many-public-methods | ||
| @override_settings(SEARCH_ENGINE="search.tests.mock_search_engine.MockSearchEngine") | ||
| @override_settings(ELASTIC_FIELD_MAPPINGS={"start_date": {"type": "date"}}) | ||
| class MockSpecificSearchTests(TestCase): | ||
| """ For testing pieces of the Mock Engine that have no equivalent in Elastic """ | ||
|
|
||
| def test_find_field_arguments(self): | ||
| """ test that field argument validity is observed """ | ||
| field_value = _find_field( | ||
| { | ||
| "name": "Come and listen to my story" | ||
| }, | ||
| "name" | ||
| ) | ||
| self.assertEqual(field_value, "Come and listen to my story") | ||
|
|
||
| field_value = _find_field( | ||
| { | ||
| "name": { | ||
| "first": "Martyn", | ||
| "last": "James" | ||
| } | ||
| }, | ||
| "name.first" | ||
| ) | ||
| self.assertEqual(field_value, "Martyn") | ||
|
|
||
| field_value = _find_field( | ||
| { | ||
| "name": { | ||
| "first": "Monica", | ||
| "last": { | ||
| "one": "Parker", | ||
| "two": "James" | ||
| } | ||
| } | ||
| }, | ||
| "name.last.two" | ||
| ) | ||
| self.assertEqual(field_value, "James") | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| field_value = _find_field( | ||
| { | ||
| "name": "Come and listen to my story" | ||
| }, | ||
| 123 | ||
| ) | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| field_value = _find_field(123, "name") | ||
|
|
||
| def test_filter_optimization(self): | ||
| """ Make sure that intersection optimizes return when no filter dictionary is provided """ | ||
| test_docs = [{"A": {"X": 1, "Y": 2, "Z": 3}}, {"B": {"X": 9, "Y": 8, "Z": 7}}] | ||
| self.assertTrue(_filter_intersection(test_docs, None), test_docs) | ||
|
|
||
| def test_datetime_conversion(self): | ||
| """ tests json_date_to_datetime with different formats """ | ||
| json_date = "2015-01-31" | ||
| self.assertTrue(json_date_to_datetime(json_date), datetime(2015, 1, 31)) | ||
|
|
||
| json_datetime = "2015-01-31T07:30:28" | ||
| self.assertTrue(json_date_to_datetime(json_datetime), datetime(2015, 1, 31, 7, 30, 28)) | ||
|
|
||
| json_datetime = "2015-01-31T07:30:28.65785" | ||
| self.assertTrue(json_date_to_datetime(json_datetime), datetime(2015, 1, 31, 7, 30, 28, 65785)) | ||
|
|
||
| json_datetime = "2015-01-31T07:30:28Z" | ||
| self.assertTrue(json_date_to_datetime(json_datetime), datetime(2015, 1, 31, 7, 30, 28)) | ||
|
|
||
| json_datetime = "2015-01-31T07:30:28.65785Z" | ||
| self.assertTrue(json_date_to_datetime(json_datetime), datetime(2015, 1, 31, 7, 30, 28, 65785)) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@e-kolpakov There's a warning in the docs you've added about searching multivalue fields. This code here seems oriented toward doing something with that, though perhaps I misunderstand. Is the warning accurate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kelketek the warning is accurate. This method is later used to check if document field value is iterable, and search value is not. The second part of warning (searching lists in multivalue fields) does not apply here.
However, basically this MockSearchEngine should replicate elasticsearch behavior as closely as possible (at least for now we decided that it will), and elastic does not document what would happen if array is passed to
termfilter: http://www.elastic.co/guide/en/elasticsearch/reference/0.90/query-dsl-term-filter.htmlAlso, note elasticsearch 0.90 is used - I haven't seen any provision scripts that would confirm that, but live devstack instanceon my machine uses 0.90 for sure.