Search for multiple words

Download plugins, language packs and stuff.

Search for multiple words

Postby FI-DD » Tue Apr 18, 2006 8:06 pm

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.
Attachments
search.zip
search.php
(1.44 KiB) Downloaded 737 times
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby scottdallas » Thu Jun 08, 2006 12:18 pm

works beautiful. how come this search isn't put in the main installation?
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby scottdallas » Thu Feb 28, 2008 8:24 pm

I'm confused now..

When I search for 'one word' it shows prev and next links like this:
Code: Select all
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:
Code: Select all
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:

Code: Select all
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.
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby scottdallas » Mon Mar 03, 2008 7:52 am

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
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby scottdallas » Wed Mar 05, 2008 7:39 am

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:
Code: Select all
<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:
Code: Select all
<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
Code: Select all
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:
Code: Select all
&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?
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby FI-DD » Wed Mar 05, 2008 6:22 pm

scottdallas wrote:something with $_GET?

$_GET would work but the following is easier:

Replace the hardcoded stuff with $_SERVER['QUERY_STRING']
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby scottdallas » Thu Mar 06, 2008 6:56 pm

And you were right! So, here's the modified show.news.php file we all need to make this multiple word search to work :)
Attachments
shownews.zip
Replace this show.news.php with your /inc/show.news.php
(3.06 KiB) Downloaded 175 times
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby Mystic2010 » Mon Mar 10, 2008 1:18 am

I'm having the following problem: Am currently using a search box for on my site.

Code: Select all
              <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?
Mystic2010
 
Posts: 51
Joined: Wed Jan 10, 2007 6:36 pm

Postby scottdallas » Mon Mar 10, 2008 4:50 pm

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:

Code: Select all
<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">&nbsp;</font><select size="1" name="category"><option value="">All</option><?=category_get_tree('&nbsp;', '<option value="{id}"[php]search_this_cat({id})[/php]>{prefix}{name}</option>'); ?></select><tr>
  <td style="display: none" width="100%"><nobr><font size="2">&nbsp;</font></nobr><font size="2">&nbsp;
  </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">&nbsp;&nbsp;<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:
Code: Select all
<form action="./admin/search.php" method="post">


to something like this:

Code: Select all
<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.
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby Mystic2010 » Mon Mar 10, 2008 7:35 pm

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!
Mystic2010
 
Posts: 51
Joined: Wed Jan 10, 2007 6:36 pm

Postby scottdallas » Thu Mar 13, 2008 7:24 pm

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:
Code: Select all
<?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?
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby FI-DD » Wed Mar 19, 2008 6:50 pm

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:
Code: Select all
$_GET['search'] ? 'Here comes the search pagination' : 'Here comes the normal pagination'
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby azn_romeo_4u » Sat Sep 20, 2008 9:38 am

scottdallas wrote: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:
Code: Select all
<?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
azn_romeo_4u
 
Posts: 123
Joined: Thu Sep 18, 2008 5:06 am

Postby azn_romeo_4u » Sat Sep 20, 2008 10:18 am

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.
azn_romeo_4u
 
Posts: 123
Joined: Thu Sep 18, 2008 5:06 am

Postby nam » Sat Sep 20, 2008 3:40 pm

Is it possible for the search result to show the number of entries found?

for example:

Your search for ????? found ??? entries.
User avatar
nam
 
Posts: 221
Joined: Sat Dec 23, 2006 9:10 pm

Next

Return to Additional Downloads



Who is online

Users browsing this forum: No registered users and 0 guests

cron