Toon posts:

[MySQL] MATCH() AGAINST() probleem!

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hallo, de search heb ik er al op nagezocht en ik heb mijn antwoord niet gevonden. Ik heb een vraag, die misschien voor niet-leken wel heel erg simpel is maar ik kom er niet uit.

Ik heb een INDEX voor mijn tabel gemaakt:
code:
1
2
3
4
ALTER TABLE `live` ADD FULLTEXT (
`bnaam` ,
`adres` 
);

Er zit nu nog maar 1 veld in, maar er komen er veel meer in te staan en die wil ik doorzoeken. Ik wil een Yahoo-stijl zoekfunctie, dus voldoet "WHERE [..] LIKE" niet.

Als "adres" OF "bnaam" (of allebei) de tekst "bla" waar dan ook bevat (dus ook "bblah"), dan moet hij een resultaat geven. Dus ik dacht, ik gebruik MATCH() AGAINST() wel even:

code:
1
2
3
SELECT bnaam, adres FROM live WHERE
MATCH(bnaam, adres)
AGAINST('bla');


En wat krijg ik terug?
Empty set (0.00 sec)

Terwijl het er WEL instaat, maar ik snap niet waarom hij 'm dan niet selecteert? Als ik in boolean mode zoek doet ie het ook niet. Terwijl het er echt in staat:

code:
1
2
3
4
5
6
7
SELECT bnaam, adres FROM live;

+----------+-------------+
| bnaam    | adres       |
+----------+-------------+
| bblah    | Straatnaam7 |
+----------+-------------+


Ik dacht dat ik misschien de INDEX verkeerd had aangemaakt, maar "IN BOOLEAN MODE" doet het ook niet, en die heeft niet eens een index nodig.

Wie helpt mij? :?

  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 22:35

Creepy

Tactical Espionage Splatterer

Dat je een leek bent is niet erg. Maar iets meer moeite doen voordat je een topic opent mag wel hoor ;)


Onderstaande komt van http://www.databasejourna...mysql/article.php/1578331. De tweede link die google me geeft als ik zoek op "mysql fulltext index"
Let's have a look at some of the consequences of this. If you were a bit lazy in your typing, and tried 'to look for the word 'love', as follows:

mysql> SELECT * FROM fulltext_sample WHERE MATCH(copy) AGAINST('lov');
Empty set (0.00 sec)

you'd get nothing back, as the FULLTEXT index only contains complete words, not partial words. You'd have to write the full word to get anything back, as you did in the first example.

As mentioned, hyphenated words are also excluded from the FULLTEXT index (they are indexed as separate words), so the following also returns nothing:

mysql> SELECT * FROM fulltext_sample WHERE MATCH(copy) AGAINST('all-out');
Empty set (0.00 sec)

Unfortunately, both words are less than the required 4 letters, so they don't appear on their own either, and cannot be found at all with an ordinary search. Part 2 of this tutorial looks at BOOLEAN MODE searches when you can search for partial or hyphenated words.

You can also search for more than one word at a time, by separating the words with commas. Try and return records containing the words 'here' and 'appears', as follows:

mysql> SELECT * FROM fulltext_sample WHERE MATCH(copy) AGAINST('here');
Empty set (0.01 sec)

Unexpectedly this returns nothing. But, a more careful look at the stopword list shows this word is listed, so they are excluded from the index. Stopwords are a common cause of people complaining that the MySQL FULLTEXT index facility is not working properly. If your query does return a result, then the stopword list in your version of MySQL does not contain the word 'here'.
De eerste link die google me geeft is de MySQL manual en die zegt o.a.
Some words are ignored in full-text searches:

*

Any word that is too short is ignored. The default minimum length of words that are found by full-text searches is four characters.
*

Words in the stopword list are ignored. A stopword is a word such as “the” or “some” that is so common that it is considered to have zero semantic value. There is a built-in stopword list, but it can be overwritten by a user-defined list. See Section 12.7.5, “Fine-Tuning MySQL Full-Text Search”.
Lees voor de volgende keer P&W FAQ - De "quickstart" eens goed door zodat je weet wat we van je verwachten voordat je een topic opent hier ;)

[ Voor 53% gewijzigd door Creepy op 16-12-2005 20:57 ]

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


Verwijderd

Topicstarter
Ik weet wat er van me verwacht wordt voor ik een topic open, maar die informatie die jij me gaf helpt me ook niet. Ik zou hier ook niet posten als ik niet eerst uren heb lopen kloten eraan.

Maar het werkt dus ook niet met complete woorden. De woorden hoeven voor BOOLEAN mode trouwens niet compleet te zijn staat in het stukje wat je hebt geplakt, dus dan zou je moeten weten dat dat ook niet werkt?

[ Voor 25% gewijzigd door Verwijderd op 16-12-2005 20:57 ]


  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 22:35

Creepy

Tactical Espionage Splatterer

Je zoekt op 'bla'. Dat is 3 letters lang. Een fulltext index kan alleen wat vinden als je minimaal 4 karakers gebruikt.

Zoek je wel op woorden langer dan 4 letters? Dat heb je nergens gemeld. Ook zie ik nergens terug dat je zelf actief bezig bent geweest met het zoeken naar een oplossing. Dus welke zaken heb je geprobeerd? Wat lukte daar niet mee? Zie nogmaals de quickstart waarin we om dat soort informatie vragen ;)

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


Verwijderd

Topicstarter
bla was maar een voorbeeld.

Als er bijvoorbeeld 'Tweakers' in staat, en ik zoek op tweak, dan wil ik ook dat de row met Tweakers erin wordt weergegeven. of "tweak" nu voorkomt in de titel ('tweakers') of in de straat ('tweakstraat'), waarbij in het laatste geval de titel weer heel anders is.

Als ik het complete woord overtik dan vindt ie hem inderdaad wel ja, maar dat is toch geen functionaliteit?

[ Voor 23% gewijzigd door Verwijderd op 16-12-2005 21:07 ]


  • ripexx
  • Registratie: Juli 2002
  • Laatst online: 21:56

ripexx

bibs

Verwijderd schreef op vrijdag 16 december 2005 @ 21:06:
bla was maar een voorbeeld.

Als er bijvoorbeeld 'Tweakers' in staat, en ik zoek op tweak, dan wil ik ook dat de row met Tweakers erin wordt weergegeven. of "tweak" nu voorkomt in de titel ('tweakers') of in de straat ('tweakstraat'), waarbij in het laatste geval de titel weer heel anders is.

Als ik het complete woord overtik dan vindt ie hem inderdaad wel ja, maar dat is toch geen functionaliteit?
Fulltext search splitst geen worden op in sub onderdelen en doet ook geen like achtige searches. Full text search is handig als je in grote stukken tekst wil zoeken naar een woord. Dus bijvoorbeeld door de nieuwspost of forum topics wil zoeken.

Er zijn wel mogelijkheden om een beter search te maken (Xapian bijvoorbeeld), door stemming toe te passen, woorden logisch te splitsen en daar op te zoeken etc etc. Maar de standaard fulltext search van MySQL doet dat nu eenmaal niet.

buit is binnen sukkel

Pagina: 1