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 Allahbaksh Mohammedali Asadullah <Al...@infosys.com> on 2008/02/11 14:46:07 UTC

Getting Payload from Hits

Hi,
I have saved payload in my index. When the user types the query I get HIT document. From HIT document how I can get the value of Payload for particular tree.

For example
                    _analyzer = new PayloadAnalyzer();
           _writer = new IndexWriter(new File("d:/test1"), _analyzer, true);
           for (int i = 0; i < 10; i++) {
             Document d = new Document();
             d.add(new Field("f1", "This field has no payloads", Field.Store.NO, Field.Index.TOKENIZED));
             d.add(new Field("f2", "This field has payloads in all docs", Field.Store.YES, Field.Index.TOKENIZED));
             Integer i1 = i;
             byte []payLoadData = null;
             payLoadData[0] = i1.byteValue();
             _analyzer.setPayloadData("f2", payLoadData);
             _writer.addDocument(d);

            }
         writer.optimize();
         // flush
         writer.close();
         String queryString = "payloads + doc";
         System.out.println("Reading Payload Data will begin now");

         _parser = new QueryParser("f2", new PayloadAnalyzer());
         _searcher = new IndexSearcher("d:/test1");
         Query query =_parser.parse(queryString);
         Hits hits = _searcher.search(query);
         for (int i = 0; i < hits.length(); i++) {
             Document doc = hits.doc(i);


      Here I want to get the value of payload for the field..
Please let me know how I can get value of payload for a field from Hits
          }
Thanks in Advance
Warm Regards,
Allahbaksh




**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***

Re: Getting Payload from Hits

Posted by Grant Ingersoll <gs...@apache.org>.
Right now there is not a good way, other than to use the  
TermPositions.   See https://issues.apache.org/jira/browse/LUCENE-1001  
for some thoughts on adding the ability.  Unfortunately, I ran into a  
roadblock, and haven't been able to get back to it.  If you feel you  
can submit a patch, it would be most welcome.

-Grant


On Feb 11, 2008, at 10:51 AM, Allahbaksh Mohammedali Asadullah wrote:

>
> Hi,
> Thanks for the reply. But is there any way that from the search  
> result I can get Payload.
>
> See my requirement is when user search for some field I want to  
> display also additional data which is stored as Payload.
>
> Regards,
> Allahbaksh
>
>
>
>
> -----Original Message-----
> From: Karl Wettin [mailto:karl.wettin@gmail.com]
> Sent: Monday, February 11, 2008 8:52 PM
> To: java-user@lucene.apache.org
> Subject: Re: Getting Payload from Hits
>
>
> 11 feb 2008 kl. 14.46 skrev Allahbaksh Mohammedali Asadullah:
>
>> d.add(new Field("f1", "This field has no payloads", Field.Store.NO,
>> Field.Index.TOKENIZED));
>> d.add(new Field("f2", "This field has payloads in all docs",
>> Field.Store.YES, Field.Index.TOKENIZED));
>
>> Document doc = hits.doc(i);
>>
>> Here I want to get the value of payload for the field..
>
> Are you confusing payloads with stored field values?
>
> You retreive the /stored field value/ like this:
>
> doc.get("f2");
>
> You "can not" retreive /payloads/ from Hits.
>
>
>
>    karl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
> **************** CAUTION - Disclaimer *****************
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION  
> intended solely for the use of the addressee(s). If you are not the  
> intended recipient, please notify the sender by e-mail and delete  
> the original message. Further, you are not to copy, disclose, or  
> distribute this e-mail or its contents to any other person and any  
> such actions are unlawful. This e-mail may contain viruses. Infosys  
> has taken every reasonable precaution to minimize this risk, but is  
> not liable for any damage you may sustain as a result of any virus  
> in this e-mail. You should carry out your own virus checks before  
> opening the e-mail or attachment. Infosys reserves the right to  
> monitor and review the content of all messages sent to or from this  
> e-mail address. Messages sent to or from this e-mail address may be  
> stored on the Infosys e-mail system.
> ***INFOSYS******** End of Disclaimer ********INFOSYS***
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>

--------------------------
Grant Ingersoll
http://lucene.grantingersoll.com
http://www.lucenebootcamp.com

Lucene Helpful Hints:
http://wiki.apache.org/lucene-java/BasicsOfPerformance
http://wiki.apache.org/lucene-java/LuceneFAQ





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


RE: Getting Payload from Hits

Posted by Allahbaksh Mohammedali Asadullah <Al...@infosys.com>.
Hi,
Karl thanks for the reply. But I am not able follow you. Should I extend Query class and How should I get matching term. Can you please elaborate on it.
Regards,
Allahbakhs




-----Original Message-----
From: Karl Wettin [mailto:karl.wettin@gmail.com]
Sent: Monday, February 11, 2008 9:53 PM
To: java-user@lucene.apache.org
Subject: Re: Getting Payload from Hits

You would have to collect the payloads from matching terms by
extending a query.

See this recent thread:
http://www.nabble.com/Faceting-with-payloads-td15322956.html#a15322956

Are you sure this is what you want to do? What is it you store in the
payloads, and how do you plan to use this information once you have
retreived it?


    karl

11 feb 2008 kl. 16.51 skrev Allahbaksh Mohammedali Asadullah:

>
> Hi,
> Thanks for the reply. But is there any way that from the search
> result I can get Payload.
>
> See my requirement is when user search for some field I want to
> display also additional data which is stored as Payload.
>
> Regards,
> Allahbaksh
>
>
>
>
> -----Original Message-----
> From: Karl Wettin [mailto:karl.wettin@gmail.com]
> Sent: Monday, February 11, 2008 8:52 PM
> To: java-user@lucene.apache.org
> Subject: Re: Getting Payload from Hits
>
>
> 11 feb 2008 kl. 14.46 skrev Allahbaksh Mohammedali Asadullah:
>
>> d.add(new Field("f1", "This field has no payloads", Field.Store.NO,
>> Field.Index.TOKENIZED));
>> d.add(new Field("f2", "This field has payloads in all docs",
>> Field.Store.YES, Field.Index.TOKENIZED));
>
>> Document doc = hits.doc(i);
>>
>> Here I want to get the value of payload for the field..
>
> Are you confusing payloads with stored field values?
>
> You retreive the /stored field value/ like this:
>
> doc.get("f2");
>
> You "can not" retreive /payloads/ from Hits.
>
>
>
>    karl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
> **************** CAUTION - Disclaimer *****************
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION
> intended solely for the use of the addressee(s). If you are not the
> intended recipient, please notify the sender by e-mail and delete
> the original message. Further, you are not to copy, disclose, or
> distribute this e-mail or its contents to any other person and any
> such actions are unlawful. This e-mail may contain viruses. Infosys
> has taken every reasonable precaution to minimize this risk, but is
> not liable for any damage you may sustain as a result of any virus
> in this e-mail. You should carry out your own virus checks before
> opening the e-mail or attachment. Infosys reserves the right to
> monitor and review the content of all messages sent to or from this
> e-mail address. Messages sent to or from this e-mail address may be
> stored on the Infosys e-mail system.
> ***INFOSYS******** End of Disclaimer ********INFOSYS***


---------------------------------------------------------------------
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: Getting Payload from Hits

Posted by Karl Wettin <ka...@gmail.com>.
You would have to collect the payloads from matching terms by  
extending a query.

See this recent thread:
http://www.nabble.com/Faceting-with-payloads-td15322956.html#a15322956

Are you sure this is what you want to do? What is it you store in the  
payloads, and how do you plan to use this information once you have  
retreived it?


    karl

11 feb 2008 kl. 16.51 skrev Allahbaksh Mohammedali Asadullah:

>
> Hi,
> Thanks for the reply. But is there any way that from the search  
> result I can get Payload.
>
> See my requirement is when user search for some field I want to  
> display also additional data which is stored as Payload.
>
> Regards,
> Allahbaksh
>
>
>
>
> -----Original Message-----
> From: Karl Wettin [mailto:karl.wettin@gmail.com]
> Sent: Monday, February 11, 2008 8:52 PM
> To: java-user@lucene.apache.org
> Subject: Re: Getting Payload from Hits
>
>
> 11 feb 2008 kl. 14.46 skrev Allahbaksh Mohammedali Asadullah:
>
>> d.add(new Field("f1", "This field has no payloads", Field.Store.NO,
>> Field.Index.TOKENIZED));
>> d.add(new Field("f2", "This field has payloads in all docs",
>> Field.Store.YES, Field.Index.TOKENIZED));
>
>> Document doc = hits.doc(i);
>>
>> Here I want to get the value of payload for the field..
>
> Are you confusing payloads with stored field values?
>
> You retreive the /stored field value/ like this:
>
> doc.get("f2");
>
> You "can not" retreive /payloads/ from Hits.
>
>
>
>    karl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
> **************** CAUTION - Disclaimer *****************
> This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION  
> intended solely for the use of the addressee(s). If you are not the  
> intended recipient, please notify the sender by e-mail and delete  
> the original message. Further, you are not to copy, disclose, or  
> distribute this e-mail or its contents to any other person and any  
> such actions are unlawful. This e-mail may contain viruses. Infosys  
> has taken every reasonable precaution to minimize this risk, but is  
> not liable for any damage you may sustain as a result of any virus  
> in this e-mail. You should carry out your own virus checks before  
> opening the e-mail or attachment. Infosys reserves the right to  
> monitor and review the content of all messages sent to or from this  
> e-mail address. Messages sent to or from this e-mail address may be  
> stored on the Infosys e-mail system.
> ***INFOSYS******** End of Disclaimer ********INFOSYS***


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


RE: Getting Payload from Hits

Posted by Allahbaksh Mohammedali Asadullah <Al...@infosys.com>.
Hi,
Thanks for the reply. But is there any way that from the search result I can get Payload.

See my requirement is when user search for some field I want to display also additional data which is stored as Payload.

Regards,
Allahbaksh




-----Original Message-----
From: Karl Wettin [mailto:karl.wettin@gmail.com]
Sent: Monday, February 11, 2008 8:52 PM
To: java-user@lucene.apache.org
Subject: Re: Getting Payload from Hits


11 feb 2008 kl. 14.46 skrev Allahbaksh Mohammedali Asadullah:

> d.add(new Field("f1", "This field has no payloads", Field.Store.NO,
> Field.Index.TOKENIZED));
> d.add(new Field("f2", "This field has payloads in all docs",
> Field.Store.YES, Field.Index.TOKENIZED));

> Document doc = hits.doc(i);
>
> Here I want to get the value of payload for the field..

Are you confusing payloads with stored field values?

You retreive the /stored field value/ like this:

doc.get("f2");

You "can not" retreive /payloads/ from Hits.



    karl

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


**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***

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


Re: Getting Payload from Hits

Posted by Karl Wettin <ka...@gmail.com>.
11 feb 2008 kl. 14.46 skrev Allahbaksh Mohammedali Asadullah:

> d.add(new Field("f1", "This field has no payloads", Field.Store.NO,  
> Field.Index.TOKENIZED));
> d.add(new Field("f2", "This field has payloads in all docs",  
> Field.Store.YES, Field.Index.TOKENIZED));

> Document doc = hits.doc(i);
>
> Here I want to get the value of payload for the field..

Are you confusing payloads with stored field values?

You retreive the /stored field value/ like this:

doc.get("f2");

You "can not" retreive /payloads/ from Hits.



    karl

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