質問

If I specify two types of searches (matching and fuzzy) on the same field of a class like the following:

  QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(User.class).get();
  qb.bool().should(qb.keyword().onField("name").matching(searchQuery).createQuery())
     .should(qb.keyword().fuzzy().withPrefixLength(1).onField("name").matching(searchQuery).createQuery());

Will the search above end up being:

MATCHING searchQuery against "name" OR Fuzzy searchQuery against "name"
役に立ちましたか?

解決

I believe you may be missing a createQuery() at the end, but otherwise, looks reasonable enough to me, but you can always check for yourself. Once you have created the final query, just use the Query.toString() method, which should give you a human readable representation of the query, provided you are reasonably familiar with Lucene query parser syntax. Like:

QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(User.class).get();
Query query = qb.bool()
    .should(qb.keyword().onField("name").matching(searchQuery).createQuery())
    .should(qb.keyword().fuzzy().withPrefixLength(1).onField("name").matching(searchQuery).createQuery())
.createQuery();

System.out.println(query.toString())
//Or however you like to output debugging information...
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top