On Wed, Oct 13, 2010 at 04:37:37PM +0100, Sykes, Derek wrote: > Hi there, > > I'm currently trying to work out how I can determine the type > (string/number/date/etc)of a term. I've not seen any off the shelf way to do > it so am trying to store a payload against each term that records the type. > > I'm having a little trouble retrieving a payload I'd stored onto the term. > At the moment I'm using the TypeAsPayloadTokenFilter, however I'll change > this soon as it's not really what I'm after. > > I'm then getting a TermEnum from either reader.terms() or using a > PrefixTermEnum. > > For each term I want the payload from I'm running this function: > > private String getPayload(Term term) { > String payload = null; > try { > TermPositions termPositions = reader.termPositions(term); > termPositions.next(); > if (termPositions.isPayloadAvailable()) { > byte[] payloadBytes = new > byte[termPositions.getPayloadLength()]; > payloadBytes = termPositions.getPayload(payloadBytes, 0); > payload = new String(payloadBytes); > LOG.debug(payload); > } > } > catch( IOException e) { > ... > > This never returns anything though.
Hi, my guess is that you need to call nextPosition, why not something like this : // goto to the doc with skipTo(int internalId) or next() // Iterate over positions for(int i = 0; i < currentTermPos.freq(); i++) { int p = currentTermPos.nextPosition(); payloadBuffer = currentTermPos.getPayload(payloadBuffer, 0); ... } -- David Causse Spotter http://www.spotter.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org