We´d like to implement a fulltext search for eg. adress-search. The user input´s the name of the municipality and the first letters of the streetname.
{code:java} queryBuilder.keyword().wildcard().onFields("municipality" ).onFields( , "streetname").matching("vienna mari*").createQuery(); {code}
This does not work, because org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder does the following:
{code:java} private List<String> getAllTermsFromText(String fieldName, String localText, Analyzer analyzer) { //it's better not to apply the analyzer with wildcard as * and ? can be mistakenly removed List<String> terms = new ArrayList<String>(); if ( termContext.getApproximation() == TermQueryContext.Approximation.WILDCARD ) { terms.add( localText ); } else { try { terms = Helper.getAllTermsFromText( fieldName, localText, analyzer ); } catch (IOException e) { throw new AssertionFailure( "IO exception while reading String stream??", e ); } } return terms; } {code}
The comment tell´s is, this behaviour is intended. But it depends on the configured Analyzer. In our case we use WhitespaceTokenizerFactory, so there won´t be a issue with removed * or ?. I´d like to see some kind of configuration to influence this behavior for wildcard-search.
As a workarround we think of manually building the lucene-query. |
|