Forum Moderators: coopster

Message Too Old, No Replies

PHP Site Search

Searching the site using PHP and contents of Database

         

Francis

3:06 am on Sep 1, 2003 (gmt 0)

10+ Year Member



Question?

Can I do an entire site search using a keyword (or keywords) using PHP but the search should search through the contents of the databases, as well as HTML and PHP files in one pass (meaning I'll type the keyword and the script will search for it on the databases, HTML, and PHP files that I have)?

I am doing a site that has some files (PHP) included (because the content is long and I think that it should not be inside a database), and some are in the database (because the content to be displayed is short).

So what I want to happen is when somebody does a search, they just type in the keyword and the script would do the search through all the different databases (and tables), as well as in the HTML and PHP files that I include?

I hope that my question is clear.

Also, can you point me to a resource where I can do more reading on this preferrably online because books cost a lot in this side of the globe.

Thanks again.

Forever newbie,

Francis

Mark_A

3:27 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



dont know the answer but will sticky you some links to get you started

hope that helps

justageek

4:08 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would suggest you put all your data in a database. I use mysql and I have no problems whatsoever. Testing on about 200k pages shows very fast returns and since mysql has a built in query cache now it is even faster than ever. What that means is that if some searches your site in the db for the word 'Internet' the first time it will be slow if you use a fulltext index. Slow being about .25 seconds or so for my 200k records. The second time someone searches for the word 'Internet' the results will be returned in about .003 seconds. Interestingly enough, the more complex the search such as 'Internet search engine' the faster the return the first time.

You may want to make sure that you massage your data a bit before you put it in the database. Blow away all the html tags and such as you don't really need to store it and most people won't be searching for 'href' in a web page unless they can actually see it :-)

Francis

1:46 am on Sep 2, 2003 (gmt 0)

10+ Year Member



justageek,

I've also thought of putting the entire thingamajig on the database, however, the content would contain links (thus the href). The contents would basically be laws (such as Presidential Decrees, etc., so the content of one record would be reaaaaalllly long. Any suggestions on how to go about with this?

Also, can I do multiple table search? Or at the very least any idea how to do it?

Mark_A,

Thanks a lot for the links. I'll check them out and look for answers.

Francis...

justageek

2:46 am on Sep 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could put the whole thing in there. There really is no need to have the <a href='http://www.whatever.com'> part in there but the text that says 'Click here to go to www.whatever.com' could still be in there easy enough so the user could still search on the link text. Do something like (you may want to check this part because I'm tired) $str = preg_replace("/<((\/?\b)[^>]*>)/xis", " ", $str) which should leave the link text alone and just blow away the tags.

You really don't have to worry about the amount of data that gets stored in the record. Mysql can handle it just fine ;-)

As far as doing multiple table searches goes I guess I'd have to know more about what it is you want to do. At a minimum you can pull back a record from one table and while you are in a while getting the data you can do something else with the data to another table.

[edited by: jatar_k at 5:05 pm (utc) on Sep. 5, 2003]
[edit reason] disabled smileys [/edit]

Francis

12:43 am on Sep 3, 2003 (gmt 0)

10+ Year Member



Thanks a lot for the reply. For the table searches, what I did was create several tables pertaining to different categories, e.g., ra for republic acts, pd for presidential decrees, etc.

What I want to happen is if somebody conducts a search by typing a keyword, for example, if somebody types in the word "constitution", the search would go through all the different tables looking for the keyword, and the output would be like:

Linked Title
Description (which could be based on the first 50 text of the page)

That's it... at least for the first few parts of my problem.

Thanks a lot for the patience and help.

justageek

2:52 am on Sep 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We're all here to help each other :-)

If I understand correctly then you could pull the reults back easy enough.

Do something like:

$query = "select whatever from wherever1 where something = 'something' limit 2";
$rs = @mysql_query($query);
if(mysql_num_rows($rs)>0){
while($resultset = mysql_fetch_array($rs)){
do something here
}
}
$query = "select whatever from wherever2 where something = 'something' limit 2";
$rs = @mysql_query($query);
if(mysql_num_rows($rs)>0){
while($resultset = mysql_fetch_array($rs)){
do something here
}
}

...and so on until you have gone through all your tables. I just put a limit of 2 as an example. Does that help?

Francis

5:54 am on Sep 3, 2003 (gmt 0)

10+ Year Member



Hey, at the onset, the logic seems to be very ok and would be very useful. I'll try it out and see.

Thanks again.

Francis

1:18 am on Sep 14, 2003 (gmt 0)

10+ Year Member



Follow-up question....

How can I do a site search with an output similar to Yahoo!? I want to display the Title of the page, some texts from the meta description, the percentage and of course, the link?

Any sample scripts?

Thanks again.

Francis

2:44 am on Sep 14, 2003 (gmt 0)

10+ Year Member



Another question:

Here is the situation: I want to create an <A HREF> but the link is inside the database. For example, I have a link text XYZ with visible link library.php?db=acts&tid=a3815 (when you point to it on the browser). However, the actual link, referenced by a3815 is stored inside the database.

How can I "call" the link from inside the database? So that when I click on XYZ on the browser, it would go into the database, check for the reference and then go to the link without opening another browser?

I hope this is clear. Thanks again for the help....