Page 1 of 1

Using PHP to order search results by most relevant

Posted: Fri Oct 13, 2006 11:57 am
by webcitz
Hello,

I'm using a program called Open Realty (http://www.open-realty.com) and I've got a general PHP question about how to sort search results.

On the search page, there is an item called "features." People are given a checkbox to click on the features that interest them, there are a total of ten possible features. If someone clicks on features #1 and #2 and hits the search button, they will see all results that include features #1 and #2. However, some search results show items with features #2 and #3 ....or..... features #1 and #6.

Is there anything you can do to the sort command to have it first display items with exact matches to what is searched for, and then proceed to show other similar search results?

Here is a picture example: http://www.webcitz.com/example1.gif In the picture example, assume someone searched for Open, Sloping and Some Trees. In this same example, assume it would be desirable for me to have exact matches of Open, Sloping, and Some Trees to display first. Therefore, results #2 and #3 would be seen first.

I am prepared to offer money in exchange for assistance. If you need to see parts/all of the code just let me know.[/img]

Posted: Fri Oct 13, 2006 1:05 pm
by John Cartwright
This will involve your database and not php. Moved to databases.

I believe fulltext searching is what you are after.

Posted: Fri Oct 13, 2006 2:13 pm
by webcitz
Thank you for the help thus far. I've read the page you sent to me twice and it seems to make perfect sense. I've also tried looking for a table in phpmyadmin to see where I can modify the code to include fulltext searching. Would phpmyadmin eventually get me there if I just keep looking at the files?

Posted: Fri Oct 13, 2006 9:54 pm
by webcitz
Hey again,

I've played around with the tables for a while but i cant figure out what to use in the WHERE and AGAINST clauses. It keeps referring to columns and rows in the documentation in the link you provided me. If I post a few snapshots of my phpmyadmin, would you be able to help me some more?

Thanks,
David

Posted: Sat Oct 14, 2006 2:39 am
by pgolovko

Posted: Wed Oct 25, 2006 11:52 pm
by webcitz
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey Guys,

Thanks for the help.  So far I've been able to figure out this modification can be done through a file called "search.inc.php" from within the /includes folder.  Before today I've been looking in phpmyadmin for something to put a MATCH () to.  

However, I'm stumped regarding the location of modification I need to make.  I think I have narrowed it down to a single function that puts out search results.  Attached to this post is a small exerpt of coding from that function.

To help you understand what is going on.... 

Concerning the following line: $searchresultSQL .= " OR $safe_k.listingsdbelements_field_value LIKE '%$vitem%'";   
If you use AND, the program will return all search results that exactly match the user's checkboxes of what to search for.  If you use OR, like I am using now, the program will show search results of any item that has at least one searched value as true.  

The item "listingsdbelements_field_value"  holds information that I want to use in the MATCH statment.

Whoever reads this, thank you very much for your help.  I'm trying to solve this problem myself and not stupidly expect others to solve it for me.  However, I'm not a programmer and I can only go so far with speculation.  Please help, thank you very much!

If you want to see the program running, go to http://lotsandlandstore.com/lots/index. ... searchpage

Code: Select all

}else {
					// Make Sure Array is not empty
					$use = false;
					$comma_separated = implode(" ", $v);
					if (trim($comma_separated) != '') {
						$use = true;
						if ($searchresultSQL != '') {
							$searchresultSQL .= ' AND ';
						}
					}
					if ($use === true) {
						$safe_k = addslashes($k);
						$searchresultSQL .= "($safe_k.listingsdbelements_field_name = '$safe_k' AND (";
						$vitem_count = 0;
						foreach ($v as $vitem) {
							if ($vitem != '') {
								if ($vitem_count != 0) {
									$searchresultSQL .= " OR $safe_k.listingsdbelements_field_value LIKE '%$vitem%'";
								}else {
									$searchresultSQL .= " $safe_k.listingsdbelements_field_value LIKE '%$vitem%'";
								}
								$vitem_count++;
							}
						}
						$searchresultSQL .= "))";
						$tablelist[] = $safe_k;
					}
				}
			}
		}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Nov 04, 2006 7:31 pm
by webcitz
Does anyone have any ideas?