0

我的问题是如何使用 NEST (c#) 在渗透函数中使用多匹配、倾斜和模糊等搜索选项?

我想实现一个渗透函数,它返回与以下搜索函数完全相反的结果:

public List<string> search(string query){
.......
.......
var searchResponse = client.Search<Document>(s => s 
                .AllTypes()
                   .From(0)
                   .Take(10)
                .Query(q => q               // define query
                    .MultiMatch(mp => mp            // of type MultiMatch
                    .Query(input.Trim())
                    .Fields(f => f          // define fields to search against
                    .Fields(f3 => f3.doc_text))
                    .Slop(2)
                    .Operator(Operator.And)
                    .Fuzziness(Fuzziness.Auto))));
}

以下是我目前使用的渗透函数,但不知道如何包含多匹配、倾斜和模糊选项。我在其文档中找不到有关此的详细信息。

var searchResponseDoc = client.Search<PercolatedQuery>(s => s
               .Query(q => q
               .Percolate(f => f
               .Field(p => p.Query)
               .DocumentType<Document>() //I have a class called Document
               .Document(myDocument))) // myDocument is an object of type Document

谢谢。

4

1 回答 1

2

首先,您正在执行multi_match具有所需选项的查询。在后者中,您进行percolator查询。

如果你想两者都做,你可以使用二进制和位运算符,例如

.Query(q => 
    !q.MultiMatch(mp => mp
        .Query(input.Trim())
        .Fields(f => f.Fields(f3 => f3.doc_text))
        .Slop(2)
        .Operator(Operator.And)
        .Fuzziness(Fuzziness.Auto)
    )
    && q.Percolate(f => f
           .Field(p => p.Query)
           .DocumentType<Document>()
           .Document(myDocument)
    )
)

不使用&&来创建bool将两个查询作为must子句的查询。一元运算!符通过将查询包装在 abool中并将查询放在must_not子句中来否定查询。

查看更多信息https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/writing-queries.html

https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/bool-queries.html

于 2017-07-26T17:52:45.320 回答