Skip to content

add support for SQLite Full Text Search#623

Closed
Kenneth-KT wants to merge 8 commits into
Nozbe:masterfrom
Kenneth-KT:fts
Closed

add support for SQLite Full Text Search#623
Kenneth-KT wants to merge 8 commits into
Nozbe:masterfrom
Kenneth-KT:fts

Conversation

@Kenneth-KT

Copy link
Copy Markdown
Contributor

[SQLiteAdapter] Added support for Full Text Search for SQLite adapter:
Add isSearchable boolean flag to schema column descriptor for creating Full Text Search-able columns
Add Q.textMatches(value) that compiles to match 'value' SQL for performing Full Text Search using SQLite adpater

Kenneth-KT referenced this pull request in stigi/WatermelonDB Feb 15, 2020
Coding while the kid sleeps
@Kenneth-KT Kenneth-KT mentioned this pull request Feb 15, 2020

@radex radex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good! Thank you so much @Kenneth-KT for working on this. I think we're very close to merge, I just want to cross the t's and dot the i's to make sure that 🍉 users don't accidentally use this feature in ways that it doesn't support yet

Comment thread src/QueryDescription/test.js Outdated

it('supports textMatches as fts join', () => {
const query = Q.buildQueryDescription([
Q.textMatches('searchable', 'hello world'),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test doesn't seem right - did you mean Q.where('searchable', Q.textMatches('hello world'))?

BTW. This test shouldn't pass. Q.buildQueryDescription in DEV should probably check that args passed there are valid where/and/or -- but i guess that's out of scope for this PR

Comment thread src/adapters/sqlite/encodeSchema/index.js Outdated
if (column.isSearchable) {
logger.warn(
'[DB][Worker] Support for migrations and isSearchable is still to be implemented',
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's no support for schema migrations for FTS, that's fine, I can merge that - but throw an error if someone tries to do that - not just on add columns, but for create table migration as well

Comment thread CHANGELOG.md
Note that this only works when `useWebWorker: false`
- [SQLiteAdapter] Added support for Full Text Search for SQLite adapter:
Add `isSearchable` boolean flag to schema column descriptor for creating Full Text Search-able columns
Add `Q.textMatches(value)` that compiles to `match 'value'` SQL for performing Full Text Search using SQLite adpater

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add to docs-master/ .... queries document a few words about Full Text Search?

return value.replace(nonLikeSafeRegexp, '_')
}

export function textMatches(value: string): Comparison {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more place that takes Queries is encodeMatcher (used by query observation system). I think it would be appropriate to throw an error if you try to encode a matcher for a query that contains the unsupported textMatches operator. (Even better would be to support it, or to make .observe() de-opt to reloadingObserver, but that's out of scope for this PR)

@radex

radex commented Mar 11, 2020

Copy link
Copy Markdown
Collaborator

hey @Kenneth-KT -- will you have time in the coming weeks to look at my comments and finish your two awesome PRs? I'd love to see them merged

@radex

radex commented Jun 18, 2020

Copy link
Copy Markdown
Collaborator

@Kenneth-KT I'm interested in getting this PR to the finish line. Do you have time to work on this? If not, perhaps I will.

Another question: Are you currently shipping an app that uses this patch, or is it only in development? I want to change names of the virtual FTS tables, but if you're already shipping, maybe I don't care so much and will avoid causing trouble for you and your users

@radex

radex commented Jul 17, 2020

Copy link
Copy Markdown
Collaborator

@Kenneth-KT Hey, pinging you again. Can you please take a look at the comment above?

@sidferreira

sidferreira commented Apr 2, 2021

Copy link
Copy Markdown
Contributor

@radex is this PR stale? I might have some time to finish it

I tried to rebase and making it work, but I noticed this solution will bloat my database too much and it seems to have other ways to do the same. I may help if I better understand the expected result and why something like following isn't enough:

[
  Q.where('name', Q.like('%elon%musk%')),
  Q.or(Q.where('full_name', Q.like('%elon%musk%')),
]

@radex

radex commented Apr 3, 2021

Copy link
Copy Markdown
Collaborator

@sidferreira Yes, stale. Would very much like to see it finished up, but didn't have the need myself, and the OP disappeared. So please do!

Read up on SQLite Full Text Search. If for your application, using Q.like is enough -- great! Use it. FTS adds overhead, db size, etc... The reward is there for large databases, and also FTS finds different results from Q.like

@radex

radex commented Apr 7, 2021

Copy link
Copy Markdown
Collaborator

Closing in favor of #984. Thank you @Kenneth-KT, @stigi & @sidferreira !

@radex radex closed this Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants