Reputation: 39
I'm working in Lucene 4.6 and i'm trying to look for records that contains "keyword1" in "field1" and "keyword2" in "field2" I wrote following query:
Query q = MultifieldQueryParser.parse(
Version.Lucene_46,
new String[] {keyword1, keyword2},
new String[]{"field1","field2"},
new StandardAnalyzer()
);
That gives me some results but I want to have something like %keyword1% , %keyword2% in SQL.
Thanks for your answers. In case I have a field with the value "Lucene Game Lucene" and I'm looking for that document using the keyword "Game" I can't get that result using keyword neither keyword Who have any idea about this?
Upvotes: 0
Views: 2108
Reputation: 20069
You can use WildcardQuery. Supported wildcards are *
, which matches any character sequence (including the empty one), and ?
, which matches any single character. \
is the escape character.
You can also use the wildcard as prefix, for example *nix
, but that can very slow on large indexes, because Lucene needs to scan the entire list of Terms
.
[edit]
If you need a prefix wildcard in the queryparser, make sure to call setAllowLeadingWildcard(true)
on the QueryParser
As can be seen here
Upvotes: 3
Reputation: 1395
WildcardQuery in Lucene provides the possibility to search for keyword%. For the other way arount there is some work to be done during indexing. You need to index the terms in reversed form (in an other field) and perform the query drowyek%.
Upvotes: 1