Full-text searching (zoeken in mysql)
Probleem
moet gezocht worden in meerdere velden tegelijkertijd in grootte database bestanden.
Oplossing
gebruik Full-text searching van MySQL.
Om index toe te voegen
ALTER TABLE some_tbl ADD FULLTEXT (body)
ALTER TABLE some_tbl ADD FULLTEXT (title,body)
(voor iedere index die gezocht moet worden maak een aparte fulltext sleutel)
Als een “GROUP BY domein ORDER BY ci DESC ” wordt gebruikt dan worden prestaties verlaagd van de server. ook hetzelfde met join.
Om te zoeken
SELECT * FROM some_tbl WHERE MATCH (title,body)
AGAINST (’search engine’)
SELECT * FROM articles WHERE MATCH (title,body)
AGAINST (’+MySQL -YourSQL’ IN BOOLEAN MODE);
+
A leading plus sign indicates that this word must be present in every row returned.
-
A leading minus sign indicates that this word must not be present in any row returned.
By default (when neither plus nor minus is specified) the word is optional, but the rows that contain it will be rated higher. This mimicks the behavior of MATCH() … AGAINST() without the IN BOOLEAN MODE modifier.
> <
These two operators are used to change a word's contribution to the relevance value that is assigned to a row. The > operator increases the contribution and the < operator decreases it. See the example below.
( )
Parentheses are used to group words into subexpressions. Parenthesized groups can be nested.
~
A leading tilde acts as a negation operator, causing the word's contribution to the row relevance to be negative. It's useful for marking noise words. A row that contains such a word will be rated lower than others, but will not be excluded altogether, as it would be with the - operator.
*
An asterisk is the truncation operator. Unlike the other operators, it should be appended to the word, not prepended.
"
A phrase that is enclosed within double quote (`"') characters matches only rows that contain the phrase literally, as it was typed.
The following examples demonstrate some search strings that use boolean full-text operators:
'apple banana'
Find rows that contain at least one of the two words.
'+apple +juice'
Find rows that contain both words.
'+apple macintosh'
Find rows that contain the word ``apple'', but rank rows higher if they also contain ``macintosh''.
'+apple -macintosh'
Find rows that contain the word ``apple'' but not ``macintosh''.
'+apple +(>turnover
'apple*'
Find rows that contain words such as ``apple'', ``apples'', ``applesauce'', or ``applet''.
'"some words"'
Find rows that contain the exact phrase ``some words'' (for example, rows that contain ``some words of wisdom'' but not ``some noise words''). Note that the `"' characters that surround the phrase are included within the search string. They are not the quotes that surround the search string itself.
Voordelen
-kan gezocht worden in boolmode.
-geen extra code nodig
Nadelen
-vertraagd INSERT, UPDATE
-verdubbeld bestand grootte (met iedere index)
Add A Comment
You must be logged in to post a comment.
