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

Adding search class for simplesearch #3417

Merged
merged 2 commits into from Nov 16, 2018

Conversation

safwanrahman
Copy link
Contributor

@safwanrahman safwanrahman commented Nov 12, 2018

This PR adds a SimpleSearch class for building the Search object of simple search.
So it should work something like this

from kitsune import search as constants
simple_search = SimpleSearch(query="firefox",
                             doc_type=constants.WHERE_WIKI, locale="en-US")
search = simple_search.get_search()
search.execute()

I have tried to follow factory pattern in SimpleSearch, but dont know if totally follow the factory pattern.

This class can be used in simple_search view to build the Search object then paginate and execute. Need to be verified that all the boosting are correct and fields are covered according to previous generate_simple_search function.

Highlight and others are not added yet.

This will made following elasticsearch query. Looking at the json, I think it make sense. Maybe we can compare the old elasticsearch query with this query.

{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "minimum_should_match": 1,
            "filter": [
              {
                "terms": {
                  "document_category": [
                    10,
                    20
                  ]
                }
              },
              {
                "term": {
                  "document_locale": "en-US"
                }
              },
              {
                "term": {
                  "document_is_archived": false
                }
              },
              {
                "term": {
                  "index_name": "sumo_wiki_document"
                }
              }
            ],
            "should": [
              {
                "multi_match": {
                  "fields": [
                    "document_summary^2.0",
                    "document_keywords^8.0",
                    "document_title^6.0",
                    "document_content^1.0"
                  ],
                  "query": "Sample"
                }
              },
              {
                "multi_match": {
                  "fields": [
                    "document_summary^2.0",
                    "document_keywords^8.0",
                    "document_title^10.0",
                    "document_content^8.0"
                  ],
                  "type": "phrase",
                  "query": "Sample"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "minimum_should_match": 1,
            "filter": [
              {
                "term": {
                  "question_is_archived": false
                }
              },
              {
                "term": {
                  "question_has_helpful": true
                }
              },
              {
                "term": {
                  "index_name": "sumo_question"
                }
              },
              {
                "term": {
                  "question_locale": "en-US"
                }
              }
            ],
            "should": [
              {
                "multi_match": {
                  "fields": [
                    "question_title^4.0",
                    "question_content^3.0",
                    "question_answer_content^3.0"
                  ],
                  "query": "Sample"
                }
              },
              {
                "multi_match": {
                  "fields": [
                    "question_title^4.0",
                    "question_content^3.0",
                    "question_answer_content^3.0"
                  ],
                  "type": "phrase",
                  "query": "Sample"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

@pmac r?

@pmac pmac merged commit f7c9c0a into mozilla:es_upgrade Nov 16, 2018
@safwanrahman
Copy link
Contributor Author

Thanks @pmac

@pmac
Copy link
Member

pmac commented Nov 29, 2018

re #3294

pmac pushed a commit that referenced this pull request Apr 29, 2019
pmac pushed a commit that referenced this pull request May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants