Re: search string / query format
| From: | John Taylor-Johnston | Date: | Sat, 10 Jul 2004 02:34:26 +0000 |
| Subject: | Re: search string / query format | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-190122@lists.php.net to get a copy of this message | ||
>>Keyword AND keyword2
>>"keyword keyword2" -keyword3
It doesn't support AND or OR but it does use - + * and others.
>Consult thine manual!! (The MySQL one) ;)
http://dev.mysql.com/doc/mysql/en/Fulltext_Search.html
The problem is getting a FULLTEXT to sort by relevancy. This was a real pain, until our friend John
W. showed me the error of my ways; (see below).
MySQL> "The preceding example is a basic illustration showing how to use the MATCH()
MySQL> function
MySQL> where rows are returned in order of decreasing relevance"
I never did believe the "examples" helped me: http://dev.mysql.com/doc/mysql/en/Fulltext_Search.html
You will need something like this to make the operators display according to relevancy. This works:
SELECT *,MATCH (field1,field2,field3) AGAINST ('Margaret Atwood' IN BOOLEAN MODE)
AS relevancy FROM
mytable WHERE MATCH (field1,field2,field3) AGAINST ('Margaret Atwood' IN BOOLEAN
MODE) ORDER BY
relevancy DESC;
This does not sort by relevancy well at all:
SELECT * (field1,field2,field3) FROM mytable AGAINST ('Margaret Atwood' IN BOOLEAN MODE);
P.S. John W.: thanks for helping me on my post last week. I finally got this working.
John
"John W. Holmes" wrote:
> Ed Lazor wrote:
> > I'm going to create a search page that accepts input similar to places like
> > Yahoo and Google.
> [snip]
> > Also, I've heard that MySQL's indexing can
> > support some of this, but I'm not sure how much.
>
> Using a FULLTEXT index and searching in BOOLEAN mode supports the type
> of search strings that you wrote.
>
> Consult thine manual!! (The MySQL one) ;)