You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Aaron Schon <aa...@yahoo.com> on 2010/02/17 19:44:44 UTC

Query about Query.ToString()

Hi all, I know that persisting a Lucene query by query ToString() method. Is there any way of reconstructing the query from the string itself?
The usecase is that I will be storing a library of queries as strings and load the appropriate query (from the string) based on some conditions.

Is this possible? Could you share a code snippet?

p.s. apologies for the double posting (I had asked this on Lucene general and was asked to ask here instead)



      

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Query about Query.ToString()

Posted by Jake Mannix <ja...@gmail.com>.
On Wed, Feb 17, 2010 at 10:55 AM, Erick Erickson <er...@gmail.com>wrote:

> Well, Query *does* implement the Serializable interface, so that
> might work. WARNING: I haven't personally used the Serializable
> interface on Query, so I have no real clue whether it's applicable!
>

Query is serializable (lots of people use raw java serialization for
Query),
but warning: no core Lucene Query subclasses
define serialversionUID, so while they will transmit over the wire
fine now, but both ends (server and client) need to be on the exact
same Lucene version.  This can cause headaches during Lucene
upgrades if you have an "always running" distributed system.

   -jake

RE: Query about Query.ToString()

Posted by "Goddard, Michael J." <MI...@saic.com>.
I recently had the same need, for a utility to get me from the Query toString() output back to the Java code to construct that specific query in Lucene.  The reason for my interest is that our query syntax differs significantly from the standard Lucene query syntax, so having something like this would be useful.

If I build it, I'll post it (but I'm currently doing this all by hand so I can post some questions to this list, so I probably won't).

  Mike


-----Original Message-----
From: java-user-return-45057-MICHAEL.J.GODDARD=saic.com@lucene.apache.org on behalf of Erick Erickson
Sent: Wed 2/17/2010 1:55 PM
To: java-user@lucene.apache.org
Subject: Re: Query about Query.ToString()
 
Well, Query *does* implement the Serializable interface, so that
might work. WARNING: I haven't personally used the Serializable
interface on Query, so I have no real clue whether it's applicable!

Taking the results of query.toString() and pumping it back through
the parser is not guaranteed to produce an equivalent query though.

But if you're creating a library of queries, why not just code up the
queries
as strings and store/reuse those?

I'd think about forming a query that I can send through the query parsing,
then storing that string for later reuse (i.e. the string you parsed). This
has
problems if you're constructing the query programatically (say assembling
a BooleanQuery in the lucene code) though.

not much help I know
Erick


On Wed, Feb 17, 2010 at 1:44 PM, Aaron Schon <aa...@yahoo.com> wrote:

> Hi all, I know that persisting a Lucene query by query ToString() method.
> Is there any way of reconstructing the query from the string itself?
> The usecase is that I will be storing a library of queries as strings and
> load the appropriate query (from the string) based on some conditions.
>
> Is this possible? Could you share a code snippet?
>
> p.s. apologies for the double posting (I had asked this on Lucene general
> and was asked to ask here instead)
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>



Re: Query about Query.ToString()

Posted by Erick Erickson <er...@gmail.com>.
Well, Query *does* implement the Serializable interface, so that
might work. WARNING: I haven't personally used the Serializable
interface on Query, so I have no real clue whether it's applicable!

Taking the results of query.toString() and pumping it back through
the parser is not guaranteed to produce an equivalent query though.

But if you're creating a library of queries, why not just code up the
queries
as strings and store/reuse those?

I'd think about forming a query that I can send through the query parsing,
then storing that string for later reuse (i.e. the string you parsed). This
has
problems if you're constructing the query programatically (say assembling
a BooleanQuery in the lucene code) though.

not much help I know
Erick


On Wed, Feb 17, 2010 at 1:44 PM, Aaron Schon <aa...@yahoo.com> wrote:

> Hi all, I know that persisting a Lucene query by query ToString() method.
> Is there any way of reconstructing the query from the string itself?
> The usecase is that I will be storing a library of queries as strings and
> load the appropriate query (from the string) based on some conditions.
>
> Is this possible? Could you share a code snippet?
>
> p.s. apologies for the double posting (I had asked this on Lucene general
> and was asked to ask here instead)
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Re: Query about Query.ToString()

Posted by Chris Lu <ch...@gmail.com>.
XMLQueryParser is pretty good start. However, is it being maintained 
recently?

I noticed many Query class are not supported, like PrefixQuery, or even 
PhraseQuery.
Is it for some particular reason or simply lack of resource?

--
Chris Lu
-------------------------
Instant Scalable Full-Text Search On Any Database/Application
site: http://www.dbsight.net
demo: http://search.dbsight.com
Lucene Database Search in 3 minutes: http://wiki.dbsight.com/index.php?title=Create_Lucene_Database_Search_in_3_minutes
DBSight customer, a shopping comparison site, (anonymous per request) got 2.6 Million Euro funding!


Mark Harwood wrote:
> This was part of the rationale for creating the XMLQueryParser which can be found in contrib.
>
> See here for the background: http://marc.info/?l=lucene-dev&m=113355526731460&w=2
>
>
> On 17 Feb 2010, at 18:44, Aaron Schon wrote:
>
>   
>> Hi all, I know that persisting a Lucene query by query ToString() method. Is there any way of reconstructing the query from the string itself?
>> The usecase is that I will be storing a library of queries as strings and load the appropriate query (from the string) based on some conditions.
>>
>> Is this possible? Could you share a code snippet?
>>
>> p.s. apologies for the double posting (I had asked this on Lucene general and was asked to ask here instead)
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>     
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>   

Re: Query about Query.ToString()

Posted by Mark Harwood <ma...@yahoo.co.uk>.
This was part of the rationale for creating the XMLQueryParser which can be found in contrib.

See here for the background: http://marc.info/?l=lucene-dev&m=113355526731460&w=2


On 17 Feb 2010, at 18:44, Aaron Schon wrote:

> Hi all, I know that persisting a Lucene query by query ToString() method. Is there any way of reconstructing the query from the string itself?
> The usecase is that I will be storing a library of queries as strings and load the appropriate query (from the string) based on some conditions.
> 
> Is this possible? Could you share a code snippet?
> 
> p.s. apologies for the double posting (I had asked this on Lucene general and was asked to ask here instead)
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org