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 Leon <lm...@netzero.net> on 2007/04/05 19:38:14 UTC
indexing and searching real numbers
Hello everybody,
I need to index and search real numbers in Lucene. I found NumberUtils class
in Solr project which permits one to encode doubles into string so that
alpha numeric ordering would correctly correspond to the ordering on
numbers. When I use ConstantScoreRangeQuery programmatically everything
works just fine. However when I convert this query to a string, parse it
with QueryParser and use the resulting query – no result are found.
ConstantScoreRangeQuery wquery =
new ConstantScoreRangeQuery("westbc", null,
NumberUtils.double2sortableStr(-110.500000), false, true);
Hits hits = is.search(wquery); //returns expected results
Now if I do
String wqueryString = wquery.toString();
QueryParser queryParser = new QueryParser("westbc", new KeywordAnalyzer());
Query query = queryParser.parse(wqueryString);
Hits hits = is.search(query); // returns nothing
Interesting is that System.out.println(wquery.toString()) looks exactly the
same as System.out.println(query.toString()).
Any ideas welcome.
Thanks,
Leon
--
View this message in context: http://www.nabble.com/indexing-and-searching-real-numbers-tf3532728.html#a9859816
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: indexing and searching real numbers
Posted by Yonik Seeley <yo...@apache.org>.
On 4/5/07, Leon <lm...@netzero.net> wrote:
> I need to index and search real numbers in Lucene. I found NumberUtils class
> in Solr project which permits one to encode doubles into string so that
> alpha numeric ordering would correctly correspond to the ordering on
> numbers. When I use ConstantScoreRangeQuery programmatically everything
> works just fine. However when I convert this query to a string, parse it
> with QueryParser and use the resulting query – no result are found.
>
> ConstantScoreRangeQuery wquery =
> new ConstantScoreRangeQuery("westbc", null,
> NumberUtils.double2sortableStr(-110.500000), false, true);
> Hits hits = is.search(wquery); //returns expected results
>
> Now if I do
>
> String wqueryString = wquery.toString();
> QueryParser queryParser = new QueryParser("westbc", new KeywordAnalyzer());
> Query query = queryParser.parse(wqueryString);
> Hits hits = is.search(query); // returns nothing
Query.toString() is really for debugging only, and I don't believe
current implementations try to escape characters that might be interpreted
as something else if reparsed.
Simple example... I think
(new TermQuery(new Term("foo","\"a\""))).toString() would yield
foo:"a"
which if put through the query parser, would be parsed as
foo:a
-Yonik
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: indexing and searching real numbers
Posted by Leon <lm...@netzero.net>.
Thanks for your reply Otis,
wquery.toString() returns westbc:[* TO ????]
query.toString() returns westbc:[* TO ????]
If I compare these two strings for equality like
wquery.toString().equals(query.toString()) I get true. I also got bytes of
those strings and compared them bytewise - they are equal this way too.
Ideas are welcome.
Leonid
Otis Gospodnetic wrote:
>
> You can't really rely on Query.toString() to produce a valid query
> identical to the query in that Query instance. Are you sure both produce
> the same query string? You didn't include that.
>
> Otis
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> Simpy -- http://www.simpy.com/ - Tag - Search - Share
>
> ----- Original Message ----
> From: Leon <lm...@netzero.net>
> To: java-user@lucene.apache.org
> Sent: Thursday, April 5, 2007 1:38:14 PM
> Subject: indexing and searching real numbers
>
>
> Hello everybody,
>
> I need to index and search real numbers in Lucene. I found NumberUtils
> class
> in Solr project which permits one to encode doubles into string so that
> alpha numeric ordering would correctly correspond to the ordering on
> numbers. When I use ConstantScoreRangeQuery programmatically everything
> works just fine. However when I convert this query to a string, parse it
> with QueryParser and use the resulting query – no result are found.
>
> ConstantScoreRangeQuery wquery =
> new ConstantScoreRangeQuery("westbc", null,
> NumberUtils.double2sortableStr(-110.500000), false, true);
> Hits hits = is.search(wquery); //returns expected results
>
> Now if I do
>
> String wqueryString = wquery.toString();
> QueryParser queryParser = new QueryParser("westbc", new
> KeywordAnalyzer());
> Query query = queryParser.parse(wqueryString);
> Hits hits = is.search(query); // returns nothing
>
> Interesting is that System.out.println(wquery.toString()) looks exactly
> the
> same as System.out.println(query.toString()).
>
> Any ideas welcome.
>
> Thanks,
>
> Leon
> --
> View this message in context:
> http://www.nabble.com/indexing-and-searching-real-numbers-tf3532728.html#a9859816
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/indexing-and-searching-real-numbers-tf3532728.html#a9867984
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org