Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

SQL related question #100

Open
yarolegovich opened this issue May 31, 2018 · 7 comments
Open

SQL related question #100

yarolegovich opened this issue May 31, 2018 · 7 comments

Comments

@yarolegovich
Copy link

As far as I understand fts4 gives no benefit when LIKE is used.

CREATE VIRTUAL TABLE item_index USING fts4(content TEXT);
...
SELECT item.*
FROM item_index
JOIN item ON (docid = item.id)
WHERE content LIKE '%' || ?1 || '%' ESCAPE '\'

FTS tables can be queried efficiently using SELECT statements of two different forms:
Query by rowid. If the WHERE clause of the SELECT statement contains a sub-clause of the form "rowid = ?", where ? is an SQL expression, FTS is able to retrieve the requested row directly using the equivalent of an SQLite INTEGER PRIMARY KEY index.
Full-text query. If the WHERE clause of the SELECT statement contains a sub-clause of the form " MATCH ?", FTS is able to use the built-in full-text index to restrict the search to those documents that match the full-text query string specified as the right-hand operand of the MATCH clause.
If neither of these two query strategies can be used, all queries on FTS tables are implemented using a linear scan of the entire table. If the table contains large amounts of data, this may be an impractical approach (the first example on this page shows that a linear scan of 1.5 GB of data takes around 30 seconds using a modern PC).

@AlecKazakova
Copy link
Contributor

oh yea you're totally right. It should be WHERE content MATCH ?1

@JakeWharton
Copy link
Owner

Can I interest either of you in the fame and glory that come with sending a pull request for this change?

@yarolegovich
Copy link
Author

It should be WHERE content MATCH ?1

This will search for complete words. When inserted, text is tokenized and MATCH can perform token or token prefix matching.

screen shot 2018-06-01 at 9 33 29 am

I think it's better to just remove fts and continue using LIKE %query%.

Can I interest either of you in the fame and glory that come with sending a pull request for this change?

Tempting, indeed.

@AlecKazakova
Copy link
Contributor

Thats true. We can prefix match but not match in the middle of a word. So typing Layout wouldn't match ConstraintLayout

We could be clever and tokenize based off of camel casing to still use an fts table for those cases. I guess the question is do we care about matching things like straint to ConstraintLayout? @JakeWharton

@JakeWharton
Copy link
Owner

No. But Layout should. I'd also like to make ConLa work eventually.

@AlecKazakova
Copy link
Contributor

if we tokenize the input string on camel case then the query becomes MATCH 'con AND la' which would work.

I dont think we can build actual sqlite tokenizers through the exposed android sqlite stuff, but we can tokenize from the kotlin side and this should all theoretically work.

ConstraintLayout goes into fts as constraint layout

ConLa goes into search as con la

@JakeWharton
Copy link
Owner

JakeWharton commented Jun 1, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants