Gossamer Forum
Home : Products : Links 2.0 : Customization :

One solution to range searches in Links...

Quote Reply
One solution to range searches in Links...
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...
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;
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
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;
}
}
with this
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;
}
}
}
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...
Code:
<input type="TEXT" name="Votes" VALUE="" size="5">
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).]
Subject Author Views Date
Thread One solution to range searches in Links... oldmoney 7296 Jan 17, 2000, 8:14 AM
Post Re: One solution to range searches in Links...
Eliot 7230 Jan 20, 2000, 6:47 PM
Post Re: One solution to range searches in Links...
oldmoney 7213 Jan 20, 2000, 7:25 PM
Post Re: One solution to range searches in Links...
Eliot 7220 Jan 20, 2000, 7:38 PM
Post Re: One solution to range searches in Links...
DogTags 7236 Jan 23, 2000, 8:01 PM
Post Re: One solution to range searches in Links...
oldmoney 7218 Jan 24, 2000, 12:06 PM
Post Re: One solution to range searches in Links...
DogTags 7230 Jan 25, 2000, 6:41 PM
Post Re: One solution to range searches in Links...
socrates 7254 Apr 6, 2000, 12:44 PM
Post Re: One solution to range searches in Links...
oldmoney 7230 Apr 6, 2000, 7:19 PM
Post Re: One solution to range searches in Links...
DogTags 7211 Apr 10, 2000, 3:46 AM
Post Re: One solution to range searches in Links...
DigitalFusion 7228 Apr 10, 2000, 4:30 AM
Post Re: One solution to range searches in Links...
oldmoney 7229 Apr 10, 2000, 4:36 AM
Post Re: One solution to range searches in Links...
DigitalFusion 7232 Apr 10, 2000, 6:07 AM
Post Re: One solution to range searches in Links...
kapil 7230 May 4, 2000, 12:04 PM
Thread Re: One solution to range searches in Links...
Stealth 7251 May 4, 2000, 2:18 PM
Thread Re: One solution to range searches in Links...
socrates 7298 May 18, 2000, 10:07 PM
Thread Re: One solution to range searches in Links...
Stealth 7229 May 18, 2000, 10:12 PM
Thread Re: One solution to range searches in Links...
socrates 7320 May 18, 2000, 10:19 PM
Post Re: One solution to range searches in Links...
Stealth 7275 May 18, 2000, 10:48 PM
Thread Re: One solution to range searches in Links...
Just_Lost 6320 Oct 3, 2000, 8:13 AM
Post Re: [Just_Lost] One solution to range searches in Links...
ginblossom 5393 Dec 2, 2001, 6:40 PM