Path

ez.no / exponential / documentation / customization / components / search / custom search box


Custom search box

You can easily add a search form anywhere in your templates which will search specific classes, subtrees etc.

Subtree search

You can use the POST variables SubTreeArray[] to specify specific searches in one or more subtrees. Here you see an example which will search from node 42 and 100.

<form�action={"/content/search/"|ezurl}�method="get">

<input�class="searchbox"�type="text"�size="8"�name="SearchText"�id="Search"�value=""�/>

<input�class="searchbutton"�name="SearchButton"�type="submit"�value="Search"�/>

<input�type="hidden"�name="SubTreeArray[]"�value="42"�/>

<input�type="hidden"�name="SubTreeArray[]"�value="100"�/>

</form>

Class search

You can search specific classes. For example you can search only forum messages, articles, products etc. This only works with the advanced search.

Below is an example of how you can create a search form which only searches in objects of class 14.

<form�action={"/content/advancedsearch/"|ezurl}�method="get">

<input�class="searchbox"�type="text"�size="8"�name="SearchText"�id="Search"�value=""�/>

<input�class="searchbutton"�name="SearchButton"�type="submit"�value="Search"�/>

<input�type="hidden"�name="SearchContentClassID"�value="14"�/>

</form>

Attribute based search

You can search in specific attributes only. The following example will search only in the description attribute of the Folder class:

<form action={"/content/advancedsearch/"|ezurl} method="get">

   Search in folder description:

   <input type="hidden" name="Content_search_attribute_fulltext_classattribute_id[]" value="156" />

   <input type="text" name="Content_search_attribute_fulltext_value[]" value="{$search_array_by_class_attribute_id['156']['value']}" />

   <input type="submit" value="Search" name="SearchButton">

</form>

Note:
- You must set AllowEmptySearch=enabled in [SearchSettings] in your site.ini(.append) for this to work, because the normal search field is not used.
- The content attribute is specified by ID. The ID may be different on your installation. See the class view for your attribute IDs.
- 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.

These attribute search types are supported:

Search type

Parameters

Provides

fulltext

classattribute_id, value

Searches for the text given by value in the attribute given by classattribute_id.

patterntext

classattribute_id, value

Searches for the text given by value in the attribute given by classattribute_id. Allows wildcards.

integer

classattribute_id, value

Searches for the integer given by value in the attribute given by classattribute_id.

integers

classattribute_id, values

Searches for the integers given by values in the attribute given by classattribute_id. Supply the values as separate input fields, named Content_search_attribute_integers_values[][].

byrange

classattribute_id, from, to

Searches for integers between the values given by from and to, in the attribute given by classattribute_id.

byidentifierrange

identifier, from, to

Searches for integers between the values given by from and to, in the attributes given by identifier. Since this search uses identifier instead of class attribute ID, it supports searching in several classes at once.

integersbyidentifier

identifier, values

Searches for the integers given by values in the attributes given by identifier. Supply the values as separate input fields, named Content_search_attribute_integers_values[][]. Since this search uses identifier instead of class attribute ID, it supports searching in several classes at once.

You need one form element for each search parameter. The elements should be named "Content_search_attribute_(SEARCH TYPE)_(PARAMETER)[]". This example illustrates the "byrange" search type:

<form action={"/content/advancedsearch/"|ezurl} method="get">

   <input type="hidden" name="Content_search_attribute_byrange_classattribute_id[]" value="42" />

   <input type="text" name="Content_search_attribute_byrange_from[]" value="{$search_array_by_class_attribute_id['42']['from']}" />

   <input type="text" name="Content_search_attribute_byrange_to[]" value="{$search_array_by_class_attribute_id['42']['to']}" />

   <input type="submit" value="Search" name="SearchButton">

</form>

Comments

Re: searching in several classes by attribute

integersbyidentifier searches only in integers, not in strings, so you can't use it to search in names.. Strings will probably be converted to the number zero.

searching in several classes by attribute

Well as I understand the integersbyidentifier this should make it possible to search in two filelds in two specific classes IF both fields had the same identifier, eg. "last_name". Or is this not correct? If this is possible I can't quite figure from the examples how this is done...

Re: Search based on attributes from two classes

Sorry, this can't be done with the current search engine. As you see above only byidentifierrange and integersbyidentifier support searching by attribute identifier (which you have to do in order to search several classes at once). None of them are suitable for searching strings.

Search based on attributes from two classes

I have tried the last example and I can't get it to work - it creates two boxes.....
I want to make a search box to search for the attribute "last name" in two specific classes (the identifier is the same in both classes).
Actually I would prefer a search box to seach both last name and/or first name in two specific classes (same identifier in both classes) but as I understand this, this is not possible ?
e.g. if you write Eric Hansen you get all the findes with Eric and all the finds with Hansen in the fields "first name" and "last name" in two specific classes
Helle

Re: So help me pls...

To make an OR or NOT search, you need to rewrite or make a new search engine plugin. This is not trivial. (See kernel/search/plugins)
I hope to make this more configurable in the future.

So help me pls...

================
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.
=================

So please give me idea how make this kind OR or NOT search!

Log in or create a user account to comment.

Contents

Customization

Access control
Exponential API Documentation
Content structure
Custom design
Components
    Images
    Datatypes
    Shop
    Information collection
    Search
       Templates
       Custom search box
       Search operator
    Form processing
    Error handling
    Icons
    Menus
    Toolbars
Tips & Tricks
Troubleshooting


Created

10/07/2003
10:04:24 am
by B�rd Farstad

Last updated

16/03/2005
4:46:57 pm
by Gunnstein Lye

Authors

B�rd Farstad
Gunnstein Lye



This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.