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
Hello Diogo,
is there any way to use fulltext search, especially MATCH ... AGAINST in mysql ? I think it should be solved by adding fulltext search operator in condition and sort definitions, or by adding query customization support or by stored procedure encapsulation support.
I think more often is use in WHERE and ORDER BY. There should be model attributes in select list.
SELECT`attr1`, `attr2`, `attr3`FROM`table`WHERE
MATCH(`attr1`, `attr2`) AGAINST ('expression')
ORDER BY
MATCH(`attr1`, `attr2`) AGAINST ('expression') DESC
Hmm MATCH AGAINST is non standard SQL which only works with MySQL.
Would it not be wiser to keep ORM database server agnostic and just have Model.find_by_sql('SELECT ... MATCH ... AGAINST') for custom queries?
Or even partial sql queries: Model.find({ ... }).where_sql('MATCH ... AGAINST ...').run(...)
Yes, it's probably better to have a common syntax. For drivers that do not support it at all I think we could just throw a message. Maybe we could make some kind of global setting similar to use strict (default true). If you want to have access to specific functions of some drivers (even with a common syntax) you had to disable strict mode.
This way people using the library to have a cross database support are ok and people just wanting an abstraction layer to a specific database can disable strict mode and use more functionalities.
I suggest this because I struggle to see how the mysql & postgres drivers could have a common full text search syntax. I reviewed the doco for each; The features & functionality are vastly different:
Mysql:
SELECT*FROM articles
WHERE MATCH (title,body)
AGAINST ('oranges'IN NATURAL LANGUAGE MODE);
Postgres:
SELECT id, ts_headline(body, q), rank
FROM (SELECT id, body, q, ts_rank_cd(ti, q) AS rank
FROM apod, to_tsquery('stars') q
WHERE ti @@ q
ORDER BY rank DESCLIMIT10) AS foo;
Plugins would probably require a lot more work though..
Yes, I like the plugins idea (I'm a fan of plugins!). I'm going to make a small .use() on db (it's probably better to use the plugin after connection so the plugin can check if it's compatible) and I'm going to make an initial mysql fts plugin. @dxg you could then try and do the same for postgres :)
Activity
dresende commentedon Apr 17, 2013
I would like to have this added but I'm not sure if this is used more often in conditions or directly as a select column.
This is what you want right? Or you have a use case to use it in
WHERE?czkody commentedon Apr 17, 2013
I think more often is use in
WHEREandORDER BY. There should be model attributes in select list.dresende commentedon Apr 17, 2013
Something like this?
dxg commentedon Apr 18, 2013
Hmm
MATCH AGAINSTis non standard SQL which only works with MySQL.Would it not be wiser to keep ORM database server agnostic and just have
Model.find_by_sql('SELECT ... MATCH ... AGAINST')for custom queries?Or even partial sql queries:
Model.find({ ... }).where_sql('MATCH ... AGAINST ...').run(...)dresende commentedon Apr 18, 2013
I think pg also supports it. I still have to think about it because sqlite probably doesn't. If it doesn't we can follow your suggestion of
where_sql.dxg commentedon Apr 18, 2013
Postgres supports full text search, but the syntax is completely different.
MATCH and AGAINST are not reserved words. Frustrating..
czkody commentedon Apr 18, 2013
I think the syntax should be solved at the driver level and ORM should only have information about full-text search support of the driver.
dresende commentedon Apr 18, 2013
Yes, it's probably better to have a common syntax. For drivers that do not support it at all I think we could just throw a message. Maybe we could make some kind of global setting similar to
use strict(default true). If you want to have access to specific functions of some drivers (even with a common syntax) you had to disable strict mode.This way people using the library to have a cross database support are ok and people just wanting an abstraction layer to a specific database can disable strict mode and use more functionalities.
dxg commentedon Apr 18, 2013
Another option is having plugins/modules for ORM. Eg:
I suggest this because I struggle to see how the mysql & postgres drivers could have a common full text search syntax. I reviewed the doco for each; The features & functionality are vastly different:
Mysql:
Postgres:
Plugins would probably require a lot more work though..
dresende commentedon Apr 18, 2013
Yes, I like the plugins idea (I'm a fan of plugins!). I'm going to make a small
.use()ondb(it's probably better to use the plugin after connection so the plugin can check if it's compatible) and I'm going to make an initial mysql fts plugin. @dxg you could then try and do the same for postgres :)dxg commentedon Apr 18, 2013
Sounds good!
Adds initial plugin architecture - .use() (#121)
dresende commentedon Apr 21, 2013
I'm still working on this but I hope I'll have some good news this week :)
dresende commentedon Apr 24, 2013
Take a look at this plugin https://github.com/dresende/node-orm-mysql-fts and give me some feedback :)
dxg commentedon Apr 25, 2013
Looks great! I like how simple the code is.
dresende commentedon Apr 25, 2013
Ok, so bugs and features about fts can now go there :)