-
-
Notifications
You must be signed in to change notification settings - Fork 727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FTS usage issue "unable to use function MATCH in the requested context" #178
Comments
Hello @avaan, I may have to update the External Content Full-Text Tables documentation chapter so that other users aren't confused. Basically, the SQLite MATCH full-text operator only works with columns that belong to a full-text virtual table. You get the "unable to use function MATCH in the requested context" error because you match on the Since you intend to load all columns from SELECT dcontacts.*
FROM dcontacts
JOIN dcontacts_ft ON
dcontacts_ft.rowid = dcontacts.rowid AND
dcontacts_ft.display_name MATCH ? GRDB's Query Interface does not generate JOIN queries for you. This feature may come one day, but today you'll have to use raw SQL: let pattern = FTS3Pattern(matchingAllTokensIn: "h")
try! contactDbQueue.inDatabase { db in
let sql = "SELECT dcontacts.* " +
"FROM dcontacts " +
"JOIN dcontacts_ft ON " +
"dcontacts_ft.rowid = dcontacts.rowid AND " +
"dcontacts_ft.display_name MATCH ?"
contacts = DContacts.fetchAll(db, sql, arguments: [pattern])
} Tell me if this works. Oh, a final word: remember that SQLite full-text performs on tokens which basically are words: the |
Another advice. Your table creation has troubles: try db.create(virtualTable: "dcontacts_ft", using: FTS4()) { t in
t.synchronize(withTable: "dcontacts")
t.content = ""
t.compress = "zip"
t.uncompress = "unzip"
t.tokenizer = .porter
t.column("display_name")
} The
So don't set try db.create(virtualTable: "dcontacts_ft", using: FTS4()) { t in
t.synchronize(withTable: "dcontacts")
t.compress = "zip"
t.uncompress = "unzip"
t.tokenizer = .porter
t.column("display_name")
} As for the compress and uncompress options, the SQLite documentation says:
I'm not sure that you have registered a try db.create(virtualTable: "dcontacts_ft", using: FTS4()) { t in
t.synchronize(withTable: "dcontacts")
t.tokenizer = .porter
t.column("display_name")
} If your database is too big, you'll maybe have to consider compression. But I advise you to start with a simple setup first. |
Thanks for your valuable inputs. I will try this and will let you know the output. Meanwhile one more question, do I need to create "dcontacts_ft" every time my app launches? |
Its working like a charm. Thanks for your valuable suggestions.. |
No, a full text table is just like other tables: once created, and populated, it remains. Normally, an application sets up its database only once. GRDB recommends using migrations for that, because migrations can also handle schema changes as your application evolves. See DemoApps/GRDBDemoiOS/Database.swift for a sample code.
Great! Happy GRDB! |
@groue Are you trying to point that FTS tables are migratable/alterable. |
@dineshflock. More or less, but don't draw too many conclusions from my sentences. A conversation in an issue is not reference documentation. The definitive reference is SQLite itself. For example, as all SQLite virtual tables, full text tables can not be altered, and there's nothing GRDB can do about it. If you have a more precise question, please ask. But remember that GRDB is just a thin layer over SQLite: most questions about GRDB are actually questions about SQLite, and StackOverflow is likely to be a better place for asking. |
@groue I got it. Thanks. |
I have created a table along with FTS table as below,
As per above anything inserted into table "dcontacts" will be synced to "dcontacts_ft" table.
when I try to execute below code
I am getting below error "SQLite error 1 with statement
SELECT * FROM "DContacts" WHERE ("display_name" MATCH ?)
arguments ["h"]: unable to use function MATCH in the requested context"I don't know what I am doing wrong here. Please help me out.
The text was updated successfully, but these errors were encountered: