You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Samuru Jackson <sa...@googlemail.com> on 2006/03/15 15:14:39 UTC

inclusive range search

Hi!

I have some trouble to use the inclusive range search explained in
Lucene in Action in ch. 2.5.5

What I do is to add several fields to the index this way:

document.add(Field.Keyword("id", key));
document.add(Field.Keyword("type", type));
document.add(Field.Text("text",text));
document.add(Field.Text("date",date));

The focus lies on "Field.Text("date", date)" where date is a String of
the format YYYYMMDD.

My search goes this way:

search = "date:[20040101 TO 20040101]  Paris"
Query query = QueryParser.parse(search.trim(), "text", new StandardAnalyzer());
Hits hits = indexSearcher.search(query);


Somehow this range search does not work. I still get the same results
as without the date:[..]


Can anyone give me a hint how to use this inclusive range search?

Thanks!

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: inclusive range search

Posted by mark harwood <ma...@yahoo.co.uk>.
> What I did is this:
> 
> TermsFilter filter = new TermsFilter();
> filter.addTerm(new Term("date", "20060304 TO
> 20060304"));


The Term object's constructor in your example does not
parse the "20060304 TO 20060304" string. A term is
supposed to represent a single term exactly as it
appears in your search index, not a query to be
parsed.

TermsFilter is intended to allow you to construct a
filter from an arbitrary collection of terms.
Sounds like you actually want to define a range of
terms so see RangeFilter instead.





		
___________________________________________________________ 
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: inclusive range search

Posted by Samuru Jackson <sa...@googlemail.com>.
> Try making bother terms mandatory with "+"
>
> "+date:[20040101 TO 20040101]  +Paris"

That was it .. however it does not exactly suite my needs. I want to
create a few combo boxes to let the user create a datefilter (From and
To) on the search queries using a webform.

Now if he chooses 20040101 to 20040201 and enters "Paris" (without +)
into the searchfield he will get back all documents according to the
date plus all documents containing Paris.

This result would be valid but not intuitive because if someone is
creating a date range he assumes that the delivered results of
documents containing Paris will only be inside this daterange.

So obviously I want to create a datefilter on the "Paris"-results.

What I did is this:

TermsFilter filter = new TermsFilter();
filter.addTerm(new Term("date", "20060304 TO 20060304"));
	    	
Query query = QueryParser.parse(search.trim(), "text", new StandardAnalyzer());
	

But somehow the filter does not work with the "TO" syntax.

Can you point me out how to create a "daterange" filter using the QueryParser?

Thanks again!

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: inclusive range search

Posted by Yonik Seeley <ys...@gmail.com>.
On 3/15/06, Samuru Jackson <sa...@googlemail.com> wrote:
> search = "date:[20040101 TO 20040101]  Paris"
> Somehow this range search does not work. I still get the same results
> as without the date:[..]

Try making bother terms mandatory with "+"

"+date:[20040101 TO 20040101]  +Paris"

http://lucene.apache.org/java/docs/queryparsersyntax.html


-Yonik
http://incubator.apache.org/solr Solr, The Open Source Lucene Search Server

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org