Problem/Motivation

Elasticsearch, OpenSearch, and Solr support two options for sorting suggestions:

  • Score (i.e. sort by score first, then sort by frequency)
  • Frequency (i.e. sort by frequency first, then sort by score)

References:

However this module does not seem to provide a way to choose the order. As a result the "score" order is always used by default, which does not always provide the best results. In our case we have better results with the "frequency" order.

Is it possible to expose this option in the admin UI?

Proposed resolution

Attached is a proposed Merge Request and the associated patch. It basically adds a new dropdown to the Views areas:

Views area admin UI

The backend modules would then be responsible for using this value when calling their search engines API.

Since Elasticsearch, OpenSearch, and Solr support the same two options (Score & Frequency) I have hardcoded them. However, as an improvement, we could add an API to let each backend module declare which orders they support (if any).

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

fengtan created an issue. See original summary.

fengtan’s picture

StatusFileSize
new1.63 KB

fengtan’s picture

Issue summary: View changes
Status: Active » Needs review
fengtan’s picture

Related issues: +#3569998: Support sorting suggestions by frequency
StatusFileSize
new2.21 KB

I have opened a related issue in the Elasticsearch Connector queue to support this option: #3569998: Support sorting suggestions by frequency

mparker17’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

The code seems clear and makes good use of available APIs. This module doesn't have any tests yet, and this patch doesn't add any.

Testing manually with Elasticsearch, and the patch in #3569998: Support sorting suggestions by frequency, I can see "sort":"score" change to "sort":"frequency" in the raw query sent to Elasticsearch when I change the value in the select list created in this patch.

Also manual-testing, I couldn't figure out a mis-spelled search phrase that I could use which would get me multiple "did you mean" suggestions, so I wasn't able to verify the UI (but that's most likely an issue with my test data... I tried test data from both \Drupal\Tests\search_api\Functional\ExampleContentTrait and the Devel project's devel_generate sub-module).

Regardless, I'm going to mark this as RTBC, ideally so it can unblock #3569998: Support sorting suggestions by frequency.


It's also worth noting the same options are present in OpenSearch (i.e.: in addition to Elasticsearch and Solr). I've updated the issue summary.