LIKE
is usually a simple mechanism to be used in expressions comparing with miscellaneous texts in the database, so it reads the required data in the expression and applies LIKE
which is a simplified form of regular expression .
FTS is a proprietary mechanism of reverse indexing of bank data. Technically the entire database can be the target of this indexing. The keys in this case turn out to be words and they point to all places (which were considered in the index) where these words appear. In the most sophisticated can be control of relevance, proximity, partial word, context, etc.
FTS is often faster and more accurate in most cases, but it is more powerful but has a space consuming to maintain index structures. LIKE
can be as fast or faster than FTS in some cases. There are cases where LIKE
may not be as fast, but it is fast enough.
Each database usually has a very different FTS than the other while LIKE
is more or less standard.
LIKE
in SQLite:
SELECT FROM tabela WHERE coluna LIKE 'teste%' //costuma ser eficiente com índice apropriado
SELECT FROM tabela WHERE coluna LIKE '%teste%' //qualquer coisa que tenha 'teste' no meio
SELECT FROM tabela WHERE coluna LIKE '%teste' //termina com teste
SELECT FROM tabela WHERE coluna LIKE 'teste_' //termina com um e apenas um caractere qq
SELECT FROM tabela WHERE coluna LIKE '_teste_' //teste no meio de 1 caractere na ponta
FTS in SQLIte:
CREATE VIRTUAL TABLE tabela USING fts3 (col1, col2, text );
INSERT INTO tabela VALUES ('3', 'testo', 'Este é um exemplo');
INSERT INTO tabela VALUES ('24', 'exemplo', 'Ok, está bom assim');
INSERT INTO tabela VALUES ('13', 'outro', 'Finalizando');
SELECT * FROM tabela WHERE tabela MATCH "exemplo"