You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Markus Jelsma <ma...@openindex.io> on 2017/09/26 11:22:53 UTC

Moving to Point, trouble with IntPoint.newRangeQuery()

Hello,

I have a QParser impl. that transforms text input to one or more integers, it makes a BooleanQuery one a field with all integers in OR-more. It used to work by transforming the integer using LegacyNumericUtils.intToPrefixCoded, getting a BytesRef.

I have now moved it to use IntPoint.newRangeQuery(field, integer, integer), i read (think javadocs) this is the way to go, but i get no matches!

    Iterator<Integer> i = digests.iterator();
    while (i.hasNext()) {
      Integer digest = i.next();
      queryBuilder.add(IntPoint.newRangeQuery(field, digest, digest), Occur.SHOULD);
    }
    return queryBuilder.build();

To be sure i didn't mess up elsewhere i also tried building a string for LuceneQParser and cheat:

    Iterator<Integer> i = digests.iterator();
    while (i.hasNext()) {
      Integer digest = i.next();
      str.append(ClientUtils.escapeQueryChars(digest.toString()));
      if (i.hasNext()) {
        str.append(" OR ");
      }
    }
    QParser luceneQParser = new LuceneQParser(str.append(")").toString(), localParams, params, req);
    return luceneQParser.parse();

Well, this works! This is their respective debug output:

Using the IntPoint range query:

<result name="response" numFound="0" start="0">
</result>
<lst name="debug">
  <str name="rawquerystring">{!q  f=d1}value</str>
  <str name="querystring">{!q  f=d1}value</str>
  <str name="parsedquery">(d1:[-1820898630 TO -1820898630])</str>
  <str name="parsedquery_toString">d1:[-1820898630 TO -1820898630]</str>

LuceneQParser cheat, it does find!

<result name="response" numFound="2" start="0">
  <doc>
    <str name="id">1</str>
    <int name="d1">-1820898630</int></doc>
</result>
<lst name="debug">
  <str name="rawquerystring">{!qd f=d1}value</str>
  <str name="querystring">{!qd f=d1}value</str>
  <str name="parsedquery">d1:-1820898630</str>

There is not much difference in output, it looks fine, using LuceneQParser you can also match using a range query, so what am i doing wrong?

Many thanks!
Markus

RE: Moving to Point, trouble with IntPoint.newRangeQuery()

Posted by Markus Jelsma <ma...@openindex.io>.
Thanks! I'll try it and get back later!

 
 
-----Original message-----
> From:Chris Hostetter <ho...@fucit.org>
> Sent: Tuesday 26th September 2017 18:52
> To: Solr-user <so...@lucene.apache.org>
> Subject: Re: Moving to Point, trouble with IntPoint.newRangeQuery()
> 
> 
> : I have a QParser impl. that transforms text input to one or more 
> : integers, it makes a BooleanQuery one a field with all integers in 
> : OR-more. It used to work by transforming the integer using 
> : LegacyNumericUtils.intToPrefixCoded, getting a BytesRef.
> : 
> : I have now moved it to use IntPoint.newRangeQuery(field, integer, 
> : integer), i read (think javadocs) this is the way to go, but i get no 
> : matches!
> 
> As a general point: if you want to do this in a modular way, you should 
> fetch the FieldType from the IndexSchema and use the 
> FieldType.getRangeQuery(...) method.
> 
> That said -- at a quick glance, knowing how your schema is defined, i'm 
> not sure why/how your IntPoint.newRangeQuery() code would fail.
> 
> Maybe add a lower level test of the QParser directly and assert some 
> explicit properties on the Query objects? (class, etc...)
> 
> 
> 
> -Hoss
> http://www.lucidworks.com/
> 

Re: Moving to Point, trouble with IntPoint.newRangeQuery()

Posted by Chris Hostetter <ho...@fucit.org>.
: I have a QParser impl. that transforms text input to one or more 
: integers, it makes a BooleanQuery one a field with all integers in 
: OR-more. It used to work by transforming the integer using 
: LegacyNumericUtils.intToPrefixCoded, getting a BytesRef.
: 
: I have now moved it to use IntPoint.newRangeQuery(field, integer, 
: integer), i read (think javadocs) this is the way to go, but i get no 
: matches!

As a general point: if you want to do this in a modular way, you should 
fetch the FieldType from the IndexSchema and use the 
FieldType.getRangeQuery(...) method.

That said -- at a quick glance, knowing how your schema is defined, i'm 
not sure why/how your IntPoint.newRangeQuery() code would fail.

Maybe add a lower level test of the QParser directly and assert some 
explicit properties on the Query objects? (class, etc...)



-Hoss
http://www.lucidworks.com/

Re: Moving to Point, trouble with IntPoint.newRangeQuery()

Posted by Alan Woodward <al...@flax.co.uk>.
The Points queries use a completely different data structure to the previous range queries, so you can’t just use them interchangeably, you have to reindex your data.  I’m guessing your ‘d1’ field here is a TrieIntField or similar?

Alan Woodward
www.flax.co.uk


> On 26 Sep 2017, at 12:22, Markus Jelsma <ma...@openindex.io> wrote:
> 
> Hello,
> 
> I have a QParser impl. that transforms text input to one or more integers, it makes a BooleanQuery one a field with all integers in OR-more. It used to work by transforming the integer using LegacyNumericUtils.intToPrefixCoded, getting a BytesRef.
> 
> I have now moved it to use IntPoint.newRangeQuery(field, integer, integer), i read (think javadocs) this is the way to go, but i get no matches!
> 
>    Iterator<Integer> i = digests.iterator();
>    while (i.hasNext()) {
>      Integer digest = i.next();
>      queryBuilder.add(IntPoint.newRangeQuery(field, digest, digest), Occur.SHOULD);
>    }
>    return queryBuilder.build();
> 
> To be sure i didn't mess up elsewhere i also tried building a string for LuceneQParser and cheat:
> 
>    Iterator<Integer> i = digests.iterator();
>    while (i.hasNext()) {
>      Integer digest = i.next();
>      str.append(ClientUtils.escapeQueryChars(digest.toString()));
>      if (i.hasNext()) {
>        str.append(" OR ");
>      }
>    }
>    QParser luceneQParser = new LuceneQParser(str.append(")").toString(), localParams, params, req);
>    return luceneQParser.parse();
> 
> Well, this works! This is their respective debug output:
> 
> Using the IntPoint range query:
> 
> <result name="response" numFound="0" start="0">
> </result>
> <lst name="debug">
>  <str name="rawquerystring">{!q  f=d1}value</str>
>  <str name="querystring">{!q  f=d1}value</str>
>  <str name="parsedquery">(d1:[-1820898630 TO -1820898630])</str>
>  <str name="parsedquery_toString">d1:[-1820898630 TO -1820898630]</str>
> 
> LuceneQParser cheat, it does find!
> 
> <result name="response" numFound="2" start="0">
>  <doc>
>    <str name="id">1</str>
>    <int name="d1">-1820898630</int></doc>
> </result>
> <lst name="debug">
>  <str name="rawquerystring">{!qd f=d1}value</str>
>  <str name="querystring">{!qd f=d1}value</str>
>  <str name="parsedquery">d1:-1820898630</str>
> 
> There is not much difference in output, it looks fine, using LuceneQParser you can also match using a range query, so what am i doing wrong?
> 
> Many thanks!
> Markus


Re: Moving to Point, trouble with IntPoint.newRangeQuery()

Posted by Michael Kuhlmann <ku...@solr.info>.
Arrgh, forget my question. I just see that newExactQuery() simply
triggers newRangeQuery() like you already do.

-Michael

Am 26.09.2017 um 13:29 schrieb Michael Kuhlmann:
> Hi Markus,
> 
> I don't know why there aren't any results. But just out of curiosity,
> why don't you use the better choice IntPoint.newExectQuery(String,int)?
> 
> What happens if you use that?
> 
> -Michael
> 
> Am 26.09.2017 um 13:22 schrieb Markus Jelsma:
>> Hello,
>>
>> I have a QParser impl. that transforms text input to one or more integers, it makes a BooleanQuery one a field with all integers in OR-more. It used to work by transforming the integer using LegacyNumericUtils.intToPrefixCoded, getting a BytesRef.
>>
>> I have now moved it to use IntPoint.newRangeQuery(field, integer, integer), i read (think javadocs) this is the way to go, but i get no matches!
>>
>>     Iterator<Integer> i = digests.iterator();
>>     while (i.hasNext()) {
>>       Integer digest = i.next();
>>       queryBuilder.add(IntPoint.newRangeQuery(field, digest, digest), Occur.SHOULD);
>>     }
>>     return queryBuilder.build();
>>
>> To be sure i didn't mess up elsewhere i also tried building a string for LuceneQParser and cheat:
>>
>>     Iterator<Integer> i = digests.iterator();
>>     while (i.hasNext()) {
>>       Integer digest = i.next();
>>       str.append(ClientUtils.escapeQueryChars(digest.toString()));
>>       if (i.hasNext()) {
>>         str.append(" OR ");
>>       }
>>     }
>>     QParser luceneQParser = new LuceneQParser(str.append(")").toString(), localParams, params, req);
>>     return luceneQParser.parse();
>>
>> Well, this works! This is their respective debug output:
>>
>> Using the IntPoint range query:
>>
>> <result name="response" numFound="0" start="0">
>> </result>
>> <lst name="debug">
>>   <str name="rawquerystring">{!q  f=d1}value</str>
>>   <str name="querystring">{!q  f=d1}value</str>
>>   <str name="parsedquery">(d1:[-1820898630 TO -1820898630])</str>
>>   <str name="parsedquery_toString">d1:[-1820898630 TO -1820898630]</str>
>>
>> LuceneQParser cheat, it does find!
>>
>> <result name="response" numFound="2" start="0">
>>   <doc>
>>     <str name="id">1</str>
>>     <int name="d1">-1820898630</int></doc>
>> </result>
>> <lst name="debug">
>>   <str name="rawquerystring">{!qd f=d1}value</str>
>>   <str name="querystring">{!qd f=d1}value</str>
>>   <str name="parsedquery">d1:-1820898630</str>
>>
>> There is not much difference in output, it looks fine, using LuceneQParser you can also match using a range query, so what am i doing wrong?
>>
>> Many thanks!
>> Markus
>>
> 


Re: Moving to Point, trouble with IntPoint.newRangeQuery()

Posted by Michael Kuhlmann <ku...@solr.info>.
Hi Markus,

I don't know why there aren't any results. But just out of curiosity,
why don't you use the better choice IntPoint.newExectQuery(String,int)?

What happens if you use that?

-Michael

Am 26.09.2017 um 13:22 schrieb Markus Jelsma:
> Hello,
> 
> I have a QParser impl. that transforms text input to one or more integers, it makes a BooleanQuery one a field with all integers in OR-more. It used to work by transforming the integer using LegacyNumericUtils.intToPrefixCoded, getting a BytesRef.
> 
> I have now moved it to use IntPoint.newRangeQuery(field, integer, integer), i read (think javadocs) this is the way to go, but i get no matches!
> 
>     Iterator<Integer> i = digests.iterator();
>     while (i.hasNext()) {
>       Integer digest = i.next();
>       queryBuilder.add(IntPoint.newRangeQuery(field, digest, digest), Occur.SHOULD);
>     }
>     return queryBuilder.build();
> 
> To be sure i didn't mess up elsewhere i also tried building a string for LuceneQParser and cheat:
> 
>     Iterator<Integer> i = digests.iterator();
>     while (i.hasNext()) {
>       Integer digest = i.next();
>       str.append(ClientUtils.escapeQueryChars(digest.toString()));
>       if (i.hasNext()) {
>         str.append(" OR ");
>       }
>     }
>     QParser luceneQParser = new LuceneQParser(str.append(")").toString(), localParams, params, req);
>     return luceneQParser.parse();
> 
> Well, this works! This is their respective debug output:
> 
> Using the IntPoint range query:
> 
> <result name="response" numFound="0" start="0">
> </result>
> <lst name="debug">
>   <str name="rawquerystring">{!q  f=d1}value</str>
>   <str name="querystring">{!q  f=d1}value</str>
>   <str name="parsedquery">(d1:[-1820898630 TO -1820898630])</str>
>   <str name="parsedquery_toString">d1:[-1820898630 TO -1820898630]</str>
> 
> LuceneQParser cheat, it does find!
> 
> <result name="response" numFound="2" start="0">
>   <doc>
>     <str name="id">1</str>
>     <int name="d1">-1820898630</int></doc>
> </result>
> <lst name="debug">
>   <str name="rawquerystring">{!qd f=d1}value</str>
>   <str name="querystring">{!qd f=d1}value</str>
>   <str name="parsedquery">d1:-1820898630</str>
> 
> There is not much difference in output, it looks fine, using LuceneQParser you can also match using a range query, so what am i doing wrong?
> 
> Many thanks!
> Markus
>