Searching With ActionApps
How does ActionApps search work
Setting up a Search Form
Origin: 1769 How to setup searchform?
It is possible to create searchform manually in HTML. There is no possibility to create it automaticaly as it is known from AA v1.2., yet. Special possibilities for searching in multiple slice at once, searching in discussions, choosing keywords from hierarchical constants and using a multiple select box are described at other places in this documentataion.
<form action="index.shtml" method="get" name="sf" id="sf"> Search Author: <input type="text" name="conds[created_by......]"><br> Search in Headline and Fulltext: <input type="text" name="conds[value]"> <input type="hidden" name="conds[operator]" value="LIKE"> <input type="hidden" name="conds[headline........]" value="1"> <input type="hidden" name="conds[full_text.......]" value="1"> <br> <input type="hidden" name="sort[headline........]" value="a"> <input type="submit" value="Search" > </form>
- The action atribute on first row points to some file, where slice.php3 script is included (by SSI)
- There are two visible search fields on the form - each of them uses a bit different syntax - conds uses the simplified and conds the extended syntax.
- The conditions are allways joined by AND operator - items must allways pass all specified conditions.
conds - simplified syntax
The simplified syntax is
<input type="text" name="conds[i][field_id]">
conds[created_by......] in the example). It is easy and good, if you want to:
- search only in one field for that specified phrase
- use standard searching operator "LIKE" --- the search phrase may be anywhere in the middle of any word (e.g. the phrase "los" will get items with field content "los", "Carlos" or "lost")
conds - extended syntax
The extended syntax sets an [operator], [value] and one or more [field_id]
for each condition. See
conds in the example above.
Contains the search phrase (like
conds[value]="Prague"). Usually this is
the only visible text box (
<input type="text" name="conds[value]"><code>).
The search phrase may be a boolean expression, but you don"t need to think about
it if you are using the standard LIKE operator.
The phrase may contain <code>ANDs,
NOT. When the user
OR cherry, she will get all items containing any or both
of the two in any of the fields specified by
[field_id] (see further).
Spaces are considered as AND:
Prague Spring </i>becomes Prague AND Spring
With the standard LIKE operator this works fine: it finds all items containing both Prague and Spring at any place (not necessarily Prague space Spring).
Hyphen is considered as
AND NOT if not between two letters:
North-West remains as it is, but North -West </i>becomes North AND NOT West because of the space on the left of the hyphen
To avoid this behavior, use quotes or single quotes:
"Prague Spring" or "North -West"
If you don't specify it, the default operator is LIKE. You can change the default by using the
defaultCondsOperator parameter (e.g.
|=||equals (or "e:=" with modifiers)|
|<=||less or equals|
|>=||more or equals|
|BETWEEN||in interval: the [value] must contain two numerical values, comma separated|
|LIKE||substring search (SQL: LIKE "%phrase%")|
|RLIKE||substring which begins with phrase (SQL: LIKE "phrase%")|
|LLIKE||substring which ends with phrase (SQL: LIKE "%phrase")|
|XLIKE||string (SQL: LIKE "phrase")|
|ISNULL||not set (good for boolean values - like values from checkbox)|
|NOTNULL||is set (the field must be filled - no match for NULL or epmty string )|
Date values are stored in the database as UNIX timestamps (no. of seconds since 1.1.1970). You can use modifiers to convert it from human format. The modificators are written before a comparison operator separated by colon (like "d:>="). The possibilities are:
|d||d:>=|| Used for english style datum transformation. If used, the |
|e||e:>=|| Used for european style datum transformation. If used, the |
|m||m:>=|| Used for comparison with current time. If used, the |
Example section of code:
<input type="hidden" name="conds[value]" value="7776000" /> <input type="hidden" name="conds[operator]" value="m:>=" /> <input type="hidden" name="conds[publish_date....]" value="1" />
Specify the fields to be searched through by their IDs.
Specify the sort order by the sort form fields. For example:
<input type="hidden" name="sort[headline........]" value="a"> <input type="hidden" name="sort[full_text.......]" value="d">
The value is "a" for ascending and "d" for descending order.
The items are sorted first by
sort, second by
sort variable is defined, items are sorted by Publish date -
It is possible to sort items not only by the value, but there is possibility to sort by 'priority' for the fields which uses 'constants' (Slice Admin -> Fields -Edit -> Constants) - like category field:
<input type="hidden" name="sort[category........]" value="1"> <input type="hidden" name="sort[unspecified.....]" value="9">
The value is "1" for ascending sorting by priority and "9" for descending order.
See another example on the [http://www.apc.org/actionapps/english/demo/search.shtml APC Demo Site], where publish date field is used.
Designing Search Results
Designing nice search results
On you index view...
Include _#ID_COUNT (number of found items) in the Top HTML and _#ITEMINDX (index of item within view) in front of each result item.
Also make sure the HTML code for "No item found" message says something that makes sense for the search type. Use the notshowall=1 [exact code] so blank searches show all items. Include multiple useful sorting options.
Advanced Search Form Topics
How to search in multiple slicesThe searchform may be extended to seach for items in several slices at once. This is done by adding the slices parameter, e.g.
<input type=hidden name="slices" value="517d65d9936c98a1537a5fecbddc7d42"> <!-- news -->
<input type=hidden name="slices" value="849d65d9936c98a1537a5fecbddc7d52"> <!-- events -->
<!-- news --> are useful because you perhaps don't remember, which slice has which id (
All other settings remain the same as in the usual searchform. The only difficulty is that sometimes the field ids do exist in some slice and do not exist in another one. Than you must rename the fields (menu Slice Admin --- Change field IDs).
To view the items found, you must set the same aliases (Searchform extensions etc.) in all the slices searched through. Each item will be shown using the aliases of the slice to which it belongs.
Tip: If you want to show checkboxes to choose in which slices to search, use something like
<input type=checkbox name="slices" value="517d65d9936c98a1537a5fecbddc7d42" checked> News
<input type=checkbox name="slices" value="849d65d9936c98a1537a5fecbddc7d52" checked> Events
How to search in discussion items
The discussions are not stored in the same database tables as other item content. You may use the conds[discussion] parameters, e.g.
<input type=hidden name="conds[discussion][subject]" value="1">
<input type=hidden name="conds[discussion][body]" value="1">
Specify the discussion fields in which to search: you may use this fields --- date, subject, author, e_mail, body, state, flag, url_address,
url_description, remote_addr, free1 or free2. The other fields (conds[operator], conds[value] etc.) remain the same as usual.
To view the discussion items found include aa/discussion.php3 by SSI. You must pass a view ID of some discussion view to the script, e.g. when the view ID is 22:
The top HTML code, index view code and bottom HTML code are used to create a listing of the items found, nothing other.
How to use hierarchical constants in searchform
To show hierarchical constants like in the AA control panel Edit item, use the aa/hiercons.php3 script. You must send the following to the script:
- param --- consists of the constant group name and the parameters like in the Input type "Hierarchical constants" to it --- see the Wizard with Help for more parameter details
- varname --- the name of the select box, e.g. conds[value]. Note: the real select box in the page will have  added to the name, i.e. conds[value]
- optionally lang_file --- the language file to be used, defaults to en_news_lang.php3
The SSI include for a hierarchical constant group "Keywords" may look like
One benefit: fillform.php3 knows how to refill multiple select boxes as well.
The keywords selected by the user will be joined by OR or AND, that means any keyword or all keywords must be present in an item. You must specify the operator by conds[valuejoin], e.g.
<input type=hidden name="conds[valuejoin]" value="OR">
Tip: If you want to show a select box to choose whether the keywords should be joined by OR or AND, use something like
<option value="OR">Find items with ANY keyword
<option value="AND">Find items with ALL keywords
How to use a multiple select box
If you want the user chooses keywords from a multiple select box, use the similar settings as in hierarchical constants: set the name of the select box to [value], e.g.
<select name="conds[value]" multiple>
and add the [valuejoin] field (see above).
Refilling the Search Form
How to refill conditions on searchform?
The script fillform.php3 allows to easily refill condition variables as well.
The script can refill multiple select boxes like
<select name="conds[value]" multiple>
as well. Don't forget the  after [value].
Don't use quotes around field IDs, otherwise some values will not refill (e.g. checkbox
<INPUT TYPE="checkbox" NAME="conds[highlighted.....]"> must not be
There are special dateConds parameters which I use to refill AA-like dates (three selectboxes for day, month and year), but this is a bit difficult. If you are interested, write me and I will explain.