Mailing List Archive

Store a query in a database for later use
Hi,

I want to store a query for later use in a database, like:

1. queryToPersist = booleanQuery.toString();
2. store it to the db, go fishing, retrieve it
3. Query query = Query.parseString(queryToPersist)

The method Query.parseString does not exist. Is there a way to do something similar?
Re: Store a query in a database for later use [ In reply to ]
I think you want to have a look at the QueryParser classes. Not sure
which you're using to start with but probably the default QueryParser
should suffice.

On Thu, May 17, 2012 at 3:53 PM, Stefan Undorf <google@suncom.de> wrote:
> Hi,
>
> I want to store a query for later use in a database, like:
>
> 1. queryToPersist = booleanQuery.toString();
> 2. store it to the db, go fishing, retrieve it
> 3. Query query = Query.parseString(queryToPersist)
>
> The method Query.parseString does not exist. Is there a way to do something similar?
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Store a query in a database for later use [ In reply to ]
On Fri, May 18, 2012 at 6:23 AM, Jamie Johnson <jej2003@gmail.com> wrote:
> I think you want to have a look at the QueryParser classes.  Not sure
> which you're using to start with but probably the default QueryParser
> should suffice.

There are (at least) two catches though:

1. The semantics of a QueryParser might change over time. For
instance, today you might do "white b*" and it is a normal phrase
query. This could gets saved off and in a later version of Lucene, the
QueryParser is updated to parse it as a wildcard phrase query.

2. toString() doesn't always generate a query that the QueryParser can parse.

Lucene Query objects do implement Serializable though so they can be
serialised into a byte array. I do wonder how safe it is to do it
though (if I serialise one from a really early version is it expected
to serialise back in a much later version or does the Lucene backwards
compatibility policy not cover serialisation?)

TX

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Store a query in a database for later use [ In reply to ]
> 2. toString() doesn't always generate a query that the
> QueryParser can parse.

I remember similar discussion, I think Xml-Query-Parser is more suitable for this use case.

http://www.lucidimagination.com/blog/2009/02/22/exploring-query-parsers/


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