0
votes

We are using lucene 2.4.0.

Some Thousand Docs are indexed in file system

Below Two Fields index along with many other fields:

I am using MultiFieldQueryParser because many other fields are involved in search query.

    EffectiveDate="1970-01-01T00:00:00-05:00"
    ExpirationDate="2035-12-31T00:00:00-05:00"

1.)

Is there any way to check whether the given date is between two indexed date fields or Not

2.)

Is there any way to set max size to the return results in lucene .

1
About 'countValue': I have no idea what you are referring to.femtoRgon
@femtoRgon countValue = its nothing but a value. can we set max size to the return results in lucene .NaveenKumar1410

1 Answers

1
votes

It looks like your dates are well formatted for lexicographic ordering, so to check whether a value is between two different fields will follow a pattern like. Lucene didn't begin supporting open-ended queries in the StandardQueryParser until version 3.6, so selecting adequantely large upper and lower bounds, to emulate an open ended query:

+EffectiveDate:[0000-01-01 TO value] +ExpirationDate:[value TO 9999-12-31]

Which, I believe, won't work well with MultiFieldQueryParser. You may need to run the rest of your Query through that parser, and something like the above through a StandardQueryParser and merge them with a BooleanQuery.

you could also construct the same query manually, something like:

TermRangeQuery tqlow = new TermRangeQuery("EffectiveDate", null, new BYtesRef(value), true, true);
TermRangeQuery tqlow = new TermRangeQuery("ExpirationDate", new BYtesRef(value), null, true, true);
BooleanQuery betweenQuery = new BooleanQuery();
betweenQuery.add(new BooleanClause(tqlow, BooleanClause.Occur.MUST));
betweenQuery.add(new BooleanClause(tqhigh, BooleanClause.Occur.MUST));

Query parsedQuery = MultiFieldQueryParser.parse............

BooleanQuery rootQuery = new BooleanQuery();
rootQuery.add(new BooleanClause(parsedQuery, BooleanClause.Occur.MUST));
rootQuery.add(new BooleanClause(betweenQuery, BooleanClause.Occur.MUST));