0
votes

Im Pretty new to Lucene indexing. I have a table with fields ID ,NAME and NATIONALITY all indexed using an NGRAM Analyzer(2,2). Now i need to query a list of ID's(say 12345 and 98765) from the table. How can i do that?

I tried Boolean Query like this:

BooleanQuery.add("ID:"12 23 34 45" ,Occur.SHOULD);
BooleanQuery.add("ID:"98 87 76 65" ,Occur.SHOULD);

Since indexing is done with Ngram Analyzer with maxgram width as 2. it takes the list and tokens it to set of 2 and searches it;Result-I get a list of ID's with so many values.

I tried Occur.MUST. but returned 0 results.

1

1 Answers

0
votes

In query syntax, I think you want:

( +12 +23 +34 +45 ) ( +98 +87 +76 +65 )

which will return hits with either all of (12, 23, 34, 45) or all of (98, 87, 76, 65). Basically, the ngrams from the ID themselves are MUST queries, wrapped inside a SHOULD query (this wrapping is the secret sauce).