You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Raghuveer Kancherla <ra...@aplopio.com> on 2009/12/10 11:17:56 UTC

Payloads with Phrase queries

Hi,
I am looking for a way to use payloads in my search application. Indexing
data with payloads into Solr is pretty straightforward. However using the
payloads during search time is a bit confusing. Can anyone point me in the
right direction to enable payloads on a *PhraseQuery*. I looked at the
following resources and got payload on a TermQuery working.

   1.
   http://www.lucidimagination.com/blog/2009/08/05/getting-started-with-payloads/
   2. http://www.mail-archive.com/solr-user@lucene.apache.org/msg24863.html
   3. There is also a jira issue (SOLR-1485) that gives a patch for using
   Payload.
   4. Lucene-In-Action

I am guessing that I should return a payload version of PhraseQuery in
QueryParser's (package org.apache.lucene.queryParser.queryParser.java)
newPhraseQuery function. If yes, what type should this query be?

Thanks,
Raghu

Re: Payloads with Phrase queries

Posted by Bill Au <bi...@gmail.com>.
Lucene 2.9.1 comes with a PayloadTermQuery:
http://lucene.apache.org/java/2_9_1/api/all/org/apache/lucene/search/payloads/PayloadTermQuery.html

I have been using that to use the payload as part of the score without any
problem.

Bill


On Tue, Dec 15, 2009 at 6:31 AM, Raghuveer Kancherla <
raghuveer.kancherla@aplopio.com> wrote:

> The interesting thing I am noticing is that the scoring works fine for a
> phrase query like "solr rocks".
> This lead me to look at what query I am using in case of a single term.
> Turns out that I am using PayloadTermQuery taking a cue from solr-1485
> patch.
>
> I changed this to BoostingTermQuery (i read somewhere that this is
> deprecated .. but i was just experimenting) and the scoring seems to work
> as
> expected now for a single term.
>
> Now, the important question is what is the Payload version of a TermQuery?
>
> Regards
> Raghu
>
>
> On Tue, Dec 15, 2009 at 12:45 PM, Raghuveer Kancherla <
> raghuveer.kancherla@aplopio.com> wrote:
>
> > Hi,
> > Thanks everyone for the responses, I am now able to get both phrase
> queries
> > and term queries to use payloads.
> >
> > However the the score value for each document (and consequently, the
> > ordering of documents) are coming out wrong.
> >
> > In the solr output appended below, document 4 has a score higher than the
> > document 2 (look at the debug part). The results section shows a wrong
> score
> > (which is the payload value I am returning from my custom similarity
> class)
> > and the ordering is also wrong because of this. Can someone explain this
> ?
> >
> > My custom query parser is pasted here http://pastebin.com/m9f21565
> >
> > In the similarity class, I return 10.0 if payload is 1 and 20.0 if
> payload
> > is 2. For everything else I return 1.0.
> >
> > {
> >  'responseHeader':{
> >   'status':0,
> >   'QTime':2,
> >   'params':{
> >       'fl':'*,score',
> >       'debugQuery':'on',
> >       'indent':'on',
> >
> >
> >       'start':'0',
> >       'q':'solr',
> >       'qt':'aplopio',
> >       'wt':'python',
> >       'fq':'',
> >       'rows':'10'}},
> >  'response':{'numFound':5,'start':0,'maxScore':20.0,'docs':[
> >
> >
> >       {
> >        'payloadTest':'solr|2 rocks|1',
> >        'id':'2',
> >        'score':20.0},
> >       {
> >        'payloadTest':'solr|2',
> >        'id':'4',
> >        'score':20.0},
> >
> >
> >       {
> >        'payloadTest':'solr|1 rocks|2',
> >        'id':'1',
> >        'score':10.0},
> >       {
> >        'payloadTest':'solr|1 rocks|1',
> >        'id':'3',
> >        'score':10.0},
> >
> >
> >       {
> >        'payloadTest':'solr',
> >        'id':'5',
> >        'score':1.0}]
> >  },
> >  'debug':{
> >   'rawquerystring':'solr',
> >   'querystring':'solr',
> >
> >
> >   'parsedquery':'PayloadTermQuery(payloadTest:solr)',
> >   'parsedquery_toString':'payloadTest:solr',
> >   'explain':{
> >       '2':'\n7.227325 = (MATCH) fieldWeight(payloadTest:solr in 1),
> product of:\n  14.142136 = (MATCH) btq, product of:\n    0.70710677 =
> tf(phraseFreq=0.5)\n    20.0 = scorePayload(...)\n  0.81767845 =
> idf(payloadTest:  solr=5)\n  0.625 = fieldNorm(field=payloadTest, doc=1)\n',
> >
> >
> >       '4':'\n11.56372 = (MATCH) fieldWeight(payloadTest:solr in 3),
> product of:\n  14.142136 = (MATCH) btq, product of:\n    0.70710677 =
> tf(phraseFreq=0.5)\n    20.0 = scorePayload(...)\n  0.81767845 =
> idf(payloadTest:  solr=5)\n  1.0 = fieldNorm(field=payloadTest, doc=3)\n',
> >
> >
> >       '1':'\n3.6136625 = (MATCH) fieldWeight(payloadTest:solr in 0),
> product of:\n  7.071068 = (MATCH) btq, product of:\n    0.70710677 =
> tf(phraseFreq=0.5)\n    10.0 = scorePayload(...)\n  0.81767845 =
> idf(payloadTest:  solr=5)\n  0.625 = fieldNorm(field=payloadTest, doc=0)\n',
> >
> >
> >       '3':'\n3.6136625 = (MATCH) fieldWeight(payloadTest:solr in 2),
> product of:\n  7.071068 = (MATCH) btq, product of:\n    0.70710677 =
> tf(phraseFreq=0.5)\n    10.0 = scorePayload(...)\n  0.81767845 =
> idf(payloadTest:  solr=5)\n  0.625 = fieldNorm(field=payloadTest, doc=2)\n',
> >
> >
> >       '5':'\n0.578186 = (MATCH) fieldWeight(payloadTest:solr in 4),
> product of:\n  0.70710677 = (MATCH) btq, product of:\n    0.70710677 =
> tf(phraseFreq=0.5)\n    1.0 = scorePayload(...)\n  0.81767845 =
> idf(payloadTest:  solr=5)\n  1.0 = fieldNorm(field=payloadTest, doc=4)\n'},
> >
> >
> >   'QParser':'BoostingTermQParser',
> >   'filter_queries':[''],
> >   'parsed_filter_queries':[],
> >   'timing':{
> >       'time':2.0,
> >       'prepare':{
> >        'time':1.0,
> >
> >
> >        'org.apache.solr.handler.component.QueryComponent':{
> >         'time':1.0},
> >        'org.apache.solr.handler.component.FacetComponent':{
> >         'time':0.0},
> >        'org.apache.solr.handler.component.MoreLikeThisComponent':{
> >
> >
> >         'time':0.0},
> >        'org.apache.solr.handler.component.HighlightComponent':{
> >         'time':0.0},
> >        'org.apache.solr.handler.component.StatsComponent':{
> >         'time':0.0},
> >        'org.apache.solr.handler.component.DebugComponent':{
> >
> >
> >         'time':0.0}},
> >       'process':{
> >        'time':1.0,
> >        'org.apache.solr.handler.component.QueryComponent':{
> >         'time':0.0},
> >        'org.apache.solr.handler.component.FacetComponent':{
> >
> >
> >         'time':0.0},
> >        'org.apache.solr.handler.component.MoreLikeThisComponent':{
> >         'time':0.0},
> >        'org.apache.solr.handler.component.HighlightComponent':{
> >         'time':0.0},
> >
> >
> >        'org.apache.solr.handler.component.StatsComponent':{
> >         'time':0.0},
> >        'org.apache.solr.handler.component.DebugComponent':{
> >         'time':1.0}}}}}
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Thu, Dec 10, 2009 at 5:48 PM, AHMET ARSLAN <io...@yahoo.com> wrote:
> >
> >>
> >> > I was looking through some lucene
> >> > source codes and found the following class
> >> > org.apache.lucene.search.payloads.PayloadSpanUtil
> >> >
> >> > There is a function named queryToSpanQuery in this class.
> >> > Is this the
> >> > preferred way to convert a PhraseQuery to
> >> > PayloadNearQuery?
> >>
> >> queryToSpanQuery method does not return PayloadNearQuery type.
> >>
> >> You need to override getFieldQuery(String field, String queryText, int
> >> slop) of SolrQueryParser or QueryParser.
> >>
> >> This code is modified from Lucene In Action Book (2nd edition) Chapter
> >> 6.3.4 Allowing ordered phrase queries
> >>
> >> protected Query getFieldQuery(String field, String queryText, int slop)
> >> throws ParseException {
> >>
> >>        Query orig = super.getFieldQuery(field, queryText, slop);
> >>
> >>        if (!(orig instanceof PhraseQuery)) return orig;
> >>
> >>        PhraseQuery pq = (PhraseQuery) orig;
> >>        Term[] terms = pq.getTerms();
> >>        SpanQuery[] clauses = new SpanQuery[terms.length];
> >>
> >>        for (int i = 0; i < terms.length; i++)
> >>            clauses[i] = new PayloadTermQuery(terms[i], new
> >> AveragePayloadFunction());
> >>        return new PayloadNearQuery(clauses, slop, true);
> >>
> >>    }
> >>
> >>
> >> > Also, are there any performance considerations while using
> >> > a PayloadNearQuery instead of a PhraseQuery?
> >>
> >> I don't think there will be significant performance difference.
> >>
> >>
> >>
> >>
> >
>

Re: Payloads with Phrase queries

Posted by Raghuveer Kancherla <ra...@aplopio.com>.
The interesting thing I am noticing is that the scoring works fine for a
phrase query like "solr rocks".
This lead me to look at what query I am using in case of a single term.
Turns out that I am using PayloadTermQuery taking a cue from solr-1485
patch.

I changed this to BoostingTermQuery (i read somewhere that this is
deprecated .. but i was just experimenting) and the scoring seems to work as
expected now for a single term.

Now, the important question is what is the Payload version of a TermQuery?

Regards
Raghu


On Tue, Dec 15, 2009 at 12:45 PM, Raghuveer Kancherla <
raghuveer.kancherla@aplopio.com> wrote:

> Hi,
> Thanks everyone for the responses, I am now able to get both phrase queries
> and term queries to use payloads.
>
> However the the score value for each document (and consequently, the
> ordering of documents) are coming out wrong.
>
> In the solr output appended below, document 4 has a score higher than the
> document 2 (look at the debug part). The results section shows a wrong score
> (which is the payload value I am returning from my custom similarity class)
> and the ordering is also wrong because of this. Can someone explain this ?
>
> My custom query parser is pasted here http://pastebin.com/m9f21565
>
> In the similarity class, I return 10.0 if payload is 1 and 20.0 if payload
> is 2. For everything else I return 1.0.
>
> {
>  'responseHeader':{
>   'status':0,
>   'QTime':2,
>   'params':{
> 	'fl':'*,score',
> 	'debugQuery':'on',
> 	'indent':'on',
>
>
> 	'start':'0',
> 	'q':'solr',
> 	'qt':'aplopio',
> 	'wt':'python',
> 	'fq':'',
> 	'rows':'10'}},
>  'response':{'numFound':5,'start':0,'maxScore':20.0,'docs':[
>
>
> 	{
> 	 'payloadTest':'solr|2 rocks|1',
> 	 'id':'2',
> 	 'score':20.0},
> 	{
> 	 'payloadTest':'solr|2',
> 	 'id':'4',
> 	 'score':20.0},
>
>
> 	{
> 	 'payloadTest':'solr|1 rocks|2',
> 	 'id':'1',
> 	 'score':10.0},
> 	{
> 	 'payloadTest':'solr|1 rocks|1',
> 	 'id':'3',
> 	 'score':10.0},
>
>
> 	{
> 	 'payloadTest':'solr',
> 	 'id':'5',
> 	 'score':1.0}]
>  },
>  'debug':{
>   'rawquerystring':'solr',
>   'querystring':'solr',
>
>
>   'parsedquery':'PayloadTermQuery(payloadTest:solr)',
>   'parsedquery_toString':'payloadTest:solr',
>   'explain':{
> 	'2':'\n7.227325 = (MATCH) fieldWeight(payloadTest:solr in 1), product of:\n  14.142136 = (MATCH) btq, product of:\n    0.70710677 = tf(phraseFreq=0.5)\n    20.0 = scorePayload(...)\n  0.81767845 = idf(payloadTest:  solr=5)\n  0.625 = fieldNorm(field=payloadTest, doc=1)\n',
>
>
> 	'4':'\n11.56372 = (MATCH) fieldWeight(payloadTest:solr in 3), product of:\n  14.142136 = (MATCH) btq, product of:\n    0.70710677 = tf(phraseFreq=0.5)\n    20.0 = scorePayload(...)\n  0.81767845 = idf(payloadTest:  solr=5)\n  1.0 = fieldNorm(field=payloadTest, doc=3)\n',
>
>
> 	'1':'\n3.6136625 = (MATCH) fieldWeight(payloadTest:solr in 0), product of:\n  7.071068 = (MATCH) btq, product of:\n    0.70710677 = tf(phraseFreq=0.5)\n    10.0 = scorePayload(...)\n  0.81767845 = idf(payloadTest:  solr=5)\n  0.625 = fieldNorm(field=payloadTest, doc=0)\n',
>
>
> 	'3':'\n3.6136625 = (MATCH) fieldWeight(payloadTest:solr in 2), product of:\n  7.071068 = (MATCH) btq, product of:\n    0.70710677 = tf(phraseFreq=0.5)\n    10.0 = scorePayload(...)\n  0.81767845 = idf(payloadTest:  solr=5)\n  0.625 = fieldNorm(field=payloadTest, doc=2)\n',
>
>
> 	'5':'\n0.578186 = (MATCH) fieldWeight(payloadTest:solr in 4), product of:\n  0.70710677 = (MATCH) btq, product of:\n    0.70710677 = tf(phraseFreq=0.5)\n    1.0 = scorePayload(...)\n  0.81767845 = idf(payloadTest:  solr=5)\n  1.0 = fieldNorm(field=payloadTest, doc=4)\n'},
>
>
>   'QParser':'BoostingTermQParser',
>   'filter_queries':[''],
>   'parsed_filter_queries':[],
>   'timing':{
> 	'time':2.0,
> 	'prepare':{
> 	 'time':1.0,
>
>
> 	 'org.apache.solr.handler.component.QueryComponent':{
> 	  'time':1.0},
> 	 'org.apache.solr.handler.component.FacetComponent':{
> 	  'time':0.0},
> 	 'org.apache.solr.handler.component.MoreLikeThisComponent':{
>
>
> 	  'time':0.0},
> 	 'org.apache.solr.handler.component.HighlightComponent':{
> 	  'time':0.0},
> 	 'org.apache.solr.handler.component.StatsComponent':{
> 	  'time':0.0},
> 	 'org.apache.solr.handler.component.DebugComponent':{
>
>
> 	  'time':0.0}},
> 	'process':{
> 	 'time':1.0,
> 	 'org.apache.solr.handler.component.QueryComponent':{
> 	  'time':0.0},
> 	 'org.apache.solr.handler.component.FacetComponent':{
>
>
> 	  'time':0.0},
> 	 'org.apache.solr.handler.component.MoreLikeThisComponent':{
> 	  'time':0.0},
> 	 'org.apache.solr.handler.component.HighlightComponent':{
> 	  'time':0.0},
>
>
> 	 'org.apache.solr.handler.component.StatsComponent':{
> 	  'time':0.0},
> 	 'org.apache.solr.handler.component.DebugComponent':{
> 	  'time':1.0}}}}}
>
>
>
>
>
>
>
>
>
>
>
>
> On Thu, Dec 10, 2009 at 5:48 PM, AHMET ARSLAN <io...@yahoo.com> wrote:
>
>>
>> > I was looking through some lucene
>> > source codes and found the following class
>> > org.apache.lucene.search.payloads.PayloadSpanUtil
>> >
>> > There is a function named queryToSpanQuery in this class.
>> > Is this the
>> > preferred way to convert a PhraseQuery to
>> > PayloadNearQuery?
>>
>> queryToSpanQuery method does not return PayloadNearQuery type.
>>
>> You need to override getFieldQuery(String field, String queryText, int
>> slop) of SolrQueryParser or QueryParser.
>>
>> This code is modified from Lucene In Action Book (2nd edition) Chapter
>> 6.3.4 Allowing ordered phrase queries
>>
>> protected Query getFieldQuery(String field, String queryText, int slop)
>> throws ParseException {
>>
>>        Query orig = super.getFieldQuery(field, queryText, slop);
>>
>>        if (!(orig instanceof PhraseQuery)) return orig;
>>
>>        PhraseQuery pq = (PhraseQuery) orig;
>>        Term[] terms = pq.getTerms();
>>        SpanQuery[] clauses = new SpanQuery[terms.length];
>>
>>        for (int i = 0; i < terms.length; i++)
>>            clauses[i] = new PayloadTermQuery(terms[i], new
>> AveragePayloadFunction());
>>        return new PayloadNearQuery(clauses, slop, true);
>>
>>    }
>>
>>
>> > Also, are there any performance considerations while using
>> > a PayloadNearQuery instead of a PhraseQuery?
>>
>> I don't think there will be significant performance difference.
>>
>>
>>
>>
>

Re: Payloads with Phrase queries

Posted by Raghuveer Kancherla <ra...@aplopio.com>.
Hi,
Thanks everyone for the responses, I am now able to get both phrase queries
and term queries to use payloads.

However the the score value for each document (and consequently, the
ordering of documents) are coming out wrong.

In the solr output appended below, document 4 has a score higher than the
document 2 (look at the debug part). The results section shows a wrong score
(which is the payload value I am returning from my custom similarity class)
and the ordering is also wrong because of this. Can someone explain this ?

My custom query parser is pasted here http://pastebin.com/m9f21565

In the similarity class, I return 10.0 if payload is 1 and 20.0 if payload
is 2. For everything else I return 1.0.

{
 'responseHeader':{
  'status':0,
  'QTime':2,
  'params':{
	'fl':'*,score',
	'debugQuery':'on',
	'indent':'on',

	'start':'0',
	'q':'solr',
	'qt':'aplopio',
	'wt':'python',
	'fq':'',
	'rows':'10'}},
 'response':{'numFound':5,'start':0,'maxScore':20.0,'docs':[

	{
	 'payloadTest':'solr|2 rocks|1',
	 'id':'2',
	 'score':20.0},
	{
	 'payloadTest':'solr|2',
	 'id':'4',
	 'score':20.0},

	{
	 'payloadTest':'solr|1 rocks|2',
	 'id':'1',
	 'score':10.0},
	{
	 'payloadTest':'solr|1 rocks|1',
	 'id':'3',
	 'score':10.0},

	{
	 'payloadTest':'solr',
	 'id':'5',
	 'score':1.0}]
 },
 'debug':{
  'rawquerystring':'solr',
  'querystring':'solr',

  'parsedquery':'PayloadTermQuery(payloadTest:solr)',
  'parsedquery_toString':'payloadTest:solr',
  'explain':{
	'2':'\n7.227325 = (MATCH) fieldWeight(payloadTest:solr in 1), product
of:\n  14.142136 = (MATCH) btq, product of:\n    0.70710677 =
tf(phraseFreq=0.5)\n    20.0 = scorePayload(...)\n  0.81767845 =
idf(payloadTest:  solr=5)\n  0.625 = fieldNorm(field=payloadTest,
doc=1)\n',

	'4':'\n11.56372 = (MATCH) fieldWeight(payloadTest:solr in 3), product
of:\n  14.142136 = (MATCH) btq, product of:\n    0.70710677 =
tf(phraseFreq=0.5)\n    20.0 = scorePayload(...)\n  0.81767845 =
idf(payloadTest:  solr=5)\n  1.0 = fieldNorm(field=payloadTest,
doc=3)\n',

	'1':'\n3.6136625 = (MATCH) fieldWeight(payloadTest:solr in 0),
product of:\n  7.071068 = (MATCH) btq, product of:\n    0.70710677 =
tf(phraseFreq=0.5)\n    10.0 = scorePayload(...)\n  0.81767845 =
idf(payloadTest:  solr=5)\n  0.625 = fieldNorm(field=payloadTest,
doc=0)\n',

	'3':'\n3.6136625 = (MATCH) fieldWeight(payloadTest:solr in 2),
product of:\n  7.071068 = (MATCH) btq, product of:\n    0.70710677 =
tf(phraseFreq=0.5)\n    10.0 = scorePayload(...)\n  0.81767845 =
idf(payloadTest:  solr=5)\n  0.625 = fieldNorm(field=payloadTest,
doc=2)\n',

	'5':'\n0.578186 = (MATCH) fieldWeight(payloadTest:solr in 4), product
of:\n  0.70710677 = (MATCH) btq, product of:\n    0.70710677 =
tf(phraseFreq=0.5)\n    1.0 = scorePayload(...)\n  0.81767845 =
idf(payloadTest:  solr=5)\n  1.0 = fieldNorm(field=payloadTest,
doc=4)\n'},

  'QParser':'BoostingTermQParser',
  'filter_queries':[''],
  'parsed_filter_queries':[],
  'timing':{
	'time':2.0,
	'prepare':{
	 'time':1.0,

	 'org.apache.solr.handler.component.QueryComponent':{
	  'time':1.0},
	 'org.apache.solr.handler.component.FacetComponent':{
	  'time':0.0},
	 'org.apache.solr.handler.component.MoreLikeThisComponent':{

	  'time':0.0},
	 'org.apache.solr.handler.component.HighlightComponent':{
	  'time':0.0},
	 'org.apache.solr.handler.component.StatsComponent':{
	  'time':0.0},
	 'org.apache.solr.handler.component.DebugComponent':{

	  'time':0.0}},
	'process':{
	 'time':1.0,
	 'org.apache.solr.handler.component.QueryComponent':{
	  'time':0.0},
	 'org.apache.solr.handler.component.FacetComponent':{

	  'time':0.0},
	 'org.apache.solr.handler.component.MoreLikeThisComponent':{
	  'time':0.0},
	 'org.apache.solr.handler.component.HighlightComponent':{
	  'time':0.0},

	 'org.apache.solr.handler.component.StatsComponent':{
	  'time':0.0},
	 'org.apache.solr.handler.component.DebugComponent':{
	  'time':1.0}}}}}












On Thu, Dec 10, 2009 at 5:48 PM, AHMET ARSLAN <io...@yahoo.com> wrote:

>
> > I was looking through some lucene
> > source codes and found the following class
> > org.apache.lucene.search.payloads.PayloadSpanUtil
> >
> > There is a function named queryToSpanQuery in this class.
> > Is this the
> > preferred way to convert a PhraseQuery to
> > PayloadNearQuery?
>
> queryToSpanQuery method does not return PayloadNearQuery type.
>
> You need to override getFieldQuery(String field, String queryText, int
> slop) of SolrQueryParser or QueryParser.
>
> This code is modified from Lucene In Action Book (2nd edition) Chapter
> 6.3.4 Allowing ordered phrase queries
>
> protected Query getFieldQuery(String field, String queryText, int slop)
> throws ParseException {
>
>        Query orig = super.getFieldQuery(field, queryText, slop);
>
>        if (!(orig instanceof PhraseQuery)) return orig;
>
>        PhraseQuery pq = (PhraseQuery) orig;
>        Term[] terms = pq.getTerms();
>        SpanQuery[] clauses = new SpanQuery[terms.length];
>
>        for (int i = 0; i < terms.length; i++)
>            clauses[i] = new PayloadTermQuery(terms[i], new
> AveragePayloadFunction());
>        return new PayloadNearQuery(clauses, slop, true);
>
>    }
>
>
> > Also, are there any performance considerations while using
> > a PayloadNearQuery instead of a PhraseQuery?
>
> I don't think there will be significant performance difference.
>
>
>
>

Re: Payloads with Phrase queries

Posted by Grant Ingersoll <gs...@apache.org>.
On Dec 10, 2009, at 6:35 AM, Raghuveer Kancherla wrote:

> I was looking through some lucene source codes and found the following class
> org.apache.lucene.search.payloads.PayloadSpanUtil
> 
> There is a function named queryToSpanQuery in this class. Is this the
> preferred way to convert a PhraseQuery to PayloadNearQuery?

I don't think that there is a conversion method.  You will need to do this on your own.

> 
> Also, are there any performance considerations while using a
> PayloadNearQuery instead of a PhraseQuery?

Yes, I would suspect PNQ to be slower, but likely not that much slower.  That being said, I haven't benchmarked it.  Then again, PNQ does stuff that PQ doesn't, so it's an apples and oranges debate.

> 
> Thanks,
> Raghu
> 
> 
> 
> On Thu, Dec 10, 2009 at 4:40 PM, AHMET ARSLAN <io...@yahoo.com> wrote:
> 
>>> Hi,
>>> I am looking for a way to use payloads in my search
>>> application. Indexing
>>> data with payloads into Solr is pretty straightforward.
>>> However using the
>>> payloads during search time is a bit confusing. Can anyone
>>> point me in the
>>> right direction to enable payloads on a *PhraseQuery*. I
>>> looked at the
>>> following resources and got payload on a TermQuery
>>> working.
>>> 
>>>   1.
>>> 
>> http://www.lucidimagination.com/blog/2009/08/05/getting-started-with-payloads/
>>>   2.
>> http://www.mail-archive.com/solr-user@lucene.apache.org/msg24863.html
>>>   3. There is also a jira issue (SOLR-1485)
>>> that gives a patch for using
>>>   Payload.
>>>   4. Lucene-In-Action
>>> 
>>> I am guessing that I should return a payload version of
>>> PhraseQuery in
>>> QueryParser's (package
>>> org.apache.lucene.queryParser.queryParser.java)
>>> newPhraseQuery function. If yes, what type should this
>>> query be?
>> 
>> Yes. PayloadNearQuery [1]
>> 
>> [1]
>> http://lucene.apache.org/java/3_0_0/api/core/org/apache/lucene/search/payloads/PayloadNearQuery.html
>> 
>> 
>> 
>> 

--------------------------
Grant Ingersoll
http://www.lucidimagination.com/

Search the Lucene ecosystem (Lucene/Solr/Nutch/Mahout/Tika/Droids) using Solr/Lucene:
http://www.lucidimagination.com/search


Re: Payloads with Phrase queries

Posted by AHMET ARSLAN <io...@yahoo.com>.
> I was looking through some lucene
> source codes and found the following class
> org.apache.lucene.search.payloads.PayloadSpanUtil
> 
> There is a function named queryToSpanQuery in this class.
> Is this the
> preferred way to convert a PhraseQuery to
> PayloadNearQuery?

queryToSpanQuery method does not return PayloadNearQuery type.

You need to override getFieldQuery(String field, String queryText, int slop) of SolrQueryParser or QueryParser.

This code is modified from Lucene In Action Book (2nd edition) Chapter 6.3.4 Allowing ordered phrase queries

protected Query getFieldQuery(String field, String queryText, int slop) throws ParseException {

        Query orig = super.getFieldQuery(field, queryText, slop);

        if (!(orig instanceof PhraseQuery)) return orig;

        PhraseQuery pq = (PhraseQuery) orig;
        Term[] terms = pq.getTerms(); 
        SpanQuery[] clauses = new SpanQuery[terms.length];

        for (int i = 0; i < terms.length; i++)
            clauses[i] = new PayloadTermQuery(terms[i], new AveragePayloadFunction());
        return new PayloadNearQuery(clauses, slop, true);

    }


> Also, are there any performance considerations while using
> a PayloadNearQuery instead of a PhraseQuery?

I don't think there will be significant performance difference. 


      

Re: Payloads with Phrase queries

Posted by Raghuveer Kancherla <ra...@aplopio.com>.
I was looking through some lucene source codes and found the following class
org.apache.lucene.search.payloads.PayloadSpanUtil

There is a function named queryToSpanQuery in this class. Is this the
preferred way to convert a PhraseQuery to PayloadNearQuery?

Also, are there any performance considerations while using a
PayloadNearQuery instead of a PhraseQuery?

Thanks,
Raghu



On Thu, Dec 10, 2009 at 4:40 PM, AHMET ARSLAN <io...@yahoo.com> wrote:

> > Hi,
> > I am looking for a way to use payloads in my search
> > application. Indexing
> > data with payloads into Solr is pretty straightforward.
> > However using the
> > payloads during search time is a bit confusing. Can anyone
> > point me in the
> > right direction to enable payloads on a *PhraseQuery*. I
> > looked at the
> > following resources and got payload on a TermQuery
> > working.
> >
> >    1.
> >
> http://www.lucidimagination.com/blog/2009/08/05/getting-started-with-payloads/
> >    2.
> http://www.mail-archive.com/solr-user@lucene.apache.org/msg24863.html
> >    3. There is also a jira issue (SOLR-1485)
> > that gives a patch for using
> >    Payload.
> >    4. Lucene-In-Action
> >
> > I am guessing that I should return a payload version of
> > PhraseQuery in
> > QueryParser's (package
> > org.apache.lucene.queryParser.queryParser.java)
> > newPhraseQuery function. If yes, what type should this
> > query be?
>
> Yes. PayloadNearQuery [1]
>
> [1]
> http://lucene.apache.org/java/3_0_0/api/core/org/apache/lucene/search/payloads/PayloadNearQuery.html
>
>
>
>

Re: Payloads with Phrase queries

Posted by AHMET ARSLAN <io...@yahoo.com>.
> Hi,
> I am looking for a way to use payloads in my search
> application. Indexing
> data with payloads into Solr is pretty straightforward.
> However using the
> payloads during search time is a bit confusing. Can anyone
> point me in the
> right direction to enable payloads on a *PhraseQuery*. I
> looked at the
> following resources and got payload on a TermQuery
> working.
> 
>    1.
>    http://www.lucidimagination.com/blog/2009/08/05/getting-started-with-payloads/
>    2. http://www.mail-archive.com/solr-user@lucene.apache.org/msg24863.html
>    3. There is also a jira issue (SOLR-1485)
> that gives a patch for using
>    Payload.
>    4. Lucene-In-Action
> 
> I am guessing that I should return a payload version of
> PhraseQuery in
> QueryParser's (package
> org.apache.lucene.queryParser.queryParser.java)
> newPhraseQuery function. If yes, what type should this
> query be?

Yes. PayloadNearQuery [1]

[1]http://lucene.apache.org/java/3_0_0/api/core/org/apache/lucene/search/payloads/PayloadNearQuery.html