【问题标题】:Hibernate apache lucene based full text search with one static filter使用一个静态过滤器的基于 Hibernate apache lucene 的全文搜索
【发布时间】:2017-01-06 12:33:18
【问题描述】:

我的目标是仅在活动项目中搜索 这是我的代码 sn-p:

 FullTextEntityManager fullTextEntityManager =
            Search.getFullTextEntityManager(this.getEntityManager());

    QueryBuilder queryBuilder =
        fullTextEntityManager.getSearchFactory()
        .buildQueryBuilder()
        .forEntity(Myclass.class)
        .get();

    BooleanJunction<BooleanJunction> booleanJunction = queryBuilder.bool();

    for(String token : tokens){
        booleanJunction.should( queryBuilder.keyword()
            .wildcard()
            .onFields("field1", "field2", "field3")
            .matching(token + "*")
            .createQuery());
    }

    FullTextQuery jpaQuery = fullTextEntityManager.createFullTextQuery(booleanJunction.createQuery(), MyClass.class);

我想用 field4 过滤,它是 Object,Enum, 我试过这个:

booleanJunction.must( queryBuilder.keyword()
            .wildcard()
            .onField("field4")
            .matching(Status.ACTIVE)
            .createQuery());

状态对象是枚举。

在这种情况下,如果上层不应该找到任何结果是所有活动项目,它会发生,因为它是布尔查询..

有什么建议吗?

【问题讨论】:

    标签: hibernate lucene full-text-search hibernate-search


    【解决方案1】:

    如果我理解正确,您需要这样的查询:

    +(token1* token2* token3*) +field4:active
    

    要构建它,您不想将 field4:active 部分添加到与令牌集相同的布尔查询中,您需要创建一个父布尔查询以根据需要添加令牌查询集(必须)查询。比如:

    BooleanJunction<BooleanJunction> parentJunction = queryBuilder.bool();
    parentJunction.must(booleanJunction.createQuery());
    parentJunction.must(field4activeQuery);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      相关资源
      最近更新 更多