Latest Register Log In

+ Advanced Search


03/20/04 (Edited 03/11/14)

The simple search box is in your 'main index' template by default. You can create as many such boxes as you need wherever needed.

<form action="search.php?filled=1&condition=or" method="post">
<input type="text" name="search" size="30">
<select name="whichtype"><option value="links">search links</option><option value="all">search all</option></select>
<input type="submit" value="Search" class="button"></form>

In this HTML, there are a number of options you can configure. If you wish to force all simple searches to be 'search all', you can remove the whichtype select and change the form action url to search.php?filled=1&condition=or&whichtype=all . If you wish to only show results that contain all of the words, instead of any, change condition=or to condition=and. To do boolean searches use condition=bool. To search for a full phrase, use condition=like. If you want a articles search to skip to the first matching result's details page -- skipping the search results page entirely -- you can add an &feelinglucky=1 parameter to the end of the URL to do that (this works like google's "I'm Feeling Lucky" button).

You may also distribute search box code to let people put it on their own sites, so that they'll be sending you search requests. To allow this remote searches to count as hits in for the person's link, just add &id={LINKID} onto the end of the form action url, where {LINKID} is the id number of their link.

Note that you can set which fields are searched by the simple search box by going to settings->functionality in your admin panel and selecting the fields you desire.

The advanced search page offers more options. For each field by which you can filter results, you have the option of choosing a particular condition:

contains - Searches for a full phrase.
is exactly - Searches for an exact match where the field contains nothing but what you have typed.
is not - Searches for where the field does not contain exactly what you have typed.
is greater than - Any numeric field with a larger value yields a match.
is less than - Any numeric field with a smaller value yields a match.
has any of the words/values - If any word of your search phrase is in the field, it's a match.
has all of the values - If all the words of your search phrase are in the field (though not necessarily in order), it's a match.
is between - Any numeric field between the two numbers you type (separate with a space or comma) is a match. Important note: if you're doing a custom form where people will be doing a between search, you'll probably want to use two fields. Do it like this: <input type="hidden" name="fieldconditon" value="between"> Between <input type="text" name="fieldsearch"> and <input type="text" name="fieldsearchmax">
boolean - Boolean searches allow you to use "and" and "or" as operators, and to group them with parenthases. A boolean search "books or videos" would return all results which contain either the word "books" or the word "videos". You can also use parenthases to group combinations. A boolean search for "(books or videos) and cheap" would find all results which contain either "books" or "videos", only so long as they also contain "cheap".

You can reconfigure a simple search box to some of the above options by changing the "condition=or" part of the form action URL. The condition options available are "or" (has any of the words, the default), "and" (has all of the words), "bool" (boolean search), "like" (contains), and "not" (not equal to).

You can extend the advanced search page to handle custom fields you create. Just copy the existing fields and change names like 'urlcondition' and 'urlsearch' to 'yourfieldcondition' and 'yourfieldsearch'.

For example, in your advanced search template, you could find
<input type="text" size="{STANDARDSIZE}" name="urlsearch" >
and place the following below it to handle a search for a field named yourfield:

<br >and your field
<select name="yourfieldcondition">
<option value="like"></option>
<option value="="></option>
<option value="or"></option>
<option value="and"></option>
<option value="!="></option>
<option value="bool"></option>
<input type="text" size="{STANDARDSIZE}" name="yourfieldsearch" >

To restrict to a particular category plus its subcategories (all the way down) you can set a value for incat. To restrict to just a category itself, set catid.

In some cases, you may want to construct an advanced search form where people can search for values in various fields and in all fields at once in one of the boxes. For example: "Find books where the title contains 'example' and any of the fields contains 'other'." You can do this by using a special pseudofield: 'allfields'. When you replace the field name with allfields it works to search all fields for the value in that box. You'll use allfieldscondition and allfieldssearch in your form as you would with real fields.

Search Results Pages

Some special template variables for the search results pages:

{SEARCHTERM} - The term being searched for.
{NUMRESULTS} - The number of results.
{NUM + type + RESULTS} - The number of results for the specified article type. For example, {NUMREGULARRESULTS} gives the number of regular type results and {NUMSPONSORRESULTS} gives the number of sponsor results.

More detailed articles about doing things with the search feature:

Description Configuring simple and advanced search.
Views 2537 views. Averaging 0 views per day.
Similar Listings