Pergunta

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"
Foi útil?

Solução

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...
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top