@Override
  protected byte[] defaultTypeDataToBinary() {
    final String encodedType = DataUtilities.encodeType(featureType);
    final String typeName = featureType.getTypeName();
    final byte[] typeNameBytes = StringUtils.stringToBinary(typeName);
    final byte[] encodedTypeBytes = StringUtils.stringToBinary(encodedType);

    byte[] attrBytes = new byte[0];

    final SimpleFeatureUserDataConfigurationSet userDataConfiguration =
        new SimpleFeatureUserDataConfigurationSet();
    userDataConfiguration.addConfigurations(typeName, new TimeDescriptorConfiguration());
    userDataConfiguration.addConfigurations(
        typeName, new SimpleFeatureStatsConfigurationCollection());
    userDataConfiguration.addConfigurations(typeName, new SimpleFeaturePrimaryIndexConfiguration());
    userDataConfiguration.configureFromType(featureType);

    try {
      attrBytes = StringUtils.stringToBinary(userDataConfiguration.asJsonString());
    } catch (final IOException e) {
      LOGGER.error("Failure to encode simple feature user data configuration", e);
    }

    final ByteBuffer buf =
        ByteBuffer.allocate(
            encodedTypeBytes.length
                + typeNameBytes.length
                + adapterId.getBytes().length
                + attrBytes.length
                + 24);

    buf.putInt(0); // a signal for the new version
    buf.putInt(typeNameBytes.length);
    buf.putInt(0); // old visibility (backward compatibility)
    buf.putInt(attrBytes.length);
    buf.putInt(encodedTypeBytes.length);
    buf.putInt(adapterId.getBytes().length);
    buf.put(typeNameBytes);
    buf.put(attrBytes);
    buf.put(encodedTypeBytes);
    buf.put(adapterId.getBytes());
    return buf.array();
  }
 public WholeFeatureDataAdapter(final SimpleFeatureType featureType) {
   super(
       new ArrayList<
           PersistentIndexFieldHandler<SimpleFeature, ? extends CommonIndexValue, Object>>(),
       new ArrayList<NativeFieldHandler<SimpleFeature, Object>>(),
       null,
       featureType);
   this.featureType = featureType;
   adapterId = new ByteArrayId(StringUtils.stringToBinary(featureType.getTypeName()));
   statsManager = new StatsManager(this, featureType, featureType, null);
 }
 @Override
 public ByteArrayId getDataId(final SimpleFeature entry) {
   return new ByteArrayId(StringUtils.stringToBinary(entry.getID()));
 }
Beispiel #4
0
public class TextIndexStrategy implements FieldIndexStrategy<TextQueryConstraint, String> {

  protected static final String START_END_MARKER = "\01";
  protected static final byte[] START_END_MARKER_BYTE =
      StringUtils.stringToBinary(START_END_MARKER);

  private int start = 2;
  private int end = 4;

  public TextIndexStrategy() {
    super();
  }

  public TextIndexStrategy(final int start, final int end) {
    this();
    this.start = start;
    this.end = end;
  }

  @Override
  public byte[] toBinary() {
    final ByteBuffer bb = ByteBuffer.allocate(8);
    bb.putInt(start);
    bb.putInt(end);
    return bb.array();
  }

  @Override
  public void fromBinary(final byte[] bytes) {
    final ByteBuffer bb = ByteBuffer.wrap(bytes);
    start = bb.getInt();
    end = bb.getInt();
  }

  @Override
  public List<ByteArrayRange> getQueryRanges(
      final TextQueryConstraint indexedRange, final IndexMetaData... hints) {
    return indexedRange.getRange(start, end);
  }

  @Override
  public List<ByteArrayRange> getQueryRanges(
      final TextQueryConstraint indexedRange,
      final int maxEstimatedRangeDecomposition,
      final IndexMetaData... hints) {
    return indexedRange.getRange(start, end);
  }

  @Override
  public List<ByteArrayId> getInsertionIds(final List<FieldInfo<String>> indexedData) {
    final List<ByteArrayId> insertionIds = new ArrayList<>();
    for (final FieldInfo<String> fieldInfo : indexedData) {
      insertionIds.addAll(
          grams(
              START_END_MARKER + fieldInfo.getDataValue().getValue() + START_END_MARKER,
              start,
              end));
    }
    return insertionIds;
  }

  @Override
  public List<ByteArrayId> getInsertionIds(
      final List<FieldInfo<String>> indexedData, final int maxEstimatedDuplicateIds) {
    return getInsertionIds(indexedData);
  }

  @Override
  public List<FieldInfo<String>> getRangeForId(final ByteArrayId insertionId) {
    return Collections.emptyList();
  }

  @Override
  public String getId() {
    return "NGRAM_" + start + "_" + end;
  }

  protected static List<ByteArrayId> grams(final String value, final int start, final int end) {

    final NGramTokenizer nGramTokenizer = new NGramTokenizer(start, end);
    final List<ByteArrayId> tokens = new ArrayList<ByteArrayId>();
    try {
      nGramTokenizer.setReader(new StringReader(value));
      final CharTermAttribute charTermAttribute =
          nGramTokenizer.addAttribute(CharTermAttribute.class);
      nGramTokenizer.reset();

      while (nGramTokenizer.incrementToken()) {
        tokens.add(new ByteArrayId(charTermAttribute.toString()));
      }
      nGramTokenizer.end();
      nGramTokenizer.close();
    } catch (final IOException e) {
      e.printStackTrace();
    }

    return tokens;
  }

  public static final byte[] toIndexByte(final String ngram) {
    return toIndexByte(StringUtils.stringToBinary(ngram));
  }

  public static final byte[] toIndexByte(final byte[] ngramBytes) {
    final ByteBuffer buffer = ByteBuffer.allocate(ngramBytes.length + 4);
    buffer.putInt(ngramBytes.length);
    buffer.put(ngramBytes);
    return buffer.array();
  }

  @Override
  public Set<ByteArrayId> getNaturalSplits() {
    return null;
  }

  @Override
  public List<IndexMetaData> createMetaData() {
    return Collections.emptyList();
  }
}
Beispiel #5
0
 public static final byte[] toIndexByte(final String ngram) {
   return toIndexByte(StringUtils.stringToBinary(ngram));
 }