在Liferay的BooleanQuery中使用按术语过滤

时间:2018-09-06 12:13:58

标签: elasticsearch liferay liferay-7

我能够使用后过滤器:

    POST _search
    {
      "query": {
        "bool" : {
          "must" : {
            "term" : { "user" : "kimchy" }
          }
        }
       },
       "post_filter":{
            "terms" : { "tag" : ["tech", "luxury"] }
          },
       ...
    }

代码以完成该查询:

 SearchEngine searchEngine=SearchEngineHelperUtil
                                    .getSearchEngine(s_ctx.getSearchEngineId());
 IndexSearcher indexSearcher = searchEngine.getIndexSearcher();
 ...
 TermsFilter termsFilter = new TermsFilter("tag");
 termsFilter.addValue("tech");
 termsFilter.addValue("luxury");

 BooleanQuery booleanQuery = new BooleanQueryImpl(); //use factory instead
 ...
 booleanQuery.setPostFilter(termsFilter);
 indexSearcher.search(s_ctx, booleanQuery);
 ....
 //s_ctx is the searchContext

我想要的是类似于ElasticSearch doc的查询:

   POST _search
    {
      "query": {
        "bool" : {
          "must" : {
            "term" : { "user" : "kimchy" }
          },
          "filter": {
            "terms" : { "tag" : ["tech", "luxury"] }
          },
       ...
    }

如何使用BoolQuery.class或liferay 7中的类似内容在自定义Portlet中执行该查询?

0 个答案:

没有答案