Forums / Developer / A question on custom the search function

A question on custom the search function

Author Message

Toms King

Thursday 17 August 2006 12:03:25 am

Hi, all,

Me again. I just wanna improve the default search function by search with more than two items. For example, if I wanna search through class company, by company_name = "Microsoft" and company_owner = "Bill Gates". However, from the advanced search function, it seems that I can only perform the search function with only one item. So, how?

Thank you very much for attention.

Best regards,

Toms

Toms King

Thursday 17 August 2006 12:52:21 am

updates, I have just read the article http://ez.no/community/bugs/search_lacks_multi_attribute_queries
and know that eZpublish support multiple attributes searching,

And the following are the codes for my search function, where 191 and 193 are the attribute_id.

<form action={"/content/advancedsearch/"|ezurl} method="get">
<div class="maincontentheader">
<h1>{"Advanced search"|i18n("design/standard/content/search")}</h1>
</div>

<input type="hidden" name="Content_search_attribute_fulltext_classattribute_id[]" value="191" />
<input type="text" name="Content_search_attribute_fulltext_value[]" value="{$search_array_by_class_attribute_id['191']['value']}"  />
<input type="hidden" name="Content_search_attribute_fulltext_classattribute_id[]" value="193" />
<input type="text" name="Content_search_attribute_fulltext_value[]" value="{$search_array_by_class_attribute_id['193']['value']}" />

<div class="buttonblock">
<input class="button" type="submit" name="SearchButton" value="{'Search'|i18n('design/standard/content/search')}" />
</div>

However, it returns no result, why?

Thank you for your attention.

Toms King

Thursday 17 August 2006 1:13:57 am

keep on updates
I am reading the search function in the user manual.

fetch( content, search,
       hash( text, text,
           [ offset,             offset, ]
           [ limit,              limit,  ]
           [ section_id,         id,     ]
           [ subtree_array,      array,  ]
           [ publish_timestamp,  time,   ]
           [ publish_date,       date,   ]
           [ class_id,           id,     ]
           [ class_attribute_id, id,     ]
           [ sort_by,            sort_by ] ) )

Then how can I change this function to search using more than two attributes?

Marcin Drozd

Thursday 17 August 2006 2:16:10 am

Hi
class_attribute_id - <i>"This parameter can also be an array of attribute ID numbers."</i>

see my two last posts: http://ez.no/content/view/full/105218
and U can use

fetch( content, search,
      hash( text, text,
               class_attribute_id, array( ATTR_ID_1, ATTR_ID_2, ... )
))

http://ez-publish.pl

Toms King

Thursday 17 August 2006 3:24:54 am

thx, Marcin, but what I mean is that I want to search in this way, I provide different values for two attributes, for example, name = "Microsoft", and owner = "Bill Gates" for example. The search key words for the two attributes are not same.

And some more question, seems a bit fool, but I really cannot find how to use the fetch function to get an array of all the objects under the same class with class_id provided.

Thank again, and sorry for the misleading.

Toms King

Thursday 17 August 2006 3:41:13 am

for fetch all the objects by giving the class_id, I got a solution but I think not the best

{def $obj=fetch( content, list, hash( parent_node_id, 2,
class_filter_type, include,
class_filter_array, array( '21' ) ) )}

where 21 is the class_id

however, all the object need have the same parent_node

anyone have better solution? Thanks for sharing........

Marcin Drozd

Thursday 17 August 2006 3:51:36 am

Hi
for fetch all objects of class "my_class" U can use "tree" ( http://ez.no/doc/ez_publish/technical_manual/3_8/reference/modules/content/fetch_functions/tree )
(here my_class=21)

{def $obj=fetch( content, tree, hash( parent_node_id, 2,
class_filter_type, include,
class_filter_array, array( 'my_class' ) ) )}

And U can use also "attribute_filter":
(for name = "Microsoft", and owner = "Bill Gates")

{def $obj=fetch( content, tree, hash( parent_node_id, 2,
class_filter_type, include,
class_filter_array, array( 'my_class' ),
'attribute_filter', array( 'and',
                                array( 'my_class/name', '=', 'Microsoft' ),
                                array( 'my_class/owner', '=', 'Bill Gates' ) )
) )

http://ez-publish.pl

Toms King

Thursday 17 August 2006 6:18:18 pm

Sorry hah, for the search function to perform search with more than two items, I found that I still need to use the search fetch function.

I also found that
http://ez.no/ez_publish/documentation/customization/components/search/custom_search_box
say that
If you search by several attributes at once, you will only get results where all attributes match. In other words, only AND search is supported, not OR or NOT search.

But how can perform this kind of search, who can give me an example?
Sorry for the inconvenince, coz I am really a new player here. ^__^

eZ debug

Timing: Jan 18 2025 22:12:45
Script start
Timing: Jan 18 2025 22:12:45
Module start 'content'
Timing: Jan 18 2025 22:12:45
Module end 'content'
Timing: Jan 18 2025 22:12:46
Script end

Main resources:

Total runtime0.8301 sec
Peak memory usage4,096.0000 KB
Database Queries209

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 589.2734180.8125
Module start 'content' 0.00550.6920 770.0859574.9531
Module end 'content' 0.69750.1324 1,345.0391341.7813
Script end 0.8299  1,686.8203 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.4672210.0002
Check MTime0.00150.1786210.0001
Mysql Total
Database connection0.00090.102710.0009
Mysqli_queries0.754990.94262090.0036
Looping result0.00200.24412070.0000
Template Total0.805397.020.4026
Template load0.00190.233720.0010
Template processing0.803396.780520.4017
Template load and register function0.00010.015410.0001
states
state_id_array0.00120.143110.0012
state_identifier_array0.00130.151320.0006
Override
Cache load0.00180.2178540.0000
Sytem overhead
Fetch class attribute can translate value0.00090.107130.0003
Fetch class attribute name0.00090.107380.0001
XML
Image XML parsing0.00040.051030.0001
class_abstraction
Instantiating content class attribute0.00000.001880.0000
General
dbfile0.00320.3823210.0002
String conversion0.00000.000530.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
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
15content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
9content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/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: 39
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs