Lucene: Multi-word phrases as search terms

The reason why you don’t get your documents back is that while indexing you’re using StandardAnalyzer, which converts tokens to lowercase and removes stop words. So the only term that gets indexed for your example is ‘crescent’. However, wildcard queries are not analyzed, so ‘the’ is included as mandatory part of the query. The same goes for phrase queries in your scenario.

KeywordAnalyzer is probably not very suitable for your use case, because it takes whole field content as a single token. You can use SimpleAnalyzer for the street field — it will split the input on all non-letter characters and then convert them to lowercase. You can also consider using WhitespaceAnalyzer with LowerCaseFilter. You need to try different options and work out what works best for your data and users.

Also, you can use different analyzers per field (e.g. with PerFieldAnalyzerWrapper) if changing analyzer for that field breaks other searches.

Leave a Comment