Forums / Extensions / eZ Find / search, filter multiple fields and OR condition

search, filter multiple fields and OR condition

Author Message

Saad Tazi

Friday 28 August 2009 10:35:17 am

Hi,
I just want to share with you some difficulties I had with the ezfind search function.

I was trying to search only the recipe objects that have a specific value (let say 'breakfast') in specific fields (categories_*) only, not in all the fields. For example, if "Breakfast" was present in the ingredient field, I don't want this object in my result.

I tried to do a search on multiple fields but using an OR condition:

def $keyword = 'Breakfast'
$recipe_list = fetch(ezfind, search, 
			hash(
				query, $keyword,
				'limit', $recipes_per_page,
				'offset', $offset,
				filter, array('or',
								array('and',
								concat('recipe/categories_meals:',$keyword),
								'contentclass_id:48'
								),
								array('and',
								concat('recipe/categories_courses:',$keyword),
								'contentclass_id:48'
								),
								array('and',
								concat('recipe/categories_milkproducts:',$keyword),
								'contentclass_id:48'
								),
								array('and',
								concat('recipe/categories_milkcalendar:',$keyword),
								'contentclass_id:48'
								),
								array('and',
								concat('recipe/categories_moreoptions:',$keyword),
								'contentclass_id:48'
								)
								
								
								
								
				)
				

			)
		)

But I noticed that the $filterQuery param in ezfezpsolrquerybuilder.php was:

array:
0=>...(don't think it's relevant)...
1=>
( meta_contentclass_id_si:48 AND attr_categories_meals_t:Breakfast AND meta_contentclass_id_si:48 ) 
OR ( meta_contentclass_id_si:48 AND attr_categories_courses_t:Breakfast AND meta_contentclass_id_si:48 ) 
OR ( meta_contentclass_id_si:48 AND attr_categories_milkproducts_t:Breakfast AND meta_contentclass_id_si:48 ) 
OR ( meta_contentclass_id_si:48 AND attr_categories_milkcalendar_t:Breakfast AND meta_contentclass_id_si:48 ) 
OR ( meta_contentclass_id_si:48 AND attr_categories_moreoptions_t:Breakfast AND meta_contentclass_id_si:48 ) 
OR meta_language_code_s:eng-CA
 

This was returning more result than excepted because of the last condition <b>OR meta_language_code_s:eng-CA</b>. the search was returning a recipe that has "Breakfast" in another field ("tips").

So this is how I fix the problem: I started the filter with an "AND" condition:

				$recipe_list = fetch(ezfind, search, 
			hash(
				query, $keyword,
				'limit', $recipes_per_page,
				'offset', $offset,
				'contentclass_id',48,
				filter, array('and',
							array('or',
								array('and',
								concat('recipe/categories_meals:',$keyword)
								),
								array('and',
								concat('recipe/categories_courses:',$keyword)
								),
								array('and',
								concat('recipe/categories_milkproducts:',$keyword)
								),
								array('and',
								concat('recipe/categories_milkcalendar:',$keyword)
								),
								array('and',
								concat('recipe/categories_moreoptions:',$keyword)
								)
							)			
				)
			)
		)

THat's probably not the best way to bild the query, but it works for me.

Ivo Lukac

Tuesday 01 September 2009 5:50:36 am

I head similar problem and reported it:
http://issues.ez.no/IssueView.php?Id=15186&activeItem=2

http://www.linkedin.com/in/ivolukac
http://www.netgen.hr/eng/blog
http://twitter.com/ilukac

Max Keil

Tuesday 08 September 2009 10:41:19 am

The same problem as yours,

after 10 minutes debugging I found a dirty solution:

'filter', array( array( 'or',
                           array( 'and',
                                    'class_identifier:auktion',
                                    'auktion/beendet:0'
                                   ),
                          array( 'and',
                                   'class_identifier:sofortkauf',
                                   'sofortkauf/beendet:0'
                                  )
                             )
                ),

the whole 'OR' condition should be in a separate array because of the language code!

Mit freundlichen Grüßen
Best regards

Max Keil

____________________________________________________________
eZ Publish Gold Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

eZ debug

Timing: Jan 18 2025 02:48:32
Script start
Timing: Jan 18 2025 02:48:32
Module start 'content'
Timing: Jan 18 2025 02:48:33
Module end 'content'
Timing: Jan 18 2025 02:48:33
Script end

Main resources:

Total runtime0.6089 sec
Peak memory usage4,096.0000 KB
Database Queries198

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0089 589.1016180.7578
Module start 'content' 0.00890.4850 769.8594603.9141
Module end 'content' 0.49390.1149 1,373.7734336.7188
Script end 0.6089  1,710.4922 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.7072210.0002
Check MTime0.00160.2580210.0001
Mysql Total
Database connection0.00090.148810.0009
Mysqli_queries0.535687.95121980.0027
Looping result0.00180.29581960.0000
Template Total0.577594.820.2887
Template load0.00200.333020.0010
Template processing0.575494.494120.2877
Template load and register function0.00020.030410.0002
states
state_id_array0.00110.181310.0011
state_identifier_array0.00070.112020.0003
Override
Cache load0.00170.2859250.0001
Sytem overhead
Fetch class attribute can translate value0.00130.219940.0003
Fetch class attribute name0.00100.164750.0002
XML
Image XML parsing0.00140.228340.0003
class_abstraction
Instantiating content class attribute0.00000.001650.0000
General
dbfile0.00290.4842340.0001
String conversion0.00000.001030.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
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs