1

Given the following configuration:

  • A Search Api views page(connected with a Solr server) with a "Search: Fulltext search" exposed filter searching only on one "Full Text" aggregated field (Node Title).
  • All the content is in Dutch;

The issue:

Having a list of node titles as following:

  • AVENE CREM NUTRITIVE COMP POT 50 ML
  • Widmer Nutritive Creme Parf 50ml
  • AVENE TRIXERA NUTRITION NUTRI-FLUIDE 400
  • NUTRITIC MEMOTONIC 7 FLAC
  • NUTRITIC VIT A-D GINKGO 30 TABL

Searching for the keyword "Nutritic" will return me the following order:

  • NUTRITIC MEMOTONIC 7 FLAC
  • AVENE CREM NUTRITIVE COMP POT 50 ML
  • Widmer Nutritive Creme Parf 50ml
  • AVENE TRIXERA NUTRITION NUTRI-FLUIDE 400
  • NUTRITIC VIT A-D GINKGO 30 TABL

It seems like the keyword "NUTRITI" is considered the same as "NUTRITIC".

enter image description here

How can ensure that searching on keyword "NUTRITIC" the content containing specifically "NUTRITIC" will have the bigger score than others?

1

Having just worked with Solr myself (for English) text. You need to assure Solr is Configured to search how you want. Out of the box the Solr configuration provides:

  • a case insensitive, stemmed search (fuzzy, such as "savage" searches for "savage", "savages", "savaged", etc. and the search ignores punctuation. It also supports short phrase searching such as "find me this text" although Search API in 7.x-1.20 has a bug that removes min_length words from quoted strings: https://www.drupal.org/node/2832196

This issue is resolved in the current -dev release available on 12/09/2016.

You have 2 options

  1. So, if the default stemmed search works for you as-is OK. If you want exact word searching with no stemming you need to alter the Solr schema to index text content differently than it does out of the box.

    For non-stemmed, case sensitive searches change the analysis and query and multi-part logic to not use SnowballPorterStemmer and CaseInsenitive.

    This is kinda outlined, but out of date for Solr 5x in this drupal issue. https://www.drupal.org/node/1319516#comment-5158076 Solr 5x depercated enablePositionIncrements=true so don't do that in the comments, and it will work.

  2. If you like the searching as-is. You can alternatively boost the exact words to score higher than the inexact results. You would do this by:

    • adding a fake entity property using an alter hook, and copying the text content from your fields into that field.
    • You would then define a Solr field in the solr schema to use for this drupal entity property field which doesnt use stemming to returned results
    • include this fake property field in your drupal search api Index.
    • use an alter hook for the solr query include this field with a boost (&myfield="FOOBAR"^10) in your search query.

Here's how you add a fake entity property to then be boosted: http://cornel.co/article/add-entity-property-node-which-can-be-used-search-api-index-field

Then it's simply a query alter in your form (here for apachesolr module, but for search API it's the same thing): https://www.phase2technology.com/blog/techniques-to-improve-your-solr-search-results/

Isn't Solr fun!!! (sigh) it's really cool, but also cumbersome.

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.