LIKE
is usually a simple mechanism to be used in expressions comparing to various texts in the database, so it reads the required data in the expression and applies the LIKE
which is a simplified form of regular expression.
The FTS is a inverted indexing of database data. Technically the entire database can be the target of this indexing. The keys in this case become words and they point to all places (which were considered in the index) where these words appear. In the more sophisticated can be control of relevance, proximity, partial word, context, etc.
The FTS is usually faster and more accurate in most cases, as well as being more powerful, but has a space consumption to maintain index structures. The LIKE
may be as or faster than FTS in some cases. There are cases where the LIKE
may not be that fast, but it’s fast enough.
Each database usually has a very different FTS than the other while the LIKE
is more or less standard.
LIKE
in the 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 on the 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"
I put in the Github for future reference.