| Author |
Message |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2818 Location: Germany |
|
Search for multiple words |
|
This modified search.php allows you to search for multiple words.
You can decide wether to search for any of the words or all of the words.
Installation:
Replace your old search.php with the new one.
| Description: |
|
 Download |
| Filename: |
search.zip |
| Filesize: |
1.44 KB |
| Downloaded: |
538 Time(s) |
|
|
| Tue Apr 18, 2006 8:06 pm |
|
 |
Guest
|
|
|
Please login to hide the ads.
|
|
|
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1955 Location: US |
|
|
|
works beautiful. how come this search isn't put in the main installation?
_________________ www.scodal.com is an example of cnr as a social forum - www.scottdizzle.com is an example of cnr as a personal website to share whatever cool stuff i feel like. i have another, but it's nsfw. pm me  |
|
| Thu Jun 08, 2006 12:18 pm |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1955 Location: US |
|
|
|
I'm confused now..
When I search for 'one word' it shows prev and next links like this:
 |  | http://www.website.com/search.php?skip=7&do=search&search=with |
That's fine and works, but it doesn't seem to be utilizing the other features of the form like the one from the original search result URL:
 |  | http://www.website.com/search.php?do=search&search=with&category=&year=0&month=0&day=0&search_boolean=or |
Does this perhaps have something to do with something in inc/show.news.php? I've played with the URL's and found that the proper way for them to work with pagination should look like this:
 |  | http://www.website.com/search.php?do=search&search=with+and&category=&year=0&month=0&day=0&search_boolean=or&skip=7 |
Specifically with &skip=x at the end for whatever reason (if it's first you get no results)
Can it be done? I can't figure it out.
_________________ www.scodal.com is an example of cnr as a social forum - www.scottdizzle.com is an example of cnr as a personal website to share whatever cool stuff i feel like. i have another, but it's nsfw. pm me  |
|
| Thu Feb 28, 2008 8:24 pm |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1955 Location: US |
|
|
|
Okay, I compared my show.news.php with the one from the main cnr download.. mine was slightly altered. So, now with the one from the original download it produces correct search URL:
 |  | http://www.website.com/search.php?do=search&search=the+search&category=&year=0&month=0&day=0&search_boolean=or |
But pagination occurs like this:
 |  | http://www.website.com/search.php?skip=7 |
So, it is show.news.php but how do I get all the extra infos in there? I'm sorry I'm so stupid lol
_________________ www.scodal.com is an example of cnr as a social forum - www.scottdizzle.com is an example of cnr as a personal website to share whatever cool stuff i feel like. i have another, but it's nsfw. pm me  |
|
| Mon Mar 03, 2008 7:52 am |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1955 Location: US |
|
|
|
Okay, decided to play with it some more. I got even closer! I changed all the links on show.news.php to this and it works.. but it's makeshift:
Prev Links:
 |  | <a href="'.($_GET['search'] ? '?do=search&search='.$_GET['search'] : '').'&category=&year0=&search_boolean=and'.$PHP_SELF.'&skip='.($skip - $number).'">\\1</a> |
Next Links:
 |  | <a href="'.($_GET['search'] ? '?do=search&search='.$_GET['search'] : '').'&category=&year0=&search_boolean=and'.$PHP_SELF.'&skip='.($skip + $number).'">\\1</a> |
Numbered Links:  |  | <a href="'.($_GET['search'] ? '?do=search&search='.$_GET['search'] : '').'&category=&year0=&search_boolean=and'.$PHP_SELF.'&skip='.$pages_skip.'">'.$j.'</a> |
And, that works.. but you can't use any filtering options, so I  |  | style="display: none" | on the fields 'category', 'date', and the 'any/all words' (defaulting on All Words cause I liked that it was more specific)
The reason this is makeshift is because.. look at how I hardcoded the info in the URL:
 |  | &category=&year0=&search_boolean=and |
That's so the links stop breaking during pagination.. I just can't figure out how to add the extras in the URL.. something with $_GET?
_________________ www.scodal.com is an example of cnr as a social forum - www.scottdizzle.com is an example of cnr as a personal website to share whatever cool stuff i feel like. i have another, but it's nsfw. pm me  |
|
| Wed Mar 05, 2008 7:39 am |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2818 Location: Germany |
|
|
|
 |  | something with $_GET? |
$_GET would work but the following is easier:
Replace the hardcoded stuff with $_SERVER['QUERY_STRING']
|
|
| Wed Mar 05, 2008 6:22 pm |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1955 Location: US |
|
|
| Thu Mar 06, 2008 6:56 pm |
|
 |
Mystic2010
Joined: 10 Jan 2007 Posts: 51
|
|
|
|
I'm having the following problem: Am currently using a search box for on my site.
 |  |
<form action="./admin/search.php" method="post">
<input name="do" type="hidden" value="search">
<input type="text" name="search" id="search" value="" />
<input type="submit" name="submit" id="submit" value="Zoek!" />
</form>
|
The problem is that if I input multiple words, I get no results, as if it doesn't search.
If I input only one word, the results do show.
The funny thing is that when using multiple words in search.php, results do show.
Also, how would it be possible to have the results shown on a predefined page instead of showing search.php? Would I need to use $user_query?
|
|
| Mon Mar 10, 2008 1:18 am |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1955 Location: US |
|
|
|
Ironically those 2 dilemmas you just mentioned are the 2 I sought to tackle and after much frustration and help from FI-DD it has been accomplished.
 |  | The problem is that if I input multiple words, I get no results, as if it doesn't search. If I input only one word, the results do show. |
This probably is because the URL that is generating from your search form. You must keep all of the code that FI-DD had supplied or else it won't calculate or add it to the URL after the search button is pressed. Links should always display something like this:
 |  | http://www.yoursite.com/search.php?do=search&search=your+search&category=&year=0&month=0&day=0&search_boolean=and |
Yours is probably doing what mine was doing for so long cause I too modified and deleted parts of the search form. The URL's I was getting (which worked for one word searches only) were just:
 |  | http://www.yoursite.com/search.php?do=search&search=word |
So, the solution? Well, it's tricky to modify the search form and make it still work. Here's what I ended up doing for mine:
 |  | <form method="get" action="search.php">
<input name="do" type="hidden" value="search">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" colspan="2">
<p align="center">
<input type="text" name="search" size="44" value="<?=$search; ?>"><font size="2"> </font><select size="1" name="category"><option value="">All</option><?=category_get_tree(' ', '<option value="{id}"[php]search_this_cat({id})[/php]>{prefix}{name}</option>'); ?></select><tr>
<td style="display: none" width="100%"><nobr><font size="2"> </font></nobr><font size="2">
</font>
<td style="display: none" width="1%"><?=makeDropDown($syear, 'year', $year); ?>
<font size="2">/<?=makeDropDown($smonth, 'month', $month); ?>/<?=makeDropDown($sday, 'day', $day); ?>
</font>
<tr>
<td width="100%" colspan="2">
<p align="center">
<font style="font-size: 9pt">Any word</font><input type="radio" name="search_boolean" value="or"> <font style="font-size: 9pt">All words</font><input type="radio" name="search_boolean" value="and" checked></font>
<input type="submit" value="Search"></table>
</form> |
I moved the search bar and categories box to be on the same line, and I hid (rather than delete) the date information using style="display: none"
 |  | Also, how would it be possible to have the results shown on a predefined page instead of showing search.php? Would I need to use $user_query? |
I don't know what $user_query does but I can tell you that you can point the search results to open on any page you want by modifying this line in your search form:
 |  | <form action="./admin/search.php" method="post"> |
to something like this:
 |  | <form method="get" action="whatev.php"> |
If you put it in an iframe it will fuck up, I forget why.. I just noticed it did and it was driving me crazy and I realized it was just the iframe.. If you iframe this with search history it will fuck up too. So, best way is just include it in a page and let the results show beneath similarly to show_news.php except you specify the template near the bottom of search.php.
Okay, that's all I can think to say about that. I hope it helps if not I can upload my files cause I got the search bar working really good.
_________________ www.scodal.com is an example of cnr as a social forum - www.scottdizzle.com is an example of cnr as a personal website to share whatever cool stuff i feel like. i have another, but it's nsfw. pm me  |
|
| Mon Mar 10, 2008 4:50 pm |
|
 |
Mystic2010
Joined: 10 Jan 2007 Posts: 51
|
|
|
|
Wow, thanks a lot scott! Never occured to me that the rest couldn't be left out. It explains it all though. I'll be sure to experiment with it and post results, as soon as my other problem (Help forum) gets fixed, as that's kinda killin me right now
But thanks for the swift reply!
|
|
| Mon Mar 10, 2008 7:35 pm |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1955 Location: US |
|
|
|
Uhoh, I just found out making all those changes to show.news.php makes the search pagination work but normal pagination breaks.
For example if you had index.php with basic include code:
 |  | <?php
$number = "10";
include("admin/show_news.php");
?> |
It would display 10 results and the pagination would link to this:
 |  | http://www.yoursite.com/$skip=10 |
Any idea how to get it to work with both pagination?
_________________ www.scodal.com is an example of cnr as a social forum - www.scottdizzle.com is an example of cnr as a personal website to share whatever cool stuff i feel like. i have another, but it's nsfw. pm me  |
|
| Thu Mar 13, 2008 7:24 pm |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2818 Location: Germany |
|
|
|
I guess, you just have to check for the search parameter:
If the search parameter is set in the url then add the search pagination. If it's not set then add the normal pagination.
Translated to php code:
 |  | $_GET['search'] ? 'Here comes the search pagination' : 'Here comes the normal pagination' |
|
|
| Wed Mar 19, 2008 6:50 pm |
|
 |
azn_romeo_4u
Joined: 18 Sep 2008 Posts: 60
|
|
|
|
 |  | Uhoh, I just found out making all those changes to show.news.php makes the search pagination work but normal pagination breaks.
For example if you had index.php with basic include code:
 |  | <?php
$number = "10";
include("admin/show_news.php");
?> |
It would display 10 results and the pagination would link to this:
 |  | http://www.yoursite.com/$skip=10 |
Any idea how to get it to work with both pagination? |
I think i figured it out...O_O took me 2 hours to gather all the information on the forums doing the search and messing with code. I'll post it up when I finish everything.
But I manage to be able to add the search form on the entire site without an iframe
Do searches base all words or any words (any words is a problem though, someone could input the word "a" and it will search everything for a, so I would only do "all words")
Fixed the site and search pagination error
|
|
| Sat Sep 20, 2008 9:38 am |
|
 |
azn_romeo_4u
Joined: 18 Sep 2008 Posts: 60
|
|
|
|
Massive problem with character limits and spaces. If you set a character limit of 3 letters, you can still use 2 spaces and one letter and it search for everything that has that letter in it. Takes a massive amount of cpu power if you have like 3000 news like me.
I think you should hard code letter limit in the php file somewhere, and do something about having multple spaces. And you can get errors like these if you did
...a... (dots are spaces)
 |  | Warning: preg_replace() [function.preg-replace]: Compilation failed: regular expression is too large at offset 44900 in /home/xxxx/public_html/mysql.class.php on line 215 |
this error repeats itself about 100,000 times (seriously) freeze up my computer.
|
|
| Sat Sep 20, 2008 10:18 am |
|
 |
nam

Joined: 23 Dec 2006 Posts: 122
|
|
|
|
Is it possible for the search result to show the number of entries found?
for example:
Your search for ????? found ??? entries.
|
|
| Sat Sep 20, 2008 3:40 pm |
|
 |
|