Page MenuHomePhabricator

Boost Elasticsearch results if match is found on title instead of body.
Closed, ResolvedPublic

Description

On current PhabricatorSearchEngineElastic implementation there is no difference if match query was found on title or on body fields. This makes difficult to get expected results and IMO title field must be prioritized.
For example if wiki document has a lot of content in field.corpus field with tokens from search phrase "some runbook", likely it will be listed above the document with less content but with exact title "some runbook".

Currently generated basic query:

{
  "query": {
    "bool": {
      "must": [
        {
          "simple_query_string": {
            "query": "some runbook",
            "fields": [
              "field.corpus"
            ]
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 101
}

we can add additional lookup on title field while every document has it:

{
  "query": {
    "bool": {
      "must": [
        {
          "simple_query_string": {
            "query": "some runbook",
            "fields": [
              "field.corpus"
            ]
          }
        }
      ],
      "should": {
        "simple_query_string": {
          "query": "some runbook",
          "fields": [
            "title"
          ]
        }
      }
    }
  },
  "from": 0,
  "size": 101
}