0

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 .

NaveenKumar1410
  • 1,565
  • 14
  • 20

1 Answers1

1

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));
femtoRgon
  • 32,893
  • 7
  • 60
  • 87
  • countValue = its nothing but a value. can we set max size to the return results in lucene . – NaveenKumar1410 Jun 19 '13 at 12:24
  • 1
    Still not sure what you mean. You can set the max number of results found with your [IndexSearcher.search](http://lucene.apache.org/core/4_0_0-BETA/core/org/apache/lucene/search/IndexSearcher.html#search(org.apache.lucene.search.Query,%20int)) call, and you can get the number of hits found from [TopDocs.totalHits](http://lucene.apache.org/core/4_0_0-BETA/core/org/apache/lucene/search/TopDocs.html#totalHits). Either of those what you are trying to get? – femtoRgon Jun 19 '13 at 15:20
  • eg:) if I setted maxCount = 15 then it should return top 15 results.. Is that possible – NaveenKumar1410 Jun 20 '13 at 04:34
  • 1
    Like I said, pass it to your call to IndexSearcher.search. Unless you pass it a Collector instead, you are actually required to give it a maximum number of documents to return. – femtoRgon Jun 20 '13 at 05:30
  • +ExpirationDate:[value TO *] some problem with this range query – NaveenKumar1410 Jun 27 '13 at 07:20
  • http://stackoverflow.com/questions/17337098/lucene-2-4-0-range-query-is-not-working-as-expected – NaveenKumar1410 Jun 27 '13 at 08:34
  • To accept answer :- edit you answer to +ExpirationDate:[value TO null] it will help others too – NaveenKumar1410 Jun 28 '13 at 04:42