When we are testing our solr we have dont get exact matches.
For example when we type "clares" we get as first results matches with clare.
We have analysed the situation (see screenshots) and we think Solr sees the company name "clares" as the plural of "clare" in its snowballporter algoritme.

The problem: We have no idea how to do exact matches in solr. Do we disable the snowballporter algoritme? How do we do that? We tried to disable it in schema.xml (without reindexing) but no effect. We probably need to reindex with a new schema.xml? (We restarted the solr instance after modifying the schema.xml)

Can someone document how to do exact matches? It seems like an important feature. Thanks!

CommentFileSizeAuthor
Clares analyse 0.png72.1 KBdomidc
Clares analyse.png17.85 KBdomidc

Comments

robertdouglass’s picture

Yes, you'd have to reindex with the change in schema.xml.

I have some questions myself around exact matching. Will report back if I have interesting information.

ramprassad’s picture

Hi domidc,

I assume you want to do an exact match on company name when you type the start words. Not sure this is what you are looking for, I had a similar situation doing a type ahead functionality based on city field using apachesolr_automplete module. To get the exact match the fields should not be tokenized, so I had to use a new field type with solr.KeywordTokenizerFactory

<fieldType name="text_auto" class="solr.TextField"/>
         <analyzer>
          <tokenizer class="solr.KeywordTokenizerFactory"/>
          <filter class="solr.LowerCaseFilterFactory"/>
         </analyzer>
</fieldType>

<field name="cities" type="text_auto" indexed="true" stored="true" multiValued="false" />

Then I had to just make a copy of the original city taxonomy value to this field in hook_update_index and faceted on the new "cities" field.

janusman’s picture

It'd be nice to index both unstemmed and stemmed versions of the node and (by default) boost results with exact matches higher than those with stemming. However, that would mean a much larger index size.

domidc’s picture

Hi ramprassad,

I m currently not on the project anymore but this is what my collegue came up with (he send me this info). Didnt tested this but according to him it worked. I ll post it because it might be useful.

For exact match, I think the solution may be to to use a Boost Function based on strdist. But in order for it to work, the field used in strdist needs to be of the type string (not a text or a sortString) on the solr side (ie. in the schema.xml).

Each request produce an XML document with the same results. However, if you look at the end of the document, in the , there is a difference in the explanation of the score of each result:
* title: 0.0 = strdist(CRONOS,*ord*(title)=331487, dist=org.apache.lucene.search.spell.LevensteinDistance)
* sname 0.0 = strdist(CRONOS,*str*(sname)=calibrate, dist=org.apache.lucene.search.spell.LevensteinDistance)

Being a text, the title field is not properly evaluated when used in strdist. The sname field is a string and is properly evaluated.

So, an additional copy of the title field should be added to the schema.xml.

  <fields>
    <field name="boost_title" type="string" indexed="false" stored="true" omitNorms="true"/>
  <copyField source="sort_title" dest="boost_title"/>
With this setup, the following should be added to glue_final_apachesolr_modify_query to add a Boost Function:
 function glue_final_apachesolr_modify_query(&$query, &$params, $caller) {
  if($caller == 'apachesolr_views_query' && (!$query->has_filter('NOT type', 'company'))) {   

    foreach($boosted as $field_value => $boost_factor) {
       $params['bq'][] = "$field_name:$field_value^$boost_factor";
    }

    if($query_basic = $query->get_query_basic()) {
      //TODO: Sanitize $query_basic to avoid generation of an invalid bf value
      $params['bf'][] = 'strdist("'. drupal_strtolower($query_basic) .'", boost_title, edit)';
    }
  }
}
In order for this solution be tested and confirmed to work, an index rebuild is required. The process to properly rebuild the index is still unclear to me.

Note: sort_title is copied instead of title to avoid upper/lower case mismatch in strdist. The sort_title is already a copy of title with lowercase and trim filters applied. drupal_strtolower($query_basic) is used for the same reason.

pwolanin’s picture

Status: Active » Fixed

An alternative is to populate the prowords.txt file to prevent some specific words from being stemmed. Or switch to a different stemmer on the server like kstem.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jaffarcheckout’s picture

Hi,

How to assign score for each and every node.. $params['bq'][] = "$field_name:$field_value^$boost_factor"; it doesnot work... Kindly provide solution.

jaffarcheckout’s picture

We are building a customized Scoring module for the Apache Solr Results.

To do the same, we are using a custom module to override the Query created by Apache Colr using suggestion provided by domidc at Apache Solr Search Integration » Issues #4. http://drupal.org/node/912214#comment-3748634

The Custom function reads:
function hook_apachesolr_modify_query(&$query, &$params, $caller) {
$params['bf'][] = "recip(rord(is_field_mytestval),1000,1000,1000)^200";
}

In the above function

we assigned score to this field is_field_mytestval

There is so difference tin the results, the above Query doesnot get expected results.

SandraVdv’s picture

I got the same issue I think.. When i search for a full node title SOLR doesn't seem to find the node, but when I search for a part of the node title SOLR does return that node...
I'm a little bit confused here, but it seems to me that the title isn't indexed properly...
That's why I wanted to try your suggestion domidc, but when I add those fields to schema.xml my SOLR breaks... I get following errors:

HTTP Status 500 - Severe errors in solr configuration. Check your log files for more detailed information on what may be wrong. If you want solr to continue after configuration errors, change: <abortOnConfigurationError>false</abortOnConfigurationError> in solr.xml ------------------------------------------------------------- java.lang.RuntimeException: SchemaField: boost_title conflicting indexed field options:{indexed=false, stored=true, omitNorms=true} at org.apache.solr.schema.SchemaField.calcProps(SchemaField.java:229)

Any help would be appreciated!

srajan83’s picture

Status: Closed (fixed) » Active

here also same issue, actually my requirement is if we search a phrase (with in quotation marks) i need exact match only. other wise stemming would be fine. Any help please.

nick_vh’s picture

Status: Active » Closed (fixed)

Let's not reopen such an old thread. Please open a new issue is this is still relevant for you and see if it has been fixed in 6.x-3.x or 7.x-1.x. Thanks

balmydrizzle’s picture

Mostly the conflicting index options errors occur when you set indexed=false and omitNorms (no matter the value) simultanesously.