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

[Fix #2457] Implement exact match search #4292

Merged
merged 3 commits into from Jun 26, 2018

Conversation

safwanrahman
Copy link
Member

@safwanrahman safwanrahman commented Jun 22, 2018

Fix #2457
This PR implements searching exact phrase by using "" quoted text.(eg: "foo bar")

It also rewrite the search functionality as there will be more relavant result by using both AND and OR operator. AND operator has higher priority than the OR operator.
Like search with Foo Bar(without quote) will match all the documents which have either Foo or Bar, but the pages which have Foo and Bar both, will be higher in index. So user will first see the relavant results, then see other results wich maybe also helpful for them.

I have used bool query to combine both of the query. Elasticsearch The Definative Guide helped mostly to understand the thing. The paragraph in elasticsearch-dsl docs is also helpful.

@ericholscher r?

@safwanrahman safwanrahman self-assigned this Jun 22, 2018
@safwanrahman safwanrahman added this to Backlog in Search update via automation Jun 22, 2018
@safwanrahman safwanrahman moved this from Backlog to In progress in Search update Jun 22, 2018
Copy link
Contributor

@davidfischer davidfischer left a comment

Choose a reason for hiding this comment

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

I'm still trying to grasp everything there is to know about our search but I had a few comments/questions on this one.

@@ -20,7 +20,7 @@ def es_index():


@pytest.fixture(autouse=True)
def all_projects(es_index, mock_processed_json):
def all_projects(es_index, mock_processed_json, db):
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't appear to be used. Is it necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Its actually a fixture which need to injected for db access. whether you use or not, if any fixture has dependency to db fixture, that means the fixture has access to database.

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the thought process that the first example -- both "foo" and "bar" are present -- will rank more highly than the second?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. It will have higher in rank as its more relevant

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

This looks good. I'm excited about the addition of SimpleQueryString, as I think that will make our searches much nicer in general.


# Need to search for both 'AND' and 'OR' operations
# The score of AND should be higher as it comes first
for operator in ['AND', 'OR']:
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to boost the AND in some way, or will it automatically sort higher?

Copy link
Member Author

Choose a reason for hiding this comment

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

AND matched index will surely have higher score as it satisfies both of the query.
It describes better: https://www.elastic.co/guide/en/elasticsearch/guide/current/bool-query.html#CO60-1

Or we can add boost value to the query explecitly!

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it for now, and we can boost it later if we want.

@ericholscher ericholscher merged commit af641b0 into readthedocs:search_upgrade Jun 26, 2018
Search update automation moved this from In progress to Done Jun 26, 2018
@safwanrahman safwanrahman deleted the exact_match branch July 7, 2018 19:24
safwanrahman pushed a commit to safwanrahman/readthedocs.org that referenced this pull request Jul 16, 2018
safwanrahman pushed a commit to safwanrahman/readthedocs.org that referenced this pull request Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Search update
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants