Mailing List Archive

StandardQueryParser and numeric fields
Hello,



I'm banging my head at this point, hoping someone can help me.



I can't get StandardQueryParser to work on numeric fields. Luke v9.8.0
finds the records for me. Example search query string in Luke that works:
eventIdNum:3001



Here is my code:



Query initQuery() {

StandardQueryParser p = new StandardQueryParser( analyzer );

p.setDefaultOperator( StandardQueryConfigHandler.Operator.AND );

String queryString = "eventIdNum:3001";

return p.parse( queryString, "any" );

}



here is how the field was added to the index:

d.add( new IntField( "eventIdNum", 3001, Field.Store.NO ) );



I've tried various analyzers. Example: new StandardAnalyzer(
CharArraySet.EMPTY_SET );





I'm sure there is something I'm missing here, but I can't seem to track down
what I'm missing. The analyzer is the exact same analyzer I'm using during
indexing. It's a PerFieldAnalyzerWrapper. The specific analyzer for the
numeric fields is the one I mentioned above (StandardAnalyzer).



The query used is:

indexSearcher.search( query, 10 );



Thank you,



Tony Schwartz
Re: StandardQueryParser and numeric fields [ In reply to ]
Hi,

By default the standard query parser has no idea about field types (and
it cannot because it does not know the schema of your index). If you
want to allow searching in non-text fields (TextField, all other - also
normal StringField breaks easy), you need to customize it.

There are 2 query parsers that I would call "standard":

* For the default / classic QueryParser the QueryParser#newXYQuery
methods need to be adapted (by subclassing) to generate a query
based on the text input. This is how Solr/Elasticsearch adapt their
schemas.
* For the flexible query parser (I think you mean that one with
StandardQueryParser), there is an option to use PointsConfig
instances and set a "per field" mapping how to parse points. Use
StandardQueryParser#setPointsConfigMap?() for that. Unfortunately
Javadocs is missing....

This is what Solr/Elasticsearch/Opensearch do.

Uwe

Am 14.11.2023 um 03:01 schrieb Tony Schwartz:
> Hello,
>
>
>
> I'm banging my head at this point, hoping someone can help me.
>
>
>
> I can't get StandardQueryParser to work on numeric fields. Luke v9.8.0
> finds the records for me. Example search query string in Luke that works:
> eventIdNum:3001
>
>
>
> Here is my code:
>
>
>
> Query initQuery() {
>
> StandardQueryParser p = new StandardQueryParser( analyzer );
>
> p.setDefaultOperator( StandardQueryConfigHandler.Operator.AND );
>
> String queryString = "eventIdNum:3001";
>
> return p.parse( queryString, "any" );
>
> }
>
>
>
> here is how the field was added to the index:
>
> d.add( new IntField( "eventIdNum", 3001, Field.Store.NO ) );
>
>
>
> I've tried various analyzers. Example: new StandardAnalyzer(
> CharArraySet.EMPTY_SET );
>
>
>
>
>
> I'm sure there is something I'm missing here, but I can't seem to track down
> what I'm missing. The analyzer is the exact same analyzer I'm using during
> indexing. It's a PerFieldAnalyzerWrapper. The specific analyzer for the
> numeric fields is the one I mentioned above (StandardAnalyzer).
>
>
>
> The query used is:
>
> indexSearcher.search( query, 10 );
>
>
>
> Thank you,
>
>
>
> Tony Schwartz
>
>
>
>
>
>
--
Uwe Schindler
Achterdiek 19, D-28357 Bremen
https://www.thetaphi.de
eMail:uwe@thetaphi.de
RE: StandardQueryParser and numeric fields [ In reply to ]
Perfect! Thank you very much! Exactly what I needed, and simple!

Tony

-----Original Message-----
From: Uwe Schindler <uwe@thetaphi.de>
Sent: Tuesday, November 14, 2023 05:51
To: java-user@lucene.apache.org
Subject: Re: StandardQueryParser and numeric fields

Hi,

By default the standard query parser has no idea about field types (and it cannot because it does not know the schema of your index). If you want to allow searching in non-text fields (TextField, all other - also normal StringField breaks easy), you need to customize it.

There are 2 query parsers that I would call "standard":

* For the default / classic QueryParser the QueryParser#newXYQuery
methods need to be adapted (by subclassing) to generate a query
based on the text input. This is how Solr/Elasticsearch adapt their
schemas.
* For the flexible query parser (I think you mean that one with
StandardQueryParser), there is an option to use PointsConfig
instances and set a "per field" mapping how to parse points. Use
StandardQueryParser#setPointsConfigMap?() for that. Unfortunately
Javadocs is missing....

This is what Solr/Elasticsearch/Opensearch do.

Uwe

Am 14.11.2023 um 03:01 schrieb Tony Schwartz:
> Hello,
>
>
>
> I'm banging my head at this point, hoping someone can help me.
>
>
>
> I can't get StandardQueryParser to work on numeric fields. Luke
> v9.8.0 finds the records for me. Example search query string in Luke that works:
> eventIdNum:3001
>
>
>
> Here is my code:
>
>
>
> Query initQuery() {
>
> StandardQueryParser p = new StandardQueryParser( analyzer );
>
> p.setDefaultOperator( StandardQueryConfigHandler.Operator.AND );
>
> String queryString = "eventIdNum:3001";
>
> return p.parse( queryString, "any" );
>
> }
>
>
>
> here is how the field was added to the index:
>
> d.add( new IntField( "eventIdNum", 3001, Field.Store.NO ) );
>
>
>
> I've tried various analyzers. Example: new StandardAnalyzer(
> CharArraySet.EMPTY_SET );
>
>
>
>
>
> I'm sure there is something I'm missing here, but I can't seem to
> track down what I'm missing. The analyzer is the exact same analyzer
> I'm using during indexing. It's a PerFieldAnalyzerWrapper. The
> specific analyzer for the numeric fields is the one I mentioned above (StandardAnalyzer).
>
>
>
> The query used is:
>
> indexSearcher.search( query, 10 );
>
>
>
> Thank you,
>
>
>
> Tony Schwartz
>
>
>
>
>
>
--
Uwe Schindler
Achterdiek 19, D-28357 Bremen
https://www.thetaphi.de
eMail:uwe@thetaphi.de


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