1

We're using the search API something like this, and returning results in alphabetical order:

// Set up
$search_api_index = $this->entityTypeManager->getStorage('search_api_index');
$index = $search_api_index->load($name);
$search_id = 'restful_search_' . uniqid();
$query = $index->query([
  'limit' => $limit,
  'offset' => $offset,
  'search id' => $search_id
]);

// Add some conditions
$query->addConditionGroup($conditionGroup);

// Add sort directive
$query->sort('title', SORT_ASC);

This is working, and the results are coming back in alphabetical order. However, we'd like the sort according to the Finnish/Swedish alphabet.

So instead of things being sorted like "ÄBC", we'd like them sorted like "BCÄ". That is, those beginning with Å, Ä and Ö etc. should come last, not first.

Is it possible to tell the Search API to return results which meet this order?

0

I believe your question is more tailored to Solr rather than Drupal persay.

I'm using Solr, but not with any special language semantics for Sorting required.

It appears as though solr can be configured to support the kind of alphabetical sorting you requested via a Plugin and a special field type. See the section entitled Unicode Collation on this reference page: https://cwiki.apache.org/confluence/display/solr/Language+Analysis

Once your Solr instance is configured to support the ICUCollationField field type. You then need to tell Drupal to make use of that field for analysis/sorting. So either in D8 you need to implement some of the below modifications:

  • alter the Solr Field type that fulltext searches are indexed with to use the ICUCollationField instead of the default fulltext field supplied by Search API using the Search API hooks.
  • OR, use the copyfield technique described in the Solr reference page under Sorting Text for Multiple Languages, and use the Search API copy field functionality to clone the default fulltext into this collation aware field.
    • then alter every search performed by your site using Search API hooks to override the Sort parameter to use the collation field.

Your request will likely require a full Solr re-index of all your Nodes, and if you use copyfield be aware the index may be much bigger.

These are some general approaches you can attempt using Search API and Solr. I'm not 100% sure they'll work, but they're the 2 approaches I'd try if I was setting this up.

Any feedback, success or failure is welcome to your original post once you've figured it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.