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).]
Quote Reply
Re: One solution to range searches in Links... In reply to
Very nice modification! You should consider putting it in the Modification or FAQ section in the Resource Center.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
http://www.anthrotech.com
Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
----------------------





Quote Reply
Re: One solution to range searches in Links... In reply to
Thanks. It's already in the Mod section. Searching strictly by text is passe...

------------------
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)
Quote Reply
Re: One solution to range searches in Links... In reply to
Cool...Haven't looked at the Mod section in about a week...

Smile

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
http://www.anthrotech.com
Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
----------------------





Quote Reply
Re: One solution to range searches in Links... In reply to
I wanted to test this for votes.

I added:
Code:
($in{'query'} or $in{'Votes'} or &site_html_search_form and return;

Then I added:
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;
}
}
}
I made sure to take out all the spaces between | |.

Then, to search.html, I added:
Code:
<input type="TEXT" name="Votes" VALUE="" size="5">

I kept getting a server error - 500. I switched the search.html code to:

Code:
<tr>
<td>
<font face="Verdana" size="2">
<b>Votes:</b>
<select name="Votes">
<option value="">Choose one of the following:
<option value="<10">Less Than 10
<option value="<20">Less Than 20
<option value="<30">Less Than 30
<option value="<40">Less Than 40
<option value="<50">Less Than 50
<option value="<60">Less Than 60
<option value="<70">Less Than 70
<option value="<80">Less Than 80
</select>
</font>
</td></tr>

And, I still keep getting a server error - 500.

Would anyone have any ideas? I think I followed everything correctly.

Thanks.

[This message has been edited by DogTags (edited January 23, 2000).]
Quote Reply
Re: One solution to range searches in Links... In reply to
Hmmm... got it working on my site. There are a couple things I can think of...

1) did you comment out this line?
Code:
# (keys %in <= 0) and &site_html_search_form() and return;
2) do you have FOUR closing brackets before $andmatch = $andmatch && $match;
in the sub search clause? In my original directions, I did not replace the opening if statement
Code:
if ($or_match &#0124; &#0124; $match &#0124; &#0124; !$regexp) {
or the closing bracket right before $andmatch = $andmatch && $match;. It should look like this...
Code:
$match or last FIELD;
}
}
}
}
$andmatch = $andmatch && $match;

3) Did you try this mod on a clean version of search.cgi or do you have other mods to this function?

Let me know if this helped...


------------------
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)
Quote Reply
Re: One solution to range searches in Links... In reply to
Yep, commented out that line, have 4 closing brackets, but I do use the Shetapolov mod, which searches for keywords in db.

I'll try a clean search.cgi and let you know.

Thanks.
Quote Reply
Re: One solution to range searches in Links... In reply to
Hi Oldmoney et al,

The error is because in the very first post by Oldmoney, the code:

Quote:
($in{'query'} or $in{'Cost'} or $in{'Votes'} or &site_html_search_form and return;

starts with a left bracket ( and there is no closing bracket in the statement. Where should the closing "right bracket" ) be?

Also, in links def we have search@(1,2,3) etc., I thought this would already search by fields.

Thanks
Quote Reply
Re: One solution to range searches in Links... In reply to
Yep, you found it, Socrates. I should check my typing a little better. The line should be...
Code:
($in{'query'} or $in{'Cost'} or $in{'Votes'}) or &site_html_search_form and return;
and I have also fixed it in the instructions above. Thanks for catching my typo... the reason for delineating the primary search fields in the line in question is that it creates an "optional" AND condition as opposed to the default AND condition so that you can search by any one (or of course more) of the fields from the same form. For example, without the mod, searching for

Category=
City=New York

will literally search for records with a blank Category, where what you want is ALL records with New York and any Category. And yeah, I know about the bool=OR, but consider this example,

Category=
City=New York
Price= <50.00

Here, you definately don't want the OR because you are not looking for all records with New York OR a price below 50.00, and you don't want the blank behavior on Category I mentioned above... make sense now?

------------------
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)

[This message has been edited by oldmoney (edited April 07, 2000).]
Quote Reply
Re: One solution to range searches in Links... In reply to
Hey thanks. I'll plug this in. Smile
Quote Reply
Re: One solution to range searches in Links... In reply to
Oldmoney,

have you tried this mod with other search mods ?
I have installed altavistasearch mod and exact and date search.
Your mod only works when I enter for example an exact value. I have search by hits and when I enter 1500 and theres a link i get the result but when I enter for example >1500
I get many results even with 9 or 245 hits.
Do you have any idea why this could happen ?
Would be cool if you can give me a hint Wink
cya,

nikolai
Quote Reply
Re: One solution to range searches in Links... In reply to
 
Quote:
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...

I do not have an answer for you, sorry.

------------------
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)

Quote Reply
Re: One solution to range searches in Links... In reply to
I have wseen that you didn't modify your search.cgi before but i asked because this was in January Smile
I thought that you could have modded it until now Wink
Is there anyone else who has experienced same problems like me and who has found a solution ?
cya,

nikolai
nikolai
Quote Reply
Re: One solution to range searches in Links... In reply to
 Smile cool one...
Frown sad I did'nt get to know about it earlier.

Thanks.
Take care.
Quote Reply
Re: One solution to range searches in Links... In reply to
This Mod is linked in the Resource Center in the Links: Modification section.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: One solution to range searches in Links... In reply to
Hi Guys,

This is not working for me specifically the the comparison thing "< 20,000" . I have fileds with price information and most of them are 5 digits and include a comma like 100,000 etc., I am not sure if the comma is causing the problem. Any feedback?

Thanks

Quote Reply
Re: One solution to range searches in Links... In reply to
<blockquote><font size=1>In reply to:</font><hr><p>
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).
<p><hr></blockquote><p>
I believe that the <b>comma</b> could also be a part of the problem related to decimals as <b>oldmoney</b> has stated.

Regards,

Eliot Lee
Anthro TECH, L.L.C
Web: http://www.anthrotech.com/
Quote Reply
Re: One solution to range searches in Links... In reply to
Thanks, Eliot.

Quote Reply
Re: One solution to range searches in Links... In reply to
You're welcome.

Regards,

Eliot Lee
Anthro TECH, L.L.C
Web: http://www.anthrotech.com/
Quote Reply
Re: One solution to range searches in Links... In reply to
I just finished installing this mod and can't seem to get it to work for me, I get:

Code:
'D:\WWW\yourmaine\cgi-bin\links2\search.cgi' script produced no output
I do have the Altavista search mod installed, so I think it's connected to that, possably here:

# (keys %in <= 0) and &site_html_search_form() and return;
($in{'query'} or $in{'Town'}) or &site_html_search_form and return;
($in{'search'} eq "theweb") and &altavista;
($in{'search'} eq "both") and &altavista;


I don't want to make this message too long so instead of posting the rest of the hacked sections here I'll put a copy of the search.cgi here:

http://www.yourmaine.com/temp/search.txt

In Reply To:
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...
I understand you may not have the answer, but if not, maybe some other kind person who has seen this maybe able to help.

Thanks!!

Mike

Quote Reply
Re: [Just_Lost] One solution to range searches in Links... In reply to
I have question to all of you. Is this mod applicable if I want to make a link result to that I can control several sites to come out first?

let say I have a site for PHPone.com and I add a new field in the links let say "specialfield" and I key in the keyword "PHP & programming" then when someone search for PHP or even programming I want my site php will be ahead of other results. Is this possible? can anybody help?