@Override
  public ParseResult parse(Reader reader, AttributeSource parent)
      throws IOException {
    ParseResult res = new ParseResult();

    // get MtasUpdateRequestProcessorResult
    StringBuilder sb = new StringBuilder();
    char[] buf = new char[128];
    int cnt;
    while ((cnt = reader.read(buf)) > 0) {
      sb.append(buf, 0, cnt);
    }
    Iterator<MtasUpdateRequestProcessorResultItem> iterator;

    try (
        MtasUpdateRequestProcessorResultReader result = new MtasUpdateRequestProcessorResultReader(
            sb.toString());) {
      iterator = result.getIterator();
      if (iterator != null && iterator.hasNext()) {
        res.str = result.getStoredStringValue();
        res.bin = result.getStoredBinValue();
      } else {
        res.str = null;
        res.bin = null;
        result.close();
        return res;
      }
      parent.clearAttributes();
      while (iterator.hasNext()) {
        MtasUpdateRequestProcessorResultItem item = iterator.next();
        if (item.tokenTerm != null) {
          CharTermAttribute catt = parent.addAttribute(CharTermAttribute.class);
          catt.append(item.tokenTerm);
        }
        if (item.tokenFlags != null) {
          FlagsAttribute flags = parent.addAttribute(FlagsAttribute.class);
          flags.setFlags(item.tokenFlags);
        }
        if (item.tokenPosIncr != null) {
          PositionIncrementAttribute patt = parent
              .addAttribute(PositionIncrementAttribute.class);
          patt.setPositionIncrement(item.tokenPosIncr);
        }
        if (item.tokenPayload != null) {
          PayloadAttribute p = parent.addAttribute(PayloadAttribute.class);
          p.setPayload(new BytesRef(item.tokenPayload));
        }
        if (item.tokenOffsetStart != null && item.tokenOffsetEnd != null) {
          OffsetAttribute offset = parent.addAttribute(OffsetAttribute.class);
          offset.setOffset(item.tokenOffsetStart, item.tokenOffsetEnd);
        }
        // capture state and add to result
        State state = parent.captureState();
        res.states.add(state.clone());
        // reset for reuse
        parent.clearAttributes();
      }
    } catch (IOException e) {
      // ignore
      log.debug(e);
    }
    return res;
  }
@ Override public ParseResult parse ( Reader reader , AttributeSource parent ) throws IOException { ParseResult res = new ParseResult ( ) ; StringBuilder sb = new StringBuilder ( ) ; char [ ] buf = new char [ 128 ] ; int cnt ; while ( ( cnt = reader . read ( buf ) ) > 0 ) { sb . append ( buf , 0 , cnt ) ; } Iterator < MtasUpdateRequestProcessorResultItem > iterator ; try ( MtasUpdateRequestProcessorResultReader result = new MtasUpdateRequestProcessorResultReader ( sb . toString ( ) ) ; ) { iterator = result . getIterator ( ) ; if ( iterator != null && iterator . hasNext ( ) ) { res . str = result . getStoredStringValue ( ) ; res . bin = result . getStoredBinValue ( ) ; } else { res . str = null ; res . bin = null ; result . close ( ) ; return res ; } parent . clearAttributes ( ) ; while ( iterator . hasNext ( ) ) { MtasUpdateRequestProcessorResultItem item = iterator . next ( ) ; if ( item . tokenTerm != null ) { CharTermAttribute catt = parent . addAttribute ( CharTermAttribute . class ) ; catt . append ( item . tokenTerm ) ; } if ( item . tokenFlags != null ) { FlagsAttribute flags = parent . addAttribute ( FlagsAttribute . class ) ; flags . setFlags ( item . tokenFlags ) ; } if ( item . tokenPosIncr != null ) { PositionIncrementAttribute patt = parent . addAttribute ( PositionIncrementAttribute . class ) ; patt . setPositionIncrement ( item . tokenPosIncr ) ; } if ( item . tokenPayload != null ) { PayloadAttribute p = parent . addAttribute ( PayloadAttribute . class ) ; p . setPayload ( new BytesRef ( item . tokenPayload ) ) ; } if ( item . tokenOffsetStart != null && item . tokenOffsetEnd != null ) { OffsetAttribute offset = parent . addAttribute ( OffsetAttribute . class ) ; offset . setOffset ( item . tokenOffsetStart , item . tokenOffsetEnd ) ; } State state = parent . captureState ( ) ; res . states . add ( state . clone ( ) ) ; parent . clearAttributes ( ) ; } } catch ( IOException e ) { log . debug ( e ) ; } return res ; }
/*
(non-Javadoc)

@see
org.apache.solr.schema.PreAnalyzedField.PreAnalyzedParser#parse(java.io.
Reader, org.apache.lucene.util.AttributeSource)