.net core Postgresql&;中的全文搜索存在问题。净核心2.1

.net core Postgresql&;中的全文搜索存在问题。净核心2.1,.net-core,full-text-search,npgsql,.net Core,Full Text Search,Npgsql,我发布这个问题是因为我还没有发现类似的问题。我正在尝试确保在.net core应用程序中进行全文搜索,根据我的文档: 1) 模型 2) 数据库上下文: modelBuilder.Entity<User>() .HasIndex(p => p.SearchVector) .ForNpgsqlHasMethod("GIN"); 现在,我尝试在我的应用程序中使用FTS,方法搜索从标题“阶段”(字符串)获取 但我得到:postgresception:4

我发布这个问题是因为我还没有发现类似的问题。我正在尝试确保在.net core应用程序中进行全文搜索,根据我的文档: 1) 模型

2) 数据库上下文:

  modelBuilder.Entity<User>()
       .HasIndex(p => p.SearchVector)
       .ForNpgsqlHasMethod("GIN");
现在,我尝试在我的应用程序中使用FTS,方法搜索从标题“阶段”(字符串)获取

但我得到:postgresception:42883:运算符不存在:tsvector@@text

有人知道我做错了什么吗

编辑----:

好的,我找到了我问题的答案。从字符串转换为NpgsqlTsQuery必须在Matches方法内:

 public async Task<IActionResult> SearchUsers([FromHeader] string phase)
    {
        return Ok(_context.Users.Where(c => c.SearchVector.Matches(EF.Functions.ToTsQuery(phase))));
    }
public async Task<IActionResult> SearchUsers([FromHeader] string phase)
{
    return Ok(_context.Users.Where(c => c.SearchVector.Matches(EF.Functions.ToTsQuery(phase))));
}
公共异步任务搜索用户([FromHeader]字符串阶段)
{
返回Ok(_context.Users.Where(c=>c.SearchVector.Matches(EF.Functions.ToTsQuery(phase)));
}
将此转换置于Matches方法之外会引发“NotSupportedException”,而将纯文本作为函数参数会引发42883 Exception


现在,很明显我做错了什么。

正如@sonofaforester所建议的,我对自己的问题给出了答案:

从字符串转换为NpgsqlTsQuery必须在Matches方法内:

 public async Task<IActionResult> SearchUsers([FromHeader] string phase)
    {
        return Ok(_context.Users.Where(c => c.SearchVector.Matches(EF.Functions.ToTsQuery(phase))));
    }
public async Task<IActionResult> SearchUsers([FromHeader] string phase)
{
    return Ok(_context.Users.Where(c => c.SearchVector.Matches(EF.Functions.ToTsQuery(phase))));
}
公共异步任务搜索用户([FromHeader]字符串阶段)
{
返回Ok(_context.Users.Where(c=>c.SearchVector.Matches(EF.Functions.ToTsQuery(phase)));
}

将此对话置于Matches方法之外会引发“NotSupportedException”,将纯文本作为函数参数会引发42883异常。

您应该将答案作为实际答案,我很难看出您找到了实际的解决方案。当你这样做的时候,我会投上一票
 public async Task<IActionResult> SearchUsers([FromHeader] string phase)
    {
        return Ok(_context.Users.Where(c => c.SearchVector.Matches(EF.Functions.ToTsQuery(phase))));
    }
public async Task<IActionResult> SearchUsers([FromHeader] string phase)
{
    return Ok(_context.Users.Where(c => c.SearchVector.Matches(EF.Functions.ToTsQuery(phase))));
}