Don't use a TermQuery
. TermQuery
is a simple query exactly matching the given text. If you are manually constructing a query, there isn't a query parser to handle that sort of thing for you, so you have to select the correct types of queries yourself.
PrefixQuery
is the one you are looking for:
bq.add(new PrefixQuery(new Term("id", queryKeyValue)), BooleanClause.Occur.MUST);
I don't think this will do what you want, however. The difference between
+meta.type:typeA +id:12345678
and
+meta.type:typeA +id:12345678 +id:12345678*
Is actually quite trivial. You will not get more results that way, because you still require an exact id
match. I believe what you are looking for is probably more like:
+meta.type:typeA +(id:12345678 id:12345678*)