You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently knex has an open issue since 2014 to (generically) support full-text searches. In the interim, we can do as other have and use whereRaw and syntax based on the database type.
MySQL
I currently have been using MySQL (Google Cloud SQL) and plan to implement this first as it's pretty straight forward. Add a fulltext to the column(s) designed and then use match(column_name) against ('seach terms')
altertable`comment` add fulltext(`content`);
select*from comment where match(`content`) against ('some word')
-- or multiple columnsaltertable`comment` add fulltext(`title`, `content`);
select*from comment where match(`title`, `content`) against ('some word')
While I haven't looked into it much yet, Postgres appears a little more complicated and need to better understand tsvector. The following articles look like a good start.
Until it's decided how best to handle this, as of version 0.11.10, you can register a custom query operator and provide your own implementation (or override an existing one). For example, here's what I (roughly) use for MySQL
varadapter=newDSSqlAdapter({
...
queryOperators: {'search': (query,field,value)=>{returnquery.whereRaw(`MATCH(${field}) AGAINST(? IN BOOLEAN MODE)`,value)},'|search': (query,field,value)=>{returnquery.orWhereRaw(`MATCH(${field}) AGAINST(? IN BOOLEAN MODE)`,value)}}}
I'm proposing to add the
search
query operator to support full-text searchyou could also specify multiple columns using a comma separated field (similar to how near queries do for lat/long columns)
Currently knex has an open issue since 2014 to (generically) support full-text searches. In the interim, we can do as other have and use
whereRaw
and syntax based on the database type.MySQL
I currently have been using MySQL (Google Cloud SQL) and plan to implement this first as it's pretty straight forward. Add a
fulltext
to the column(s) designed and then usematch(column_name) against ('seach terms')
Need to determine is we should always use boolean full-text searches
Postgres
While I haven't looked into it much yet, Postgres appears a little more complicated and need to better understand
tsvector
. The following articles look like a good start.The text was updated successfully, but these errors were encountered: