2017-07-30 52 views
0

我有用NEST(c#)编写的percolate函数。我想启用突出显示功能但不起作用。渗滤器工作正常,但突出显示没有返回任何东西,在NEST文档中没有发现任何东西。任何帮助非常感谢。在NEST中写入的Percolate函数中突出显示Elasticsearch

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 

      .Highlight(h => h 
       .Fields(f => f 
       .Field(p => p.Query)) 
       .PreTags("<em>") 
       .PostTags("</em>") 
       .FragmentSize(20))); 

回答

0

The Elasticsearch documentation gives a good example of how to use percolate queries with highlighting。突出显示的渗透查询的工作方式稍有不同,因为中的Fields()应该是要突出显示的文档类型上的字段。

例如,给定

public class Document 
{ 
    public string Content { get; set; } 
} 

与突出了渗滤液的查询可能看起来像

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 
     ) 
    ) 
    .Highlight(h => h 
     .Fields(f => f 
      .Field(Infer.Field<Document>(ff => ff.Content)) 
     ) 
     .PreTags("<em>") 
     .PostTags("</em>") 
     .FragmentSize(20) 
    ) 
); 

Infer.Field<T>()用于获得DocumentHighlight<T>()content字段的名称是强类型的响应类型,在这种情况下,PercolatedQuery

+0

它的工作原理,非常感谢。 – Abdulaziz