Forum Index
RegisterSearchFAQMemberlistUsergroupsLog in
Search for multiple words
Goto page 1, 2  Next
 
Reply to topic    Forum Index » Additional Downloads View previous topic
View next topic
Search for multiple words
Author Message
FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2818
Location: Germany

Post Search for multiple words Reply with quote
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.



search.zip
 Description:
search.php

Download
 Filename:  search.zip
 Filesize:  1.44 KB
 Downloaded:  538 Time(s)

Tue Apr 18, 2006 8:06 pm View user's profile Send private message
Guest








Please login to hide the ads.

scottdallas



Joined: 04 May 2006
Posts: 1955
Location: US

Post Reply with quote
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 Wink
Thu Jun 08, 2006 12:18 pm View user's profile Send private message Visit poster's website AIM Address
scottdallas



Joined: 04 May 2006
Posts: 1955
Location: US

Post Reply with quote
I'm confused now..

When I search for 'one word' it shows prev and next links like this:
Code:
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:
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:
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 Wink
Thu Feb 28, 2008 8:24 pm View user's profile Send private message Visit poster's website AIM Address
scottdallas



Joined: 04 May 2006
Posts: 1955
Location: US

Post Reply with quote
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:
Quote:
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:
Quote:
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 Wink
Mon Mar 03, 2008 7:52 am View user's profile Send private message Visit poster's website AIM Address
scottdallas



Joined: 04 May 2006
Posts: 1955
Location: US

Post Reply with quote
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:
<a href="'.($_GET['search'] ? '?do=search&search='.$_GET['search'] : '').'&category=&year0=&search_boolean=and'.$PHP_SELF.'&skip='.($skip - $number).'">\\1</a>


Next Links:
Quote:
<a href="'.($_GET['search'] ? '?do=search&search='.$_GET['search'] : '').'&category=&year0=&search_boolean=and'.$PHP_SELF.'&skip='.($skip + $number).'">\\1</a>


Numbered Links:
Code:
<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:
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:
&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 Wink
Wed Mar 05, 2008 7:39 am View user's profile Send private message Visit poster's website AIM Address
FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2818
Location: Germany

Post Reply with quote
scottdallas wrote:
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 View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1955
Location: US

Post Reply with quote
And you were right! So, here's the modified show.news.php file we all need to make this multiple word search to work Smile



shownews.zip
 Description:
Replace this show.news.php with your /inc/show.news.php

Download
 Filename:  shownews.zip
 Filesize:  3.06 KB
 Downloaded:  50 Time(s)


_________________
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 Wink
Thu Mar 06, 2008 6:56 pm View user's profile Send private message Visit poster's website AIM Address
Mystic2010



Joined: 10 Jan 2007
Posts: 51

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

Code:

              <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 View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1955
Location: US

Post Reply with quote
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.

Quote:
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:

Quote:
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:

Quote:
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:
<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"

Quote:
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:
<form action="./admin/search.php" method="post">


to something like this:

Code:
<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 Wink
Mon Mar 10, 2008 4:50 pm View user's profile Send private message Visit poster's website AIM Address
Mystic2010



Joined: 10 Jan 2007
Posts: 51

Post Reply with quote
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 Sad

But thanks for the swift reply!
Mon Mar 10, 2008 7:35 pm View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1955
Location: US

Post Reply with quote
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:
<?php
$number = "10";
include("admin/show_news.php");
?>


It would display 10 results and the pagination would link to this:
Quote:
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 Wink
Thu Mar 13, 2008 7:24 pm View user's profile Send private message Visit poster's website AIM Address
FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2818
Location: Germany

Post Reply with quote
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:
$_GET['search'] ? 'Here comes the search pagination' : 'Here comes the normal pagination'

Wed Mar 19, 2008 6:50 pm View user's profile Send private message
azn_romeo_4u



Joined: 18 Sep 2008
Posts: 60

Post Reply with quote
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:
<?php
$number = "10";
include("admin/show_news.php");
?>


It would display 10 results and the pagination would link to this:
Quote:
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 View user's profile Send private message
azn_romeo_4u



Joined: 18 Sep 2008
Posts: 60

Post Reply with quote
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)


Quote:
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 View user's profile Send private message
nam



Joined: 23 Dec 2006
Posts: 122

Post Reply with quote
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 View user's profile Send private message
Display posts from previous:    
Reply to topic    Forum Index » Additional Downloads All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Music Lyrics.