Difference between revisions of "Searching With ActionApps"

From ActionApps Documentation
Jump to: navigation, search
 
Line 1: Line 1:
 
== How does ActionApps search work ==
 
== How does ActionApps search work ==
 
  ~ToDo: write a general intro into ActionApps search approach
 
  ~ToDo: write a general intro into ActionApps search approach
== How to setup a searchform ==
+
== Setting up a Search Form ==
 
<aafaq id=1769> ~ToDo: 1769 How to setup searchform? </aafaq>
 
<aafaq id=1769> ~ToDo: 1769 How to setup searchform? </aafaq>
== Advanced search form topics ==
+
== Designing Search Results ==
<aafaq id=1707> ~ToDo: 1707 Searchform extensions </aafaq>
+
<aafaq id=2052> ~ToDo: 2052 Designing nice search results <aafaq>
 +
== Advanced Search Form Topics ==
 +
<aafaq id=1707> ~ToDo: 1707 Searchform extensions </aafaq>
 +
== Refilling the Search Form ==
 +
<aafaq id=1723> ~ToDo: 1723 How to refill conditions on searchform? <aafaq></aafaq>

Revision as of 14:00, 5 August 2005

How does ActionApps search work

~ToDo: write a general intro into ActionApps search approach

Setting up a Search Form

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

Form example:

 <form action="index.shtml" method="get" name="sf" id="sf"> Search Author: <input type="text" name="conds[0][created_by......]"><br> Search in Headline and Fulltext: <input type="text" name="conds[1][value]"> <input type="hidden" name="conds[1][operator]" value="LIKE"> <input type="hidden" name="conds[1][headline........]" value="1"> <input type="hidden" name="conds[1][full_text.......]" value="1"> <br> <input type="hidden" name="sort[0][headline........]" value="a"> <input type="submit" value="Search" > </form> 
Let's notice:
  • 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[0] uses the simplified and conds[1] 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]"> (see conds[0][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[1] in the example.

[value]

Contains the search phrase (like conds[1][value]="Prague"). Usually this is the only visible text box (<input type="text" name="conds[1][value]">). 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 ANDs, ORs, parenthesis ({[]}) and NOT. When the user gives apple 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 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
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"

[operator]

If you don't specify it, the default operator is LIKE. You can change the default by using the defaultCondsOperator parameter (e.g. defaultCondsOperator=RLIKE). Other posibilities are:

Operator Description
= equals (or "e:=" with modifiers)
<> not equals
< less than
> more than
<= 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 modifiers

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:

Operator modificator Example Description
d d:>= Used for english style datum transformation. If used, the "value" can be in format like "06/24/2001" or "10 September 2000" see strtotime PHP function definition
e e:>= Used for european style datum transformation. If used, the "value" can be in format like "24.12.2001"
m m:>= Used for comparison with current time. If used, the "value" is substracted from current time (time()) and result value is used in comparison. The value should be in seconds. This modifier is good for displaying items newer than two days, for example.

[field_id]

Specify the fields to be searched through by their IDs.

sort

Specify the sort order by the sort[] form fields. For example:

<input type="hidden" name="sort[0][headline........]" value="a">
<input type="hidden" name="sort[1][full_text.......]" value="d">

The value is "a" for ascending and "d" for descending order. The items are sorted first by sort[0], second by sort[1] etc.
If no sort[] variable is defined, items are sorted by Publish date - descending.

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[0][category........]" value="1">
<input type="hidden" name="sort[1][unspecified.....]" value="9">

The value is "1" for ascending sorting by priority and "9" for descending order.

See another example on the 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.


Refilling the Search Form

How to refill conditions on searchform?

The script fillform.php3 allows to easily refill condition variables as well.

If you have some search form using the conds[] array, you may call fillform.php3?fillConds= 1 to create JavaScript, which will automaticallyrefill the condition input fields. You may use it by SSI, e.g.

<!--#include virtual="/aaa/fillform.php3?form=formname&fillConds=1"-->

Place it after the HTML code for the search form, otherwise it will only make a JavaScript error. Replace "formname " with the name of the form containing input fields.

The script can refill multiple select boxes like
<select name="conds[0][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[1][highlighted.....]"> must not be 'highlighted.....').

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.