Query about Query.ToString()

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Query about Query.ToString()

Aaron Schon
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Query about Query.ToString()

Erick Erickson
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 <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

RE: Query about Query.ToString()

Goddard, Michael J.
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=[hidden email] on behalf of Erick Erickson
Sent: Wed 2/17/2010 1:55 PM
To: [hidden email]
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 <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Query about Query.ToString()

Jake Mannix
In reply to this post by Erick Erickson
On Wed, Feb 17, 2010 at 10:55 AM, Erick Erickson <[hidden email]>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
Reply | Threaded
Open this post in threaded view
|

Re: Query about Query.ToString()

mark harwood
In reply to this post by Aaron Schon
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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Query about Query.ToString()

chrislusf
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: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>    
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: Query about Query.ToString()

mark harwood
In reply to this post by Aaron Schon
Yes it is being maintained and I have it in production on many large systems.
Phrase prefix wildcard etc can be supported using the "UserQuery" tag which hands off to the regular Lucene QueryParser. It would be easy to add XML tags for these types but these clauses tend to be provided by users anyway as part of free-text fields. The other XML syntax tends to be useful for capturing all the other structured input eg date ranges, checkboxes etc as filters or caches filters.
I intend to give it a 3.0 refresh to add geo etc soon
---------------------------------------

On 18 Feb 2010, at 02:12, Chris Lu <[hidden email]> wrote:

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: [hidden email]
For additional commands, e-mail: [hidden email]

   


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

 






---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Query about Query.ToString()

Uwe Schindler
Don't forget to add the new *RangeQuery classes! :-)

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: [hidden email]


> -----Original Message-----
> From: Mark Harwood [mailto:[hidden email]]
> Sent: Thursday, February 18, 2010 8:32 AM
> To: [hidden email]
> Subject: Re: Query about Query.ToString()
>
> Yes it is being maintained and I have it in production on many large
> systems.
> Phrase prefix wildcard etc can be supported using the "UserQuery" tag
> which hands off to the regular Lucene QueryParser. It would be easy to
> add XML tags for these types but these clauses tend to be provided by
> users anyway as part of free-text fields. The other XML syntax tends to
> be useful for capturing all the other structured input eg date ranges,
> checkboxes etc as filters or caches filters.
> I intend to give it a 3.0 refresh to add geo etc soon
> ---------------------------------------
>
> On 18 Feb 2010, at 02:12, Chris Lu <[hidden email]> wrote:
>
> 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_i
> n_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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Query about Query.ToString()

chrislusf
In reply to this post by mark harwood
It's great that this is supported. I have 3 questions:

1) XML query parser just focuses on the "difficult" queries, left the
"simple" ones to the standard query parser.
I think it'll be good to support all of the queries. Makes it easier to
implement, rather than combine two different parser together.
2) Another side point is the lack of examples in the Javadoc. Currently
I need to dig into the unit test part to find some examples.
3) Can this be "standardized" into Lucene trunk? Is it possible to
support other serialization forms, like google protocol buffer?
Hopefully I only need to serialize it via query.toXML() or
query.toBytes()  and the parser can recognize the serialized forms.

--
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:

> Yes it is being maintained and I have it in production on many large systems.
> Phrase prefix wildcard etc can be supported using the "UserQuery" tag which hands off to the regular Lucene QueryParser. It would be easy to add XML tags for these types but these clauses tend to be provided by users anyway as part of free-text fields. The other XML syntax tends to be useful for capturing all the other structured input eg date ranges, checkboxes etc as filters or caches filters.
> I intend to give it a 3.0 refresh to add geo etc soon
> ---------------------------------------
>
> On 18 Feb 2010, at 02:12, Chris Lu <[hidden email]> wrote:
>
> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>    
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  
>
>
>
>      
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Query about Query.ToString()

mark harwood

> I have 3 questions:
>
> 1) XML query parser just focuses on the "difficult" queries, left the "simple" ones to the standard query parser.
> I think it'll be good to support all of the queries. Makes it easier to implement, rather than combine two different parser together.

"Lucene in Action 2" contains a section on XML query parser with an example that is typical of its use. An HTML form for a job search is mapped to an XML query via XSL. The free-text field for a job description accepts standard Lucene query syntax and gets mapped to a <UserQuery> tag - the other form content is all structured e.g date ranges, salary bands, contract/permanent choices and location choices - these all get mapped to  specialised tags in the XML. Phrase, Wildcard etc are happily handled by the UserQuery tag and it makes perfect sense for these elements to mix in the same XML. I could easily add Phrase, wildcard etc as explicit XML tags but there's not a great deal of demand for that so far and it may give people the wrong ideas.


> 2) Another side point is the lack of examples in the Javadoc. Currently I need to dig into the unit test part to find some examples.

In the source distro the contrib/xml-query-parser/docs directory has extensive docs with examples. These are generated from comments held in a formal DTD


> 3) Can this be "standardized" into Lucene trunk? Is it possible to support other serialization forms, like google protocol buffer? Hopefully I only need to serialize it via query.toXML() or query.toBytes()  and the parser can recognize the serialized forms.


I'm not sure about requiring query objects to serialize to XML or putting in trunk. It seems like a bit of a burden to place on core code for all query objects. It also enforces a single XML representation whereas the parser has been designed to support multiple new tags easily e.g. you can plug in simple tag handlers for tags like <All> ...</All> or <Any>....</Any> if you wanted a simplified form of expressing Boolean logic containers in the XML.


Cheers
Mark




>
> --
> 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:
>> Yes it is being maintained and I have it in production on many large systems. Phrase prefix wildcard etc can be supported using the "UserQuery" tag which hands off to the regular Lucene QueryParser. It would be easy to add XML tags for these types but these clauses tend to be provided by users anyway as part of free-text fields. The other XML syntax tends to be useful for capturing all the other structured input eg date ranges, checkboxes etc as filters or caches filters. I intend to give it a 3.0 refresh to add geo etc soon
>> ---------------------------------------
>>
>> On 18 Feb 2010, at 02:12, Chris Lu <[hidden email]> wrote:
>>
>> 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: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>  
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>
>>
>>      
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>  
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]