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. ^__^

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.