Ed:

Right, doing this in a custom query parser on the Solr end that subclasses 
edismax
is probably the way to go or similar.

Especially because String->parsed query->String, even without any changes in 
the parsing is _not_ guaranteed to give you the same string back. I’m not clear
on whether it gives back a string that would parse to the same query object, 
but…

Best,
Erick

> On Aug 17, 2020, at 4:51 PM, Edward Turner <eddtur...@gmail.com> wrote:
> 
> Hi Markus,
> 
> Many thanks, I see what you are saying. My question was:
> 
> Question: is it possible to get a Lucene Query representation of the
> client's query, which we can then navigate and manipulate -- before we then
> send the String representation of this Query to Solr for evaluation?
> 
> ... and from your answer, I think the last part of this question, "before
> we then send the String representation of this Query to Solr for
> evaluation" perhaps makes no sense when doing things in the proper Solr
> way. I had originally thought about doing this manipulation in, say, a REST
> application, before sending it to Solr, which I suppose isn't the way to do
> it.
> 
> Many thanks,
> 
> Edd
> --------------------
> Edward Turner
> 
> 
> On Mon, 17 Aug 2020 at 21:23, Markus Jelsma <markus.jel...@openindex.io>
> wrote:
> 
>> Hello Edward,
>> 
>> You asked for the 'Lucene Query representation of the client's query'
>> which is already inside Solr and needs no forwarding to anything. Just
>> return in parse() and you are good to go.
>> 
>> The Query object contains the analyzed form of your query string.
>> ExtendedDismax has some variable (i think it was qstr) that contains the
>> original input string. In there you have access to that too.
>> 
>> Regards,
>> Markus
>> 
>> 
>> -----Original message-----
>>> From:Edward Turner <eddtur...@gmail.com>
>>> Sent: Monday 17th August 2020 21:25
>>> To: solr-user@lucene.apache.org
>>> Subject: Re: Manipulating client's query using a Query object
>>> 
>>> Hi Markus,
>>> 
>>> That's really great info. Thank you.
>>> 
>>> Supposing we've now modified the Query object, do you know how we would
>> get
>>> the corresponding query String, which we could then forward to our
>>> Solrcloud via SolrClient?
>>> 
>>> (Or should we be using this extended ExtendedDisMaxQParser class server
>>> side in Solr?)
>>> 
>>> Kind regards,
>>> 
>>> Edd
>>> 
>>> --------------------
>>> Edward Turner
>>> 
>>> 
>>> On Mon, 17 Aug 2020 at 15:06, Markus Jelsma <markus.jel...@openindex.io>
>>> wrote:
>>> 
>>>> Hello Edward,
>>>> 
>>>> Yes you can by extending ExtendedDismaxQParser [1] and override its
>>>> parse() method. You get the main Query object through super.parse().
>>>> 
>>>> If you need even more fine grained control on how Query objects are
>>>> created you can extend ExtendedSolrQueryParser's [2] (inner class)
>>>> newFieldQuery() method.
>>>> 
>>>> Regards,
>>>> Markus
>>>> 
>>>> [1]
>>>> 
>> https://lucene.apache.org/solr/8_6_0/solr-core/org/apache/solr/search/ExtendedDismaxQParser.html
>>>> [2]
>>>> 
>> https://lucene.apache.org/solr/8_6_0/solr-core/org/apache/solr/search/ExtendedDismaxQParser.ExtendedSolrQueryParser.html
>>>> 
>>>> -----Original message-----
>>>>> From:Edward Turner <eddtur...@gmail.com>
>>>>> Sent: Monday 17th August 2020 15:53
>>>>> To: solr-user@lucene.apache.org
>>>>> Subject: Manipulating client's query using a Query object
>>>>> 
>>>>> Hi all,
>>>>> 
>>>>> Thanks for all your help recently. We're now using the edismax query
>>>> parser
>>>>> and are happy with its behaviour. We have another question which
>> maybe
>>>>> someone can help with.
>>>>> 
>>>>> We have one use case where we optimise our query before sending it to
>>>> Solr,
>>>>> and we do this by manipulating the client's input query string.
>> However,
>>>>> we're slightly uncomfortable using String manipulation to do this as
>>>>> there's always the possibility we parse their string wrongly. (We
>> have a
>>>>> large test suite to check if we're doing the right thing, but even
>> then,
>>>> we
>>>>> String manipulation doesn't feel right ...).
>>>>> 
>>>>> Question: is it possible to get a Lucene Query representation of the
>>>>> client's query, which we can then navigate and manipulate -- before
>> we
>>>> then
>>>>> send the String representation of this Query to Solr for evaluation?
>>>>> 
>>>>> Kind regards and thank you for your help in advance,
>>>>> 
>>>>> Edd
>>>>> 
>>>> 
>>> 
>> 

Reply via email to