Advanced Search: Forcing additional search terms
In rare cases it is necessary to create a custom search form in which search terms are entered in multiple form fields. FDSE accepts search terms via the main "Terms" form field and also from optional form fields named "p:q1", "p:q2", "p:q3"... "p:qn". Internally, all search strings from the various fields are joined together, separated by spaces, and FDSE then applies its usual rules for finding matching pages. In practice you will want to force the Match=1 setting so that all terms will be required to match.
Example - Forced, Hidden Terms
Here is an example of how to create a search form which only finds results in a certain subfolder of your site, by forcing a required search term of "url:www.xav.com/scripts/search":
<form method="get" action="search.pl">
<input type="hidden" name="Match" value="1" />
<input type="hidden" name="p:q1" value="url:www.xav.com/scripts/search" />
Keywords: <input name="Terms" /> <input type="submit" />
</form>
| ( input "Keywords" required ) |
Example - Multiple Inputs
Here is an example of a search form which mixes a freeform search box with an enumerated list of search criteria:
<form method="get" action="search.pl">
<input type="hidden" name="Match" value="1" />
Title contains <select name="p:q1">
<option value="title:foo">foo</option>
<option value="title:bar">bar</option>
<option value="title:xxx">xxx</option>
</select><br />
Keywords: <input name="Terms" /> <input type="submit" />
</form>
| ( input "Keywords" required ) |
Limitations
-
The visitor performing the search will see all of the search criteria listed in the header section where it says "Your search for x,y,z found the following documents...", and so it is not possible to fully hide the criteria.
-
The "view with highlighted search terms" feature will only recognize terms from the "Terms" form field or its aliases "terms" and "q". It will not use secondary "p:q*" form fields. See Advanced Search: Forcing additional search terms for details on secondary form fields.
-
The additional search terms will be persisted through the Previous, Next, and numbered links when there are multiple pages of results. However, to have the additional search terms persisted through the default search form which appears at the bottom of the search results, you will have to mirror the additional form fields in the "searchform.htm" template.
-
The correct way to implement this feature would be for FDSE to evaluate each set of search terms in the "Terms", "p:q1", "p:q2", etc., fields, and perform a logical AND operation over all groups. Thus if "Terms" is "foo bar" and "p:q1" is "dog cat" and the search is set to "Match Any Term", then FDSE should return pages matching ("foo" OR "bar") AND ("dog" OR "cat"). But... FDSE does not do this, because it lacks full support of complex Boolean statements. Instead, it would interpret the above search query as ("foo" OR "bar" OR "dog" OR "cat") and thus it might return some search results which contained only "dog" or "cat" but did not contain either of the visitor-supplied terms "foo" or "bar". The workaround of forcing "Match All Terms" should avoid this scenario. Support for complex Boolean queries is on the to-do list.
Required field behavior
FDSE will only enter into "search mode" if the "Terms" variable is non-empty. When the "Terms" variable is empty, FDSE will display the search tips page, even if other "p:q1" and "p:q2" fields are present and contain search terms.
To override this behavior, create a hidden field named "Terms" and give it a fixed value " " (blank space). Then name your free-form text input as p:qn. Then, all form submissions will result in searching, even if the free-form text input is blank.
<form method="get" action="search.pl">
<input type="hidden" name="Match" value="1" />
<input type="hidden" name="Terms" value=" " />
Title contains <select name="p:q1">
<option value="title:foo">foo</option>
<option value="title:bar">bar</option>
<option value="title:xxx">xxx</option>
</select><br />
Keywords: <input name="p:q2" /> <input type="submit" />
</form>
| ( input "Keywords" NOT required ) |
History: the additional search terms functionality was added in FDSE version 2.0.0.0052.
"Advanced Search: Forcing additional search terms"
http://www.xav.com/scripts/search/help/1120.html