1
votes

We are using Lucene.net beta version - Lucene.net 48. We want to provide support for not like clause using lucene query object. We are using WildcardQuery class for wild card support and using boolean clause as 'BooleanClause.Occur.MUST_NOT'.

It is generating query --> : "-company:lucene*".

It has '-' sign before query but it is not returning data where company is not like lucene*. Ideally, it should return 'elastic', 'mongodb', etc.

WildcardQuery qfWildcard = new WildcardQuery(new Term("company","lucene*"));
BooleanQuery bq = new BooleanQuery();
bq.Add(qfWildcard, BooleanClause.Occur.MUST_NOT);

On other way, WildcardQuery with MUST clause is working.

Query --> : "+company:lucene*".

It has '+' sign before query and it is returning data where company is like 'lucene*'. It is returning 'lucene', 'lucene.net', etc.

WildcardQuery qfWildcard = new WildcardQuery(new Term("company","lucene*"));
BooleanQuery bq= new BooleanQuery();
bq.Add(qfWildcard, BooleanClause.Occur.MUST);

Please help me, if any one know about the solution using WildcardQuery class or any other class or any alternative way to solve the issue.

Please also let me know, if there is way to support - 'Is Null' and 'Is Not Null' clause.

1
'Is Null' and 'Is Not Null', can be supported by storing all fields in index document. But, I am looking for syntax/api based field exist in document or not. If some field does not exist in indexed document, means it is 'null'. And, if field exist in indexed document means, is 'not null'. Didn't found any api/class in lucene.net 48 version.Nikunj Banker

1 Answers

2
votes

Querying with only a MUST_NOT clause will not work. A MUST_NOT clause does only what it says, it specifies which documents must not be matched. It doesn't say anything about which documents should be matched, and doesn't imply that everything else should be retrieved (further discussion here).

You must always have a SHOULD or MUST clause in your BooleanQuery. To match everything else, you can use a MatchAllDocsQuery.

WildcardQuery qfWildcard = new WildcardQuery(new Term("company","lucene*"));
BooleanQuery bq = new BooleanQuery();
bq.Add(qfWildcard, BooleanClause.Occur.MUST_NOT);
bq.Add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD);