lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luis Alves (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (LUCENE-1768) NumericRange support for new query parser
Date Fri, 07 Aug 2009 20:45:14 GMT

    [ https://issues.apache.org/jira/browse/LUCENE-1768?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12740718#action_12740718
] 

Luis Alves edited comment on LUCENE-1768 at 8/7/09 1:43 PM:
------------------------------------------------------------

{quote}
Neither is your version with rangeTypes.put("money", RangeUtils.getType(RangeUtils.NUMERIC...
That's the application specific configuration code and doesn't need (or want) to be committed.
{quote}
You are correct, I was describing the use case from the user perspective. 
That code was a example how to use the API's if we implement them in the future, those API's
are not currently available.

{quote}
Directly instantiating the query you want is simple, ultimately configurable, and avoids adding
a ton of unnecessary classes or methods that need to be kept in sync with everything that
a user may want to do.
{quote}

I'm not sure what to say here. So I'll point to the documentation that we currently have:
You can read https://issues.apache.org/jira/secure/attachment/12410046/QueryParser_restructure_meetup_june2009_v2.pdf
and the java docs  for 
package org.apache.lucene.queryParser.core 
class org.apache.lucene.queryParser.standard.StandardQueryParser

You can also look at TestSpanQueryParserSimpleSample junit for another example how the API's
can be used,
in a completely different way.

The new QueryParser was designed to be extensible,
allow the implementation of languages extensions or different languages,
and have reusable components like the processors and builders

We use SyntaxParsers, Processors and Builders, all are replaceable components at runtime.
Any user can build it's own pipeline and create new processors, builders, querynodes and integrate
them
with the existing ones to create the features they require. 

Some of the features are:
- Syntax Tree optimization
- Syntax Tree expansion
- Syntax Tree validation and error reporting
- Tokenization and normalization of the query
- Makes it easy to create extensions
- Support for translation of error messages
- Allows users to plug and play processors and builders, without having to modify lucene code.
- Allow lucene users to implement features much faster
- Allow users to change default behavior in a easy way without having to modify lucene code.

{quote}
Is there a simple way to provide a custom QueryBuilder for range queries (or any other query
type?) I'm sure there must be, but there are so many classes in the new QP, I'm having a little
difficulty finding my way around.
{quote}

Below is the java code for option 2. It's not the recomend way to use the new queryparser,
but is the shortest way to do what you want.

{code}
  class NumericQueryNodeBuilder extends RangeQueryNodeBuilder {
    public TermRangeQuery build(QueryNode queryNode) throws QueryNodeException {
    RangeQueryNode rangeNode = (RangeQueryNode) queryNode;
      
    if (rangeNode.getField().toString().equals("money")) {
      // do whatever you need here with queryNode.
      return new NumericRangeQuery(field,...)
    }
    else {
        return super.build(queryNode);
      }
    }
  }
  
  public void testNewRangeQueryBuilder() throws Exception {    
    StandardQueryParser qp = new StandardQueryParser();
    QueryTreeBuilder builder = (QueryTreeBuilder)qp.getQueryBuilder();
    builder.setBuilder(RangeQueryNode.class, new NumericQueryNodeBuilder());
    
    String startDate = getLocalizedDate(2002, 1, 1, false);
    String endDate = getLocalizedDate(2002, 1, 4, false);    
    
    StandardAnalyzer oneStopAnalyzer = new StandardAnalyzer();
    qp.setAnalyzer(oneStopAnalyzer);
    
    Query a = qp.parse("date:[" + startDate + " TO " + endDate + "]", null);
    System.out.print(a);
  }
{code}

      was (Author: lafa):
    {quote}
Neither is your version with rangeTypes.put("money", RangeUtils.getType(RangeUtils.NUMERIC...
That's the application specific configuration code and doesn't need (or want) to be committed.
{quote}
You are correct, I was describing the use case from the user perspective. 
That code was a example how to use the API's if we implement them in the future, those API's
are not currently available.

{quote}
Directly instantiating the query you want is simple, ultimately configurable, and avoids adding
a ton of unnecessary classes or methods that need to be kept in sync with everything that
a user may want to do.
{quote}

I'm not sure what to say here. So I'll point to the documentation that we currently have:
You can read https://issues.apache.org/jira/secure/attachment/12410046/QueryParser_restructure_meetup_june2009_v2.pdf
and the java docs  for 
package org.apache.lucene.queryParser.core 
class org.apache.lucene.queryParser.standard.StandardQueryParser

You can also look at TestSpanQueryParserSimpleSample junit for another example how the API's
can be used,
in a completely different way.

The new QueryParser was designed to be extensible,
allow the implementation of languages extensions or different languages,
and have reusable components like the processors and builders

We use SyntaxParsers, Processors and Builders, all are replaceable components at runtime.
Any user can build it's own pipeline and create new processors, builders, querynodes and integrate
them
with the existing ones to create the features they require. 

Some of the features are:
- Syntax Tree optimization
- Syntax Tree expansion
- Syntax Tree validation and error reporting
- Tokenization and normalization of the query
- Makes it easy to create extensions
- Support for translation of error messages
- Allows users to plug and play processors and builders, without having to modify lucene code.
- Allow lucene users to implement features much faster
- Allow users to change default behavior in a easy way without having to modify lucene code.

{quote}
Is there a simple way to provide a custom QueryBuilder for range queries (or any other query
type?) I'm sure there must be, but there are so many classes in the new QP, I'm having a little
difficulty finding my way around.
{quote}



{code}
  class NumericQueryNodeBuilder extends RangeQueryNodeBuilder {
    public TermRangeQuery build(QueryNode queryNode) throws QueryNodeException {
    RangeQueryNode rangeNode = (RangeQueryNode) queryNode;
      
    if (rangeNode.getField().toString().equals("money")) {
      // do whatever you need here with queryNode.
      return new NumericRangeQuery(field,...)
    }
    else {
        return super.build(queryNode);
      }
    }
  }
  
  public void testNewRangeQueryBuilder() throws Exception {    
    StandardQueryParser qp = new StandardQueryParser();
    QueryTreeBuilder builder = (QueryTreeBuilder)qp.getQueryBuilder();
    builder.setBuilder(RangeQueryNode.class, new NumericQueryNodeBuilder());
    
    String startDate = getLocalizedDate(2002, 1, 1, false);
    String endDate = getLocalizedDate(2002, 1, 4, false);    
    
    StandardAnalyzer oneStopAnalyzer = new StandardAnalyzer();
    qp.setAnalyzer(oneStopAnalyzer);
    
    Query a = qp.parse("date:[" + startDate + " TO " + endDate + "]", null);
    System.out.print(a);
  }
{code}
  
> NumericRange support for new query parser
> -----------------------------------------
>
>                 Key: LUCENE-1768
>                 URL: https://issues.apache.org/jira/browse/LUCENE-1768
>             Project: Lucene - Java
>          Issue Type: New Feature
>          Components: QueryParser
>    Affects Versions: 2.9
>            Reporter: Uwe Schindler
>            Assignee: Uwe Schindler
>             Fix For: 2.9
>
>
> It would be good to specify some type of "schema" for the query parser in future, to
automatically create NumericRangeQuery for different numeric types? It would then be possible
to index a numeric value (double,float,long,int) using NumericField and then the query parser
knows, which type of field this is and so it correctly creates a NumericRangeQuery for strings
like "[1.567..*]" or "(1.787..19.5]".
> There is currently no way to extract if a field is numeric from the index, so the user
will have to configure the FieldConfig objects in the ConfigHandler. But if this is done,
it will not be that difficult to implement the rest.
> The only difference between the current handling of RangeQuery is then the instantiation
of the correct Query type and conversion of the entered numeric values (simple Number.valueOf(...)
cast of the user entered numbers). Evenerything else is identical, NumericRangeQuery also
supports the MTQ rewrite modes (as it is a MTQ).
> Another thing is a change in Date semantics. There are some strange flags in the current
parser that tells it how to handle dates.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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


Mime
View raw message