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 java.io.IOException { 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 " + doc.get("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? Regards Alex -- View this message in context: http://lucene.472066.n3.nabble.com/Lucene-4-0-Payloads-tp2695817p2695817.html Sent from the Lucene - Java Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org