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 mmastroianni <mm...@placester.com> on 2014/10/21 20:01:30 UTC

SolrJ and Lucene queries

I have an existing application using raw lucene that does some entity
extraction on a raw query and mixes in some other params to augment or
replace pieces of a large boolean query that it then constructs, which is a
mix of term queries, range queries, and recursiveprefixtree queries. 

I'm now switching (or at least trying to switch) to solr for the ease of nrt
indexing and the operational benefits, but am worried about how to do this
query processing. 

I could put it in as a plugin, which seems painful,  especially as I have
several different tokenizers and in general just a lot of code and
configuration that I would have to shoehorn into solr. Not the least of my
fears there may seem trivial but just consists of how I would mix together
all of the params coming from the client. 

Anyway, I was hoping that I could somehow use solrj to send the lucene query
straight through. This does not appear possible, and the last posts on this
board regarding this issue are several years old. Is there in general no
good way of serializing/deserializing lucene queries from solrj through to
solr? 

Is my best option to go down the plugin route?



--
View this message in context: http://lucene.472066.n3.nabble.com/SolrJ-and-Lucene-queries-tp4165233.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: SolrJ and Lucene queries

Posted by Ramzi Alqrainy <ra...@gmail.com>.
Yeah, it's a shame such a ser/deser feature isn't available in Lucene. 

My idea is to have a separate module that the Query classes can delegate to 
for serialization and deserialization, handling recursion for nested query 
objects, and then have modules for XML, JSON, and a pseudo-Java functional 
notation (maybe closer to JavaScript) for the actual formatting and parser. 
And then developers can subclass the module to add any custom Query classes 
of their own. 

A full JSON query ser/deser would be an especially nice addition to Solr, 
allowing direct access to all Lucene Query features even if they haven't 
been integrated into the higher level query parsers. 

And maybe the format should have a flag for whether terms have been analyzed 
or not. Then, deserialization could optionally do analysis as well. 

The Solr QueryParsing.toString method shows a purely external approach to 
serialization (I've done something similar myself.) This is what is output 
in the "parsedquery" section of debugQuery output for a Solr query response. 



--
View this message in context: http://lucene.472066.n3.nabble.com/SolrJ-and-Lucene-queries-tp4165233p4165290.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: SolrJ and Lucene queries

Posted by mmastroianni <mm...@placester.com>.
Thanks for the reply. 

The issue I have is trying to figure out how to either translate my large
programmatically generated lucene query to a string i can set as the q
parameter (which is non-trivial, since the toString methods on lucene
queries don't necessarily produce a parseable string), or generate it
myself. I'm particularly leery about the string representation of the
recursive tree geo query part of the query.

I was hoping there had been some facility for serializing prebuilt lucene
queries across the wire, but perhaps this is not the case and I am stuck
with either cobbling together a string to pass in or pushing my parser into
a plugin directly (not sure which way is better at present, any suggestions
would be great). 



--
View this message in context: http://lucene.472066.n3.nabble.com/SolrJ-and-Lucene-queries-tp4165233p4165247.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: SolrJ and Lucene queries

Posted by Ramzi Alqrainy <ra...@gmail.com>.
Use query() to have Solr search for results. You have to pass a SolrQuery
object that describes the query, and you will get back a QueryResponse (from
the org.apache.solr.client.solrj.response package).
SolrQuery has methods that make it easy to add parameters to choose a
request handler and send parameters to it. Here is a very simple example
that uses the default request handler and sets the q parameter:

<http://lucene.472066.n3.nabble.com/file/n4165239/1.png> 

To choose a different request handler, for example, just set the qt
parameter like this:

<http://lucene.472066.n3.nabble.com/file/n4165239/2.png> 

Once you have your SolrQuery set up, submit it with query():

<http://lucene.472066.n3.nabble.com/file/n4165239/3.png> 

The client makes a network connection and sends the query. Solr processes
the query, and the response is sent and parsed into a QueryResponse.
The QueryResponse is a collection of documents that satisfy the query
parameters. You can retrieve the documents directly with getResults() and
you can call other methods to find out information about highlighting or
facets.

<http://lucene.472066.n3.nabble.com/file/n4165239/4.png> 



--
View this message in context: http://lucene.472066.n3.nabble.com/SolrJ-and-Lucene-queries-tp4165233p4165239.html
Sent from the Solr - User mailing list archive at Nabble.com.