lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex vB <>
Subject Lucene 4.0 Payloads
Date Thu, 17 Mar 2011 23:21:05 GMT
Hello everybody,

I am currently experimenting with Lucene 4.0 and would like to add payloads.
Payload should only be added once per term on the first position. My current
code looks like this:

public final boolean incrementToken() throws {
   String term = characterAttr.toString();
      if (!input.incrementToken()) {
         return false;
      // hmh contains all terms for one document
      if(hmh.checkKey(term)){ //  check if hashmap contains term
    		  Payload payload = new Payload(hmh.getCompressedData(term)); //get
payload data
    		  payloadAttr.setPayload(payload); // add payload
    		  hmh.removeFromIndexingMap(term);	// remove term from hashmap
      return true;

Is this a correct way for adding payloads in Lucene 4.0? When I try to
receive payloads I am not getting payload on the first position. For getting
payloads I use this:

        DocsAndPositionsEnum tp = MultiFields.getTermPositionsEnum(ir,       
                                MultiFields.getDeletedDocs(ir), fieldName,
new BytesRef(searchString));
        while (tp.nextDoc() != tp.NO_MORE_DOCS) {
			if (tp.hasPayload() && counter < 10) {
				Document doc = ir.document(tp.docID());
				BytesRef br = tp.getPayload();
				System.out.println("Found payload \"" + br.utf8ToString() + "\" for
document " +  
                                              tp.docID() + " and query " +
searchString +  " in country " +  

As far as I know there are two possibilities to use payloads
1) During similarity scoring
2) During search

Is there a better/faster way to receive payloads during search? Is it
possible to run a normal query and read the payloads from hits? Is 1 or 2
the faster way to use payloads? Can I find somewhere example code for Lucene
and loading payloads?


View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message