[ 
https://issues.apache.org/jira/browse/LUCENE-4777?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

André  updated LUCENE-4777:
---------------------------

    Description: 
The method getRegexpQuery() in MultiFieldQueryParser is not overridden.
That leads to RegexpQueries where field=null (see example below).


{code}
QueryParser qp = new MultiFieldQueryParser(Version.LUCENE_41, new String[]{ 
"content" }, new StandardAnalyzer(Version.LUCENE_41)) 
Query q = qp.parse("path:foo/bar/foo"); // throws no ParseException
q.toString() // throws NPE
{code}

Workaround for MultiFieldQueryParser:

{code}
protected Query _getRegexpQuery(String field, String termStr) throws 
ParseException {
                                if (field == null) {
                      List<BooleanClause> clauses = new 
ArrayList<BooleanClause>();
                      for (int i = 0; i < fields.length; i++) {
                        clauses.add(new BooleanClause(getRegexpQuery(fields[i], 
termStr),
                            BooleanClause.Occur.SHOULD));
                      }
                      return getBooleanQuery(clauses, true);
                    }
                    return super.getRegexpQuery(field, termStr);
                  }
{code}

  was:
The method getRegexpQuery() in MultiFieldQueryParser is not overridden.
That leads to RegexpQueries where field=null (see example below).


{code}
QueryParser qp = new MultiFieldQueryParser(Version.LUCENE_41, new String[]{ 
"content" }, new StandardAnalyzer(Version.LUCENE_41)) 
Query q = qp.parse("path:foo/bar/foo"); // throws no ParseException
q.toString() // throws NPE
{code}

    
> NPE in MultiFieldQueryParser
> ----------------------------
>
>                 Key: LUCENE-4777
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4777
>             Project: Lucene - Core
>          Issue Type: Bug
>          Components: core/queryparser
>    Affects Versions: 4.1
>            Reporter: André 
>
> The method getRegexpQuery() in MultiFieldQueryParser is not overridden.
> That leads to RegexpQueries where field=null (see example below).
> {code}
> QueryParser qp = new MultiFieldQueryParser(Version.LUCENE_41, new String[]{ 
> "content" }, new StandardAnalyzer(Version.LUCENE_41)) 
> Query q = qp.parse("path:foo/bar/foo"); // throws no ParseException
> q.toString() // throws NPE
> {code}
> Workaround for MultiFieldQueryParser:
> {code}
> protected Query _getRegexpQuery(String field, String termStr) throws 
> ParseException {
>                               if (field == null) {
>                     List<BooleanClause> clauses = new 
> ArrayList<BooleanClause>();
>                     for (int i = 0; i < fields.length; i++) {
>                       clauses.add(new BooleanClause(getRegexpQuery(fields[i], 
> termStr),
>                           BooleanClause.Occur.SHOULD));
>                     }
>                     return getBooleanQuery(clauses, true);
>                   }
>                   return super.getRegexpQuery(field, termStr);
>                 }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to