homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

advanced search engine help

 4:47 pm on Aug 26, 2004 (gmt 0)

I have a couple of sites built with different databases because all these sites are under different subject. And the databases have been built for a long time already. I want to make a global search engine so if you search for ie. "berry", it would display results from all databases that have the search word.

Right now, if people want to search for "berry", they would have to go to my A database to search for it. Then if they want to search for "berry" from my B database, they would have to go there to search. So it's very inconvenient. I know I could just incorporate all the databases together into one big database, but I don't want to do that.

I hope I haven't lost anyone yet. Does anyone have any idea of doing that? Thanks.



 7:08 pm on Aug 26, 2004 (gmt 0)

you'd need to make separate connections to each database in turn. Throw your "hits" from database A into an array, then add the hits from database B, then when you're done sort the array to display the results.


 1:35 pm on Aug 28, 2004 (gmt 0)

Welcome to WebmasterWorld, someone!


 11:49 pm on Aug 29, 2004 (gmt 0)

As long as you have your indexs setup properly, you should be able to search on more than one table at the same time.

worse case, you can use a JOIN statement and join two tables together.


 3:56 pm on Aug 31, 2004 (gmt 0)

coopster, thanks for the welcom.
httpwebwitch and JasonHamilton, thanks for the hints.


 5:50 pm on Aug 31, 2004 (gmt 0)

yes, are you talking about separate DSNs, separate databases, or multiple tables in the same database?

if you have multiple databases in the same "database" (e.g. mySQL), then you can use

// do query
// do another query

If you have multiple tables in the same database, then as mentioned above you can try a JOIN or UNION or something. I am hardly capable of giving advice on that subject... Hopefully someone will jump in with a solution, if there is one.

Regardless of the method you use to grab the hits, you will want to "mix" and sort the results by relevance. If there is a way to do it with just SQL, then do that! But it's easier to do in PHP, once you've grabbed all the close hits and thrown them into an array.

$hits[0]['title]="this is my page"

$hits[1]['title]="this is your page"

then you can sort the array by relevance, and show them in order.


 11:08 am on Sep 1, 2004 (gmt 0)

If these truly are 3 different databases and not just 3 different tables as you say, you will probably want to combine the 3 databases into just one database nonetheless since connecting to databases can take time, and connecting to 3 different databases would, I imagine, result in a lot of work for your server, and time waiting for your users. 3 tables would be the way to go - using a join, as mentioned above, would speed things up tremendously.

If searching is really key to the functionality to your site, you could also set up another table that just has all the information from your other tables that you want searchable in one field, and an identifier or url in another field corresponding to the page all that info is on. This could use a fulltext index for better search relevance. It'll use a lot of hard disk space, but hard disk space is cheap these days.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved