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

eZ debug

Timing: Jan 17 2025 23:39:01
Script start
Timing: Jan 17 2025 23:39:01
Module start 'content'
Timing: Jan 17 2025 23:39:02
Module end 'content'
Timing: Jan 17 2025 23:39:02
Script end

Main resources:

Total runtime0.9766 sec
Peak memory usage4,096.0000 KB
Database Queries196

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0113 589.1016180.7578
Module start 'content' 0.01130.8271 769.8594549.1016
Module end 'content' 0.83840.1382 1,318.9609336.7031
Script end 0.9766  1,655.6641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00600.6186210.0003
Check MTime0.00170.1725210.0001
Mysql Total
Database connection0.00200.207510.0020
Mysqli_queries0.894691.59751960.0046
Looping result0.00210.21591940.0000
Template Total0.933095.520.4665
Template load0.00270.277420.0014
Template processing0.930395.257620.4652
Template load and register function0.00020.025410.0002
states
state_id_array0.00060.064310.0006
state_identifier_array0.00130.132220.0006
Override
Cache load0.00220.2288300.0001
Sytem overhead
Fetch class attribute can translate value0.00160.167830.0005
Fetch class attribute name0.00140.138440.0003
XML
Image XML parsing0.00100.099130.0003
class_abstraction
Instantiating content class attribute0.00000.001750.0000
General
dbfile0.00230.2351280.0001
String conversion0.00000.000830.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 14
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs