My Lucene queries will usually exist of a bunch of AND combined fields. Is it possible to get the queried fields out of the Query object again?
从Lucene查询中获取查询词以进行高亮显示
原标题:
问题回答
您是指提取项或字段名称吗?由于您已经知道您处理的是布尔查询,要提取字段,您可以简单地迭代由BooleanQuery.getClauses()返回的BooleanClause数组,将每个子句重写为其基础查询(Query.rewrite),并递归应用,直到您手头上有一个TermQuery。
如果您指的是术语提取,我不确定 Lucene.NET 是否支持,但在 Java Lucene 中,您可以使用 org.apache.lucene.search.highlight.QueryTermExtractor。您可以将一个(重写的)查询传递给其中一个 getTerms 重载函数,并获得 WeightedTerms 数组。
就我所记得的,使用此技术的缺点有:
- Since it internally uses a term set it won t handle multiple instances of the same token, e.g. "dream within a dream"
- It only supports base query types (TermQuery, BooleanQuery and any other query type which supports Query.extractTerms). I believe we ve used it internally for SpanNearQuery and SpanNearOrderedQuery instances, but I may be wrong on this.
无论如何,我希望这足以让你开始。
相关问题
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding