Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for terms in the index which are a prefix of the search term or vice versa (!)

Tags:

java

lucene

I would like for Lucene to find a document containing a term "bahnhofstr" if I search for "bahnhofstrasse", i.e., I don't only want to find documents containing terms of which my search term is a prefix but also documents that contain terms that are themselves a prefix of my search term...

How would I go about this?

like image 327
Damian Birchler Avatar asked Nov 15 '12 08:11

Damian Birchler


1 Answers

If I understand you correctly, and your search string is an exact string, you can set queryParser.setAllowLeadingWildcard(true); in Lucene to allow for leading-wildcard searches (which may or may not be slow -- I have seen them reasonably fast but in a case where there were only 60,000+ Lucene documents).

Your example query syntax could look something like:

*bahnhofstr bahnhofstr*

or possibly (have not tested this) just:

*bahnhofstr*
like image 56
Mark Leighton Fisher Avatar answered Nov 02 '22 12:11

Mark Leighton Fisher