: req.getSchema().getQueryAnalyzer();
: 
: I think it's in this analyzer that the undefined field error happens
: (because for instance the field 'foo' doesn't exists in the schema,
: and so it's impossible to find a specific analyzer to this field in
: the schema).

Correct.

: The strange thing is that any QueryParser (Lucene API) is supposed to
: raise a ParseException if anything wrong happens with the parsing with
: the parse(String) method.
: 
: But here, it seems that the Analyzer from the schema (the one we get
: from getQueryAnalyzer()) is creating it's own error ( the undefined
: field one, instance of SolrException) and instead of propagating it to
: the QueryParser which could have a chance to propagate it as a
: standard ParseException, it seems it stops solr processing the query
: directly.

Solr isn't doing anything magical here -- it's just throwing a 
SolrException, which is a RuntimeExcepttion -- the Lucene 
QueryParser.parse method only throws a ParseException in th event of 
TooManyClauses, TokenMgrError, or an inner ParseException.

If you want to be able to pass an analyzer to your MyLuceneQueryParser that has 
some 
"default" behavior on unidentified fields, i would write your own that 
delegates to the one provided by Solr in teh default case...

  public class TolerantAnalyzer {
    final IndexSchema schema;
    public TolerantAnalyzer(IndexSchema s) { schema = s; }
    public TokenStream tokenStream(String fieldName, Reader reader) {
      if (null == schema.getFieldNoEx(fieldName) {
        // your custom behavior
      } else {
        return schema.getQueryAnalyzer().tokenStream(fieldName, reader);
      }
    }
    ...
  }


-Hoss

Reply via email to