constructing query from string

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

constructing query from string

prabin meitei
Hi ,
    I want to construct a query from string. how can I do it??  Actually i
saved a query(a boolean query) as string (using query.toString()).
Is there a way to reconstruct the query from the string i saved? How can i
add more clauses to the  reconstructed query?
Thanks in advance.

Prabin
Reply | Threaded
Open this post in threaded view
|

Changing the Score of a Document.

Benjamin Sznajder
Hi

I am sure that this topic has been once discusses on this forum, so, sorry
to ask again!

Let's suppose a Document d1 containing the five terms:
a
b
C
D


and a query (a AND b).

The document d1 is relevant and will be retrieved and typically, its score
will be a function tf*idf relative to the terms 'a' and 'b'.

I am interesting to score the document *not* according a and b, but
according the terms C and D.
How can we do that?

Thanks
Benjamin


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

Reply | Threaded
Open this post in threaded view
|

Re: constructing query from string

Erick Erickson
In reply to this post by prabin meitei
As I remember from various threads, toString is more of
a debugging aid and you cannot completely rely on the
transformation from a parsed query -> tostring -> parsed query
to be reliable. But this is "something I remember", so take
it with a grain of salt (you might want to search the mail
archive to see if my memory is correct).

That said, use BooleanQuery to add as many clauses in
as many ways as you want.

Actually, I don't know how I'd go about storing a programmatically
constructed query, I'd sure like to know if there's a way. You could
certainly store the original query if you were taking user input and
parsing it...

Best
Erick

On Jan 16, 2008 4:22 AM, prabin meitei <[hidden email]> wrote:

> Hi ,
>    I want to construct a query from string. how can I do it??  Actually i
> saved a query(a boolean query) as string (using query.toString()).
> Is there a way to reconstruct the query from the string i saved? How can i
> add more clauses to the  reconstructed query?
> Thanks in advance.
>
> Prabin
>
Reply | Threaded
Open this post in threaded view
|

Re: Changing the Score of a Document.

hossman
In reply to this post by Benjamin Sznajder

: In-Reply-To: <[hidden email]>
: Subject: Changing the Score of a Document.

http://people.apache.org/~hossman/#threadhijack
Thread Hijacking on Mailing Lists

When starting a new discussion on a mailing list, please do not reply to
an existing message, instead start a fresh email.  Even if you change the
subject line of your email, other mail headers still track which thread
you replied to and your question is "hidden" in that thread and gets less
attention.   It makes following discussions in the mailing list archives
particularly difficult.
See Also:  http://en.wikipedia.org/wiki/Thread_hijacking





-Hoss


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

Reply | Threaded
Open this post in threaded view
|

Re: constructing query from string

prabin meitei
In reply to this post by Erick Erickson
Hi Erick,
   Thanks for your response. I have tried the folowing way and seems to be
working. Tell me if there is any problem with the approach.

String str = query.toString();
QueryParser parser = new QueryParser("", new StandardAnalyzer);
Query newQuery = parser.parse(str);

now use *newQuery* for making queries


I understand that in the constructor of QueryParser it takes default field
and a analyzer. If I put a blank field it seems to work. Putting null gives
a null pointer exception.

Regards,
Prabin



On Jan 16, 2008 7:44 PM, Erick Erickson <[hidden email]> wrote:

> As I remember from various threads, toString is more of
> a debugging aid and you cannot completely rely on the
> transformation from a parsed query -> tostring -> parsed query
> to be reliable. But this is "something I remember", so take
> it with a grain of salt (you might want to search the mail
> archive to see if my memory is correct).
>
> That said, use BooleanQuery to add as many clauses in
> as many ways as you want.
>
> Actually, I don't know how I'd go about storing a programmatically
> constructed query, I'd sure like to know if there's a way. You could
> certainly store the original query if you were taking user input and
> parsing it...
>
> Best
> Erick
>
> On Jan 16, 2008 4:22 AM, prabin meitei <[hidden email]> wrote:
>
> > Hi ,
> >    I want to construct a query from string. how can I do it??  Actually
> i
> > saved a query(a boolean query) as string (using query.toString()).
> > Is there a way to reconstruct the query from the string i saved? How can
> i
> > add more clauses to the  reconstructed query?
> > Thanks in advance.
> >
> > Prabin
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: constructing query from string

Erick Erickson
I believe, but I'm not sure, that query and newQuery
are not guaranteed to be equivalent. So I'd be cautious
about this approach. But if it works for you....

I'm assuming that you're somehow programmatically
constructing the query and therefore can't just
store the original string. I'd *always* store the
original rather than a processed query if I could,
just on general principles.

What is it that you're trying to accomplish anyway?
Perhaps there's a better approach....

Erick

On Jan 17, 2008 6:07 AM, prabin meitei <[hidden email]> wrote:

> Hi Erick,
>   Thanks for your response. I have tried the folowing way and seems to be
> working. Tell me if there is any problem with the approach.
>
> String str = query.toString();
> QueryParser parser = new QueryParser("", new StandardAnalyzer);
> Query newQuery = parser.parse(str);
>
> now use *newQuery* for making queries
>
>
> I understand that in the constructor of QueryParser it takes default field
> and a analyzer. If I put a blank field it seems to work. Putting null
> gives
> a null pointer exception.
>
> Regards,
> Prabin
>
>
>
> On Jan 16, 2008 7:44 PM, Erick Erickson <[hidden email]> wrote:
>
> > As I remember from various threads, toString is more of
> > a debugging aid and you cannot completely rely on the
> > transformation from a parsed query -> tostring -> parsed query
> > to be reliable. But this is "something I remember", so take
> > it with a grain of salt (you might want to search the mail
> > archive to see if my memory is correct).
> >
> > That said, use BooleanQuery to add as many clauses in
> > as many ways as you want.
> >
> > Actually, I don't know how I'd go about storing a programmatically
> > constructed query, I'd sure like to know if there's a way. You could
> > certainly store the original query if you were taking user input and
> > parsing it...
> >
> > Best
> > Erick
> >
> > On Jan 16, 2008 4:22 AM, prabin meitei <[hidden email]> wrote:
> >
> > > Hi ,
> > >    I want to construct a query from string. how can I do it??
>  Actually
> > i
> > > saved a query(a boolean query) as string (using query.toString()).
> > > Is there a way to reconstruct the query from the string i saved? How
> can
> > i
> > > add more clauses to the  reconstructed query?
> > > Thanks in advance.
> > >
> > > Prabin
> > >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: constructing query from string

Erick Erickson
I just thought of an interesting test for whether
toString() is reasonable. You could log/flag
when the reloaded query differs. I.e.
String queryFromToString;  // your stored form
Query newQ = parser.parse(queryFromToString);
if (newQ.toString != queryFromToString) {
  log some stuff or throw an exception or....
}

That'd provide you a reality check...

Erick

On Jan 17, 2008 10:32 AM, Erick Erickson <[hidden email]> wrote:

> I believe, but I'm not sure, that query and newQuery
> are not guaranteed to be equivalent. So I'd be cautious
> about this approach. But if it works for you....
>
> I'm assuming that you're somehow programmatically
> constructing the query and therefore can't just
> store the original string. I'd *always* store the
> original rather than a processed query if I could,
> just on general principles.
>
> What is it that you're trying to accomplish anyway?
> Perhaps there's a better approach....
>
> Erick
>
>
> On Jan 17, 2008 6:07 AM, prabin meitei <[hidden email]> wrote:
>
> > Hi Erick,
> >   Thanks for your response. I have tried the folowing way and seems to
> > be
> > working. Tell me if there is any problem with the approach.
> >
> > String str = query.toString();
> > QueryParser parser = new QueryParser("", new StandardAnalyzer);
> > Query newQuery = parser.parse(str);
> >
> > now use *newQuery* for making queries
> >
> >
> > I understand that in the constructor of QueryParser it takes default
> > field
> > and a analyzer. If I put a blank field it seems to work. Putting null
> > gives
> > a null pointer exception.
> >
> > Regards,
> > Prabin
> >
> >
> >
> > On Jan 16, 2008 7:44 PM, Erick Erickson < [hidden email]>
> > wrote:
> >
> > > As I remember from various threads, toString is more of
> > > a debugging aid and you cannot completely rely on the
> > > transformation from a parsed query -> tostring -> parsed query
> > > to be reliable. But this is "something I remember", so take
> > > it with a grain of salt (you might want to search the mail
> > > archive to see if my memory is correct).
> > >
> > > That said, use BooleanQuery to add as many clauses in
> > > as many ways as you want.
> > >
> > > Actually, I don't know how I'd go about storing a programmatically
> > > constructed query, I'd sure like to know if there's a way. You could
> > > certainly store the original query if you were taking user input and
> > > parsing it...
> > >
> > > Best
> > > Erick
> > >
> > > On Jan 16, 2008 4:22 AM, prabin meitei <[hidden email]>
> > wrote:
> > >
> > > > Hi ,
> > > >    I want to construct a query from string. how can I do it??
> >  Actually
> > > i
> > > > saved a query(a boolean query) as string (using query.toString()).
> > > > Is there a way to reconstruct the query from the string i saved? How
> > can
> > > i
> > > > add more clauses to the  reconstructed query?
> > > > Thanks in advance.
> > > >
> > > > Prabin
> > > >
> > >
> >
>
>
Reply | Threaded
Open this post in threaded view
|

Re: constructing query from string

prabin meitei
For the query I am using *newQ.toString* equals *queryFrom.ToString

*well, what i am trying to accomplish is that I need to search an index
(quite often say interval of around 15 mins) and the query depends on other
activities done by the user till that point of a time. but i don't want the
query to be changed for a particular time period. (say 2 days)  i want to
store the query so that i can use it for my search without being affected by
current or immediate activities from user. once the query becomes 2 day old
then i'll reconstruct the query considering the activities happened during
the last two days.
  Is there a better approach?

On Jan 17, 2008 9:08 PM, Erick Erickson <[hidden email]> wrote:

> I just thought of an interesting test for whether
> toString() is reasonable. You could log/flag
> when the reloaded query differs. I.e.
> String queryFromToString;  // your stored form
> Query newQ = parser.parse(queryFromToString);
> if (newQ.toString != queryFromToString) {
>  log some stuff or throw an exception or....
> }
>
> That'd provide you a reality check...
>
> Erick
>
> On Jan 17, 2008 10:32 AM, Erick Erickson <[hidden email]> wrote:
>
> > I believe, but I'm not sure, that query and newQuery
> > are not guaranteed to be equivalent. So I'd be cautious
> > about this approach. But if it works for you....
> >
> > I'm assuming that you're somehow programmatically
> > constructing the query and therefore can't just
> > store the original string. I'd *always* store the
> > original rather than a processed query if I could,
> > just on general principles.
> >
> > What is it that you're trying to accomplish anyway?
> > Perhaps there's a better approach....
> >
> > Erick
> >
> >
> > On Jan 17, 2008 6:07 AM, prabin meitei <[hidden email]> wrote:
> >
> > > Hi Erick,
> > >   Thanks for your response. I have tried the folowing way and seems to
> > > be
> > > working. Tell me if there is any problem with the approach.
> > >
> > > String str = query.toString();
> > > QueryParser parser = new QueryParser("", new StandardAnalyzer);
> > > Query newQuery = parser.parse(str);
> > >
> > > now use *newQuery* for making queries
> > >
> > >
> > > I understand that in the constructor of QueryParser it takes default
> > > field
> > > and a analyzer. If I put a blank field it seems to work. Putting null
> > > gives
> > > a null pointer exception.
> > >
> > > Regards,
> > > Prabin
> > >
> > >
> > >
> > > On Jan 16, 2008 7:44 PM, Erick Erickson < [hidden email]>
> > > wrote:
> > >
> > > > As I remember from various threads, toString is more of
> > > > a debugging aid and you cannot completely rely on the
> > > > transformation from a parsed query -> tostring -> parsed query
> > > > to be reliable. But this is "something I remember", so take
> > > > it with a grain of salt (you might want to search the mail
> > > > archive to see if my memory is correct).
> > > >
> > > > That said, use BooleanQuery to add as many clauses in
> > > > as many ways as you want.
> > > >
> > > > Actually, I don't know how I'd go about storing a programmatically
> > > > constructed query, I'd sure like to know if there's a way. You could
> > > > certainly store the original query if you were taking user input and
> > > > parsing it...
> > > >
> > > > Best
> > > > Erick
> > > >
> > > > On Jan 16, 2008 4:22 AM, prabin meitei <[hidden email]>
> > > wrote:
> > > >
> > > > > Hi ,
> > > > >    I want to construct a query from string. how can I do it??
> > >  Actually
> > > > i
> > > > > saved a query(a boolean query) as string (using query.toString()).
> > > > > Is there a way to reconstruct the query from the string i saved?
> How
> > > can
> > > > i
> > > > > add more clauses to the  reconstructed query?
> > > > > Thanks in advance.
> > > > >
> > > > > Prabin
> > > > >
> > > >
> > >
> >
> >
>