Forum Moderators: coopster

Message Too Old, No Replies

PHP and MySQL Score Queries

         

username

2:22 am on Oct 24, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi all, I am getting some strange results (or lack of) when I run a full text search on my database. When I only query the title and article fields, the results and fine, but if I add any further fields such as keywords, and description, the script returns zero results. Does anyone know why?

$selectCondition = "title, article"; //working
$selectCondition = "title, article, description, keywords"; //no results
$searchString = "user entered query";

$query = "SELECT *, MATCH($selectCondition) AGAINST ('$searchString') AS score FROM tbl_data WHERE MATCH($selectCondition) AGAINST('$searchString') limit 300";

Thanks in advance.

username

2:26 am on Oct 24, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



...also I should mention when I include only title I get zero results. When it is only article as the $selectCondition, I get very limited results, however some results. Any ideas?

eelixduppy

2:28 am on Oct 24, 2008 (gmt 0)



Have you tried running this query from the command line directly?

username

2:45 am on Oct 24, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



No I haven't. This query needs to run from the browser, so have only been testing in a browser. What would I be able to determine from a command line that I cannot in the browser? Thanks.

eelixduppy

3:08 am on Oct 24, 2008 (gmt 0)



That there are no scripting errors.

username

3:34 am on Oct 24, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



I actually have not ever done this before. How do I go about this, or is there another query which would do the job better?

homeless

5:18 am on Oct 24, 2008 (gmt 0)

10+ Year Member



Are description and keywords defined as fulltext?

Is your $searchString too vague or your table too small to handle a vague search? adding description and/or keywords may force mysql to try to receive more than half the records in your table. If this is the case, mysql will retrieve 0 records by default.

have you tried the query against description or keywords alone?

add print mysql_error(); after your mysql_query() to see if there is an error in your script.

username

5:42 am on Oct 24, 2008 (gmt 0)

10+ Year Member Top Contributors Of The Month



So now, I have it just about sorted. It turned out that the keywords, and description fields were not defined as FULLTEXT. Now that I have defined them as FULLTEXT the results generate...HOWEVER, when I do the search, although the result count is correct, only half the results print, with the processor stopping before rendering the rest of the page. I thought maybe this was an invalid character, so removed the result from the database, and the search now works. Strangely enough there was no non alphanumeric characters in the result, so I do not know why this was happening? Any ideas?