Forums

PHP

This topic is locked

Fulltext searches in Boolean Mode

Posted 28 Apr 2006 19:23:40
1
has voted
28 Apr 2006 19:23:40 fiona gilmour posted:
Hi Everyone

At the moments I have a MySQL database that has a column called info and I have made this a FULLTEXT index.

I have a page with a form (called form choose)
and a text field (called searchID)

in my results page I have the following;
$searchnow=$_GET['searchID'] ;

and

$query_Recordset1 = "SELECT * FROM activity WHERE info LIKE '%$searchnow%'";

This works, however I would really like to use the boolean fulltext search that uses match and against, but can't seem to work this out!

Any help would be great x

Replies

Replied 28 Apr 2006 19:40:47
28 Apr 2006 19:40:47 Roddy Dairion replied:
The way u use it is very simple

<pre id=code><font face=courier size=2 id=code>
SELECT * FROM activity WHERE MATCH (colnames)
AGAINST ('+contains -contains' IN BOOLEAN MODE)
</font id=code></pre id=code>

Basically the +contains is the word that u want full text you want to be found and -contains is if the fulltext has the -contains it doesn't take it
for e.g. you have a text "I like PHP but not SQL" and another that says "I like PHP and everything else", then in your query you have it as
<pre id=code><font face=courier size=2 id=code>
SELECT * from activity where match (colnames) AGAINTS ('+PHP -SQL' IN BOOLEAN MODE)
</font id=code></pre id=code>
It will retrieve only the second text because it doesn't have the word SQL in it.


Edited by - roders22 on 28 Apr 2006 19:42:02
Replied 28 Apr 2006 19:48:20
28 Apr 2006 19:48:20 fiona gilmour replied:
I know this is going to sound silly but I don't know what people are going to search for in my site and therefore still don't know how to write this.

Or do I actually write the colnames bit?

Sorry I'm really new
Replied 28 Apr 2006 20:02:58
28 Apr 2006 20:02:58 Roddy Dairion replied:
Depends wat colnames u have in ur table, that you will use for search. For e.g. if u will use colnames products and description
the your query will be

<pre id=code><font face=courier size=2 id=code>
SELECT * FROM activity WHERE MATCH (products, description)
AGAINST ('+contains -contains' IN BOOLEAN MODE)
</font id=code></pre id=code>

If u hve only 1 text field i don't really c da use of using BOOLEAN MODE.
Why don't u use a simple query?
Replied 28 Apr 2006 20:18:34
28 Apr 2006 20:18:34 fiona gilmour replied:
I am now getting an error message. I am only searching in one column tho so maybe I am on the wrong tracks anyway.

I thought that I needed to use a boolean search as I want my search to work as follows:

text column named (info) contains 'text that says fiona went for a walk'.

Currently if I search walk i get the correct result, if I search fiona I get the correct result.
However if I search fiona and walk I do not get a result!

I really appreciate all your help.
Replied 29 Apr 2006 11:01:46
29 Apr 2006 11:01:46 Roddy Dairion replied:
Oh looking for 2 words is a different story as key is a different story. This u might want to use an array then a loop that will check each word typed in the textfield on your form against the word found in your table. The problem with this is that if you have a text like "Text Fiona is still walking" and in your text field you type
fiona walking you will hve 2 results. Both echoing the same text. U can bypass by specifying if a text is found den forget d other 1.
Replied 29 Apr 2006 11:12:38
29 Apr 2006 11:12:38 fiona gilmour replied:
really appreciate the help,
thanks
Replied 29 Apr 2006 11:33:45
29 Apr 2006 11:33:45 Roddy Dairion replied:
If u need help let me kno.

Reply to this topic