2

How to check values for null and not null together using TermQuery?

1. TermQuery termQuery = new TermQuery(new Term("referencekuki.unit.name","Kuki"));
2. query.add(termQuery, BooleanClause.Occur.SHOULD);
3. BooleanQuery q = new BooleanQuery();        
4. q.add(new TermQuery(new Term("reference", "null")),BooleanClause.Occur.SHOULD);
5. q.add(new TermQuery(new Term("reference", "null")),BooleanClause.Occur.MUST_NOT);
6. query.add(q, BooleanClause.Occur.MUST);

In table we have reference column which is either null and not null and we also have referencekuki column which always have data i.e Kuki.

If i write only line 1 & 2 then it returns no results; but in DB we have 160 records. I think it should get all rows.

If i write 1, 2 & 4 line it returns result with all references having Null

But i need all data whether reference is null and not null. So i tried above code but it is not giving desired results.

Could anyone assist how to fix the same?

Sanne
  • 6,027
  • 19
  • 34
fatherazrael
  • 5,511
  • 16
  • 71
  • 155
  • What analyzer are you using? If you are using StandardAnalyzer on your `referencekuki.unit.name` field, then it will be lowercased, and you should see results if you search for "kuki". – femtoRgon Apr 19 '17 at 15:36
  • There is no analyzer used. Only @Field(index = Index.YES, analyze = Analyze.NO, store = Store.NO) – fatherazrael Apr 20 '17 at 06:11
  • when no explicit analyzer is chosen it means you're using the `StandardAnalyzer` – Sanne Apr 26 '17 at 22:11

0 Answers0