Forums / Extensions / eZ Find / Search for an exact term in a filtered query (fq) request

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

Author Message

Jim Thaxton

Thursday 01 April 2010 7:42:01 am

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_t:( "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_t:( "Hudson" ) ) AND ( meta_contentclass_id_si:49 AND attr_in_stock_b:1 ) AND NOT attr_brand_t:( "Alexis Hudson" ) AND NOT attr_brand_t:( "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?

Web Developer
Coupon Cabin
Chicago, IL

Paul Borgermans

Thursday 01 April 2010 10:34:47 am

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

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Paul Borgermans

Thursday 01 April 2010 10:44:24 am

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

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans