eZ Community » Forums » Extensions » eZ Find » Search for an exact term in a...
expandshrink

Search for an exact term in a filtered query (fq) request

Search for an exact term in a filtered query (fq) request

Thursday 01 April 2010 4:42:01 pm - 3 replies

I am working on a site that implements eZ Find using Solr via the eZ Find API. I do wonder if some of our problems would be solved using the eZ Find template tag, but since the site is already developed it is somewhat of a moot point.

Into to the API and the Solr index.

Part of our filtered query (fq) is:

( meta_contentclass_id_si:49 AND attr_brand_tsad.gif Emoticon "Hudson" ) ) AND ( meta_contentclass_id_si:49 AND attr_in_stock_b:1 )

What we want is to match all products (content class 49) in the Solr index that have a brand name of "Hudson." The problem is that it returns products where Hudson is any part of the brand name so we get products with the brand name "Alexis Hudson" and "Hudson Robes" in the results.

How can we get the brand name to match the single word passed? I know I can get this to work if I explicitly exclude other brands with Hudson in the name such as:

( meta_contentclass_id_si:49 AND attr_brand_tsad.gif Emoticon "Hudson" ) ) AND ( meta_contentclass_id_si:49 AND attr_in_stock_b:1 ) AND NOT attr_brand_tsad.gif Emoticon "Alexis Hudson" ) AND NOT attr_brand_tsad.gif Emoticon "Hudson Robes" )

But to do that I need to search for all related brands and I would prefer to avoid that if possible.

Is there a way to make the filtered query terms stricter?

Thursday 01 April 2010 7:34:47 pm

The problem you are facing is that you filter on an anlyzed field where the text is split into terms corresponding to a field type "text" in the Solr schema.xml definition.

You have two options:

1) upgrade to ezfind 2.2 which allows different types of fields to be used for filtering, specify a "string" type in the case of ezstring, then filtering will be exact string matches. See ezfind.ini for details (docs are in progress on ez.no/doc)

2) modify the schema.xml file and use the copyfield feature:

define a field name "attr_brand_s" of type string

 <field name="attr_brand_s" type="string" indexed="true" stored="false"/>

and also a coyfield construct

 <copyField source="attr_brand_t" dest="attr_brand_s"/>

After this schema change, you need to re-index your site to actually create those fields

Then modify your filterquery to use "attr_brand_s" instead and it should return only "Hudson" brands

hth

Paul

Thursday 01 April 2010 7:44:24 pm

And as a side note, you can use the second approach to do other nifty tricks in schema.xml if you have dedicated needs for filtering and matching, see http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters

Paul

Saturday 26 September 2015 12:15:59 am

* Credit goes to Miro K. @ Beaconfire RedEngine *

This is a different technique for running an exact search. It does not require changing Solr schema or disabling the tokenizer.

The premise is to NOT query any string, but use the filter instead.

 

Goal: Search for exact statement: "99 red balloons"

Config: 'allow blank searches' to be enabled

Set the 'search' value to [""] (blank)

Set the 'filter' value to [ ezf_sp_words:'99 red balloons' ]

The single quotes work for ez 4.6

Be careful of 'or' conditions in your filter.

Modified on Saturday 26 September 2015 1:04:29 am by David Sayre

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from