FlexSearch Basic Searches
FlexSearch operates in conjunction with HTML forms containing regular and hidden fields which determine how the search should be performed and the output should be presented.
To preform a search, create a form which specifies hidden fields each of these field has a special meaning to FlexSearch. These fields do not have to be hidden, but the end users would probably prefer that they are. They would confuse the content of the search form. After a brief description of the fields will be an example of several forms.
Operation
Is set to "Search", this tells FlexSearch to interpret the remaining fields as database query specifications.
DataFile
This field specifies the name of the database file to search.
NoRecordTemplate
This is the name of the template to use if no records meet the search criteria. The name default tells FlexSearch to create a template from the data file.
SingleRecordTemplate
This is the name of the template to use when a search returns only a one database record. The name default tells FlexSearch to create a template from the data file.
MultiRecordTemplate
This is the name of the template to use when a search returns multiple database records, it should contain a multi-record section (see below). The name default tells FlexSearch to create a template from the data file.
Search (1-9)
Search is actually multiple fields, Search1, Search2...Search9, these fields identify the database fields to be searched, the 1 through 9 specify the relative importance of each field. The order really does not matter unless the SoftSearch field is specified (see below).
The rest of the fields are somewhat optional, they may be hidden or visible, to make most of them hidden, would mean that the form would have to use JavaScript or VBScript to make any search meaningful.
<Field Name>
This is form field named to match the database field, it is either a specific value or the minimum value that can be selected as a match.
<Field Name>_High
This is and optional form field named to match the database field plus the suffix "_High", it is the maximum value that can be selected as a match.
<Field Name>_Range
This optional field is primarily provided to allow bracketed selection lists, such as 5000-10000, 10001-20000, the field value will be broken at a - the left size is used as the minimum and the right side is used as the maximum. Note this field if present will overwrite the field name and field name high fields.
SoftSearch
SoftSearch is intended to be either a check box or a hidden field, it Tells FlexSearch to return the last successful sub search, instead of an empty query. For instance suppose that after the first and second search fields have been processed there are three records to return but when the third is processed, no record match the selections, then SoftSearch tells FlexSearch to return the three fields that match the first two tests.
SortKey
SortKey is an optional field which contains a comma seprated list of field names to sort the selected records by. For Instance "LastName, FirstName, BirthDate". Would sort by LastName and if two records have the same LastName would sort by FirstName and so on.
MaxRecords
MaxRecords defines the maximum number of returned rows that will be processed in a single search. Large numbers of records can take substancial time to process and download. MaxRecords has no effect on single record templates.
FirstRecord
FirstRecord specifies to skip a number of records before merging with the template with the data. When used in conjunction with MaxRecords, the query can be paged in manageable size pages. FirstRecord has no effect on single record templates.
Example 4: this form defines a very simple search of a file called cars, by year and make. The end user has the option to specify a single year or make or a range of years or makes. For the purpose of clarity for the end user, the form contains a table to lineup the fields.
<form action="http://paul/cgi-bin/FlexSearch.pl"method="get"> <input type="hidden" name="Operation"value="Search"> <input type="hidden" name="DataFile"value="cars.dat"> <input type="hidden" name="NoRecordTemplate"value="Default"> <input type="hidden" name="SingleRecordTemplate"value="Default"> <input type="hidden" name="MultiRecordTemplate"value="Default"> <input type="hidden" name="Search1" value="Year"> <input type="hidden" name="Search2" value="Make"> <table border="0" cellpadding="2" cellspacing="2"align="center"> <tr> <th>Characteristic </th> <th>Minimum Value </th> <th>Maximum Value </th> </tr> <tr> <th align="Right">Year </th> <td><input type="text" size="20" name="Year"> </td> <td><input type="text" size="20" name="Year_High"> </td> </tr> <tr> <th align="Right">Make </th> <td><input type="text" size="20" name="Make"> </td> <td><input type="text" size="20" name="Make_High"> </td> </tr> </table> <center> <input type="submit" value="Search"> <input type="reset"> </center> </form>
This produces a form that looks like:
The end user can specify a single year by filling in only the minimum value or a range by filling out both fields.
Lets extend the form above by adding a bracketed price selection list. To do this we will add an additional hidden search field to the top:
<input type="hidden" name="Search3" value="Price">
Then we will add an additional object to the bottom of the form before the buttons, notice that on this for we use the name Price_Range instead of Price. This causes FlexSearch to get the high and low values to both come from the same field. This list can only select a single preselected range, later I wiill show you how to use multiple selection lists.
<b>Price</b><br> <select name="Price_Range" size="5"> <option value="0-5000">0 - $5,000</option> <option value="5001-10000">$5,001 - $10,000</option> <option value="10000-15000">$10,001 - $15,000</option> <option value="15000-999000">$15,000 - $999,000</option> </select><br>
The $999,000 was used to provide an arbitrarily high range value, if the most expensive entry in the data file was $30,000 then that could have been used. However $999,000 has the advantage that it will not likely have to be changed, when that new Ferrari comes on the lot.
This form looks like this:
By adding the price characteristic, it becomes likely that the end user will select values which cannot mutually be found. By either adding another hidden field:
<input type="hidden" name="SoftSearch" value="1">
Or by adding a check box field which allows the user to decide whether to soften the search tests:
<input type="checkbox" name="SoftSearch">Soften the Search<br>
You can increase the odds that a user will find the results that they want. The final form looks like this:
Example 5: This search form is produced by executing a series of queries of the data indexes to provide selection lists which are sensitive to the current content of the data. To produce this form we have to take advantage of the html template merging of FlexSearch. Template merging will be covered in detail later. The basic form is much what we had before but we will replace the field name form fields with selection lists:
<input type="hidden" name="Search1" value="Year"> <select name="Year" size="5" MULTIPLE > <option selected>-Any-</option> <!-- FlexSearch Multi-Record-Start cars.dat.Year--> <option>#Key#</option> <!-- FlexSearch Multi-Record-Stop --> </select>
<input type="hidden" name="Search2" value="Make"> <select name="Make" size="5" MULTIPLE > <option selected>-Any-</option> <!-- FlexSearch Multi-Record-Start cars.dat.Make--> <option>#Key#</option> <!-- FlexSearch Multi-Record-Stop --> </select>
Like the price selection list this list contains options, however here we are using the FlexSearch multi record functions to pull all of the index key values from the Year index and the Make index. Index files in FlexSearch are miniature data files which contain lists of records with a particular key value. We can make use of this to get a list of all the unique year values in the data file. Additionally, these selection lists are marked for multiple selections, this allows the user to select multiple years and or makes to get a larger list of search results.
Where before the form could be activate like any other html page, by addressing it, here we must ask FlexSearch to merge the form file as a template with the data files. To do this we will make what looks like a messy link, but is actually a fairly simple construction:
http://paul/cgi-bin/FlexSearch.pl?Operation=TemplateProcess&TemplateFile=car.html&DataFile=cars.dat&Record_Number=1
The first part of this link is a call to FlexSearch, the parameters are separated from the command by the ? symbol and each additional parameter is separated by a # symbol. Referring back to the information above, this command follows a search form, we have the operation, data file and a field value. The operation here is Template Process instead of search, this is the operation that search calls for each record that match the search criteria, here we specify a Record_Number, which we dont actually use. This allows for this search form to work quickly and easily. The final form looks like this:
You may have noticed the "-Any-" value, selection lists must return a value, the -Any-" is a special value which FlexSearch recognizes as an empty selection, just like on the original form when the user does not fill in a field.
Finally, it is possible to use JavaScript or VBScript to create a form where the user has the ability to change the priority of the search fields, this is more important when SoftSearch is in effect. If they make the fields that are more important to them the ones that get checked first, then the output would include the minimum number which met their criteria. I will leave the technology of this methodology to users who already understand these scripting tools.