Fooled around with the search.cgi last night and got range searches to work (solving the search for links with a cost of less than-- or more than-- X). A caveat: I have not previously modded my search.cgi routines, so if you have installed the search this subcategory or search sort mods, your mileage may vary...
In search.cgi, comment out this line...
Add this line below it, EXPLICITLY DEFINING which fields you want to make primary search parameters (thanks for solution by Widgetz in earlier thread for this)...
This example would allow searches by text (as normal) AND/OR searches by cost AND/OR searches by number of votes. By primary search parameter, I mean you can select just this option (cost, or text, or votes) and the search will work. If you leave one or more fields out of this list, you effectively require that another primary search parameter also be chosen for the search to work.
In sub_search, replace this
if ($or_match) {
$match = $match | | ($in{$db_cols[$field]} eq $values[$field]);
$match and last FIELD;
}
else {
$match = ($in{$db_cols[$field]} eq $values[$field]);
$match or last FIELD;
}
}with this
if ($in{$db_cols[$field]} ne "") {
if ($or_match) {
if ($in{$db_cols[$field]} =~ m/>(.+?)/) { $match = $match | | ($in{$db_cols[$field]} eq $values[$field]) | | ($1 < $values[$field]); }
elsif ($in{$db_cols[$field]} =~ m/<(.+?)/) { $match = $match | | ($in{$db_cols[$field]} eq $values[$field]) | | ($1 > $values[$field]); }
else { $match = $match | | ($in{$db_cols[$field]} eq $values[$field]); }
$match and last FIELD;
}
else {
if ($in{$db_cols[$field]} =~ m/>(.+?)/) { $match = ($in{$db_cols[$field]} eq $values[$field]) | | ($1 < $values[$field]); }
elsif ($in{$db_cols[$field]} =~ m/<(.+?)/) { $match = ($in{$db_cols[$field]} eq $values[$field]) | | ($1 > $values[$field]); }
else { $match = ($in{$db_cols[$field]} eq $values[$field]); }
$match or last FIELD;
}
}
}Make sure you take out the spaces between the | | above (or), which this BBS puts in.
In search.html, add your new search parameters. For example, to enable range searching by number of votes, add...
You should instruct your users that if they leave the field blank, the parameter will be ignored. If they want to search for an exact value, type in the value. If they want to search for a range, use < for less than and > for greater than. So, >0 in the previous field would look for all links with at least one vote.
Note that null searches are never processed. Also, I have not added codes to convert decimals, so if you are doing a search on say a cost field, the search will either *fail* or *produce unexpected results* if decimals are not used in the input (>0.00 versus >0).
Let me know if it worked for you... I may try to combine thsi with range date searches in the future.
------------------
The Immuatable Order of Modding
-=-=-=-=-=-=-=-
1. Read the FAQ, 2. Search the board, 2a. Search the board again, 3. ask the question, 4. back-up, 5. experiment, 6. rephrase question (or better yet, post solution to original question)
Typo fixed...
[This message has been edited by oldmoney (edited April 06, 2000).]
In search.cgi, comment out this line...
Code:
# (keys %in <= 0) and &site_html_search_form() and return;Add this line below it, EXPLICITLY DEFINING which fields you want to make primary search parameters (thanks for solution by Widgetz in earlier thread for this)...
Code:
($in{'query'} or $in{'Cost'} or $in{'Votes'}) or &site_html_search_form and return;In sub_search, replace this
Code:
FIELD: foreach $field (@field_search) { if ($or_match) {
$match = $match | | ($in{$db_cols[$field]} eq $values[$field]);
$match and last FIELD;
}
else {
$match = ($in{$db_cols[$field]} eq $values[$field]);
$match or last FIELD;
}
}
Code:
FIELD: foreach $field (@field_search) { if ($in{$db_cols[$field]} ne "") {
if ($or_match) {
if ($in{$db_cols[$field]} =~ m/>(.+?)/) { $match = $match | | ($in{$db_cols[$field]} eq $values[$field]) | | ($1 < $values[$field]); }
elsif ($in{$db_cols[$field]} =~ m/<(.+?)/) { $match = $match | | ($in{$db_cols[$field]} eq $values[$field]) | | ($1 > $values[$field]); }
else { $match = $match | | ($in{$db_cols[$field]} eq $values[$field]); }
$match and last FIELD;
}
else {
if ($in{$db_cols[$field]} =~ m/>(.+?)/) { $match = ($in{$db_cols[$field]} eq $values[$field]) | | ($1 < $values[$field]); }
elsif ($in{$db_cols[$field]} =~ m/<(.+?)/) { $match = ($in{$db_cols[$field]} eq $values[$field]) | | ($1 > $values[$field]); }
else { $match = ($in{$db_cols[$field]} eq $values[$field]); }
$match or last FIELD;
}
}
}
In search.html, add your new search parameters. For example, to enable range searching by number of votes, add...
Code:
<input type="TEXT" name="Votes" VALUE="" size="5">Note that null searches are never processed. Also, I have not added codes to convert decimals, so if you are doing a search on say a cost field, the search will either *fail* or *produce unexpected results* if decimals are not used in the input (>0.00 versus >0).
Let me know if it worked for you... I may try to combine thsi with range date searches in the future.
------------------
The Immuatable Order of Modding
-=-=-=-=-=-=-=-
1. Read the FAQ, 2. Search the board, 2a. Search the board again, 3. ask the question, 4. back-up, 5. experiment, 6. rephrase question (or better yet, post solution to original question)
Typo fixed...
[This message has been edited by oldmoney (edited April 06, 2000).]