我需要在lucene索引中搜索与特定正则表达式匹配的任何术语。我知道如果像这样配置了solr中的TermsComponent
,我可以使用它来完成:
<searchComponent name="terms" class="solr.TermsComponent"/>
<!-- A request handler for demonstrating the terms component -->
<requestHandler name="/terms" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<bool name="terms">true</bool>
<bool name="distrib">false</bool>
</lst>
<arr name="components">
<str>terms</str>
</arr>
</requestHandler>
例如,我想获取包含“表面缺陷”任何术语。使用Solr,我可以这样做:
http://localhost:8983/solr/core1/terms?terms.fl=content&
terms.regex=^(.*?(\bsurface%20defects\b)[^$]*)$&
terms.sort=count&
terms.limit=10000
但我的问题是,如何使用Lucene API而不是Solr来实现相同的功能?我查看了org.apache.solr.handler.component.TermsComponent
类,但对我来说并不是很明显。