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 Jeff Leedy <le...@vtls.com> on 2014/05/07 20:42:21 UTC

New equivalent to QueryParsing.parseQuery()?

I have some older code that works as expected in Solr 3.4:

            final IndexSchema indexSchema = new IndexSchema(
              new SolrConfig(solrHome +
"/repository","solrconfig.xml",null), "schema.xml", null);
            final Query luceneQuery = QueryParsing.parseQuery(
                  query, "text", indexSchema);
            luceneIndex.getIndexSearcher().search(luceneQuery, collector);

This appears to suck in all of the good stuff from the solrconfig.xml and
schema.xml, which is great. However, for Solr 4.0, I'm trying to find an
equivalent to QueryParsing.parseQuery() (which no longer exists) that lets
me incorporate these config files as before. I'm (naively?) trying the
following:

        final StandardQueryParser parser = new StandardQueryParser();
        final Query luceneQuery = parser.parse(query, "text");
        luceneIndex.getIndexSearcher().search(luceneQuery, collector);

However, the behavior of the StandardQueryParser seems to be different
enough to make some previously good queries fail, and I've not found a new
way to incorporate the xml config files. It seems silly to manually
reconstitute the relevant analyzers, filters, etc. from the schema in this
query code in my application. Is there a 4.0 equivalent to the older code
that works similarly, or are things more complicated?

Thanks in advance...

Jeff




--
View this message in context: http://lucene.472066.n3.nabble.com/New-equivalent-to-QueryParsing-parseQuery-tp4135050.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: New equivalent to QueryParsing.parseQuery()?

Posted by Chris Hostetter <ho...@fucit.org>.
: me incorporate these config files as before. I'm (naively?) trying the
: following:
: 
:         final StandardQueryParser parser = new StandardQueryParser();
:         final Query luceneQuery = parser.parse(query, "text");
:         luceneIndex.getIndexSearcher().search(luceneQuery, collector);
: 
: However, the behavior of the StandardQueryParser seems to be different
: enough to make some previously good queries fail, and I've not found a new

I don't think there's anything particular about StandardQueryParser that 
has changed that would make your queries fail -- however what you have 
there doens't refer to your schema at all, so that would obviously result 
in differences.

The main reason QueryParser.parseQuery went away is that it wasn't able to 
track any context of the request, so query time options for things like 
the default field were a pain to deal with -- no to mention doing parser 
overrides.

The closest corelary to what you were doing before is construct a 
LocalSolrQueryRequest and then pass that to QParser.getParser().

But if you are really just completley bypassing Solr, and constructing 
IndexSchema and SolrIndexConfig objects yourself -- you probably don't 
have a SolrCore object, which means that approach is probablematic.

Altenatively, you could try passing schema.getQueryAnalyzer() to your 
StandardQueryParser constructor -- that will give you all of the 
appropriate analyzers, but it won't help with some of the other FieldType 
specific features (like knowing when to build NumericRangeQueries for trie 
fields, when docValues are used, etc...)


Somewhere in between those two suggestions would be implementing 
SolrQueryRequest yourself with a a new mock object that gives access to 
the schema but just throws UnsupportedOperationExceptio for anything 
related to the SolrCore -- and then use that to directly construct a 
"LuceneQParser" instance and an org.apache.solr.parser.QueryParser 
instance.  (once you are that deep into the parsing logic, the only parsts 
of the SolrQueryRequest that hsould be consulted are the schema)


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