简体   繁体   中英

How do you do fulltext search add two field with Entity Framework Core?

If only one field is searched, it can be successful. But not two.

var results = db.tables
    .Where(x => EF.Functions.Match(x.Title, "search text",MySqlMatchSearchMode.Boolean));

I want to get sql syntax result.

select * from articles 
where match(`title`) against('葡萄牙') > 0;

Below is the result I want to achieve.

var results = db.tables
    .Where(x => EF.Functions.Match(x.Title+x.ArticleContent, "search text"));

I want to get sql syntax result.

select * from articles 
where match(`title`,`article_content`) against('葡萄牙') > 0;

Error: MySqlConnector.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '( s . title , COALESCE( s . article_content , ''))) AGAINST ('葡萄牙' IN BOOL...' at line 3

Because I found the answer, share the answer URL: <https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/blob/f4b1ab9497743db5a395a36340515b3d3fc28e3c/test/EFCore.MySql.FunctionalTests/Query/MatchQueryMySqlTest.cs >

var results = db.tables
    .Where(x => EF.Functions.Match(new [] {x.Title,x.ArticleContent}, "search text"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM