Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexableField


        BytesRef tempPayload = null;
        BytesRef tempTerm = null;
        Set<BytesRef> tempContexts = new HashSet<>();

        if (hasPayloads) {
          IndexableField payload = doc.getField(payloadField);
          if (payload == null || (payload.binaryValue() == null && payload.stringValue() == null)) {
            continue;
          }
          tempPayload = (payload.binaryValue() != null) ? payload.binaryValue() : new BytesRef(payload.stringValue());
        }

        if (hasContexts) {
          final IndexableField[] contextFields = doc.getFields(contextsField);
          for (IndexableField contextField : contextFields) {
            if (contextField.binaryValue() == null && contextField.stringValue() == null) {
              continue;
            } else {
              tempContexts.add((contextField.binaryValue() != null) ? contextField.binaryValue() : new BytesRef(contextField.stringValue()));
            }
          }
        }

        IndexableField fieldVal = doc.getField(field);
        if (fieldVal == null || (fieldVal.binaryValue() == null && fieldVal.stringValue() == null)) {
          continue;
        }
        tempTerm = (fieldVal.stringValue() != null) ? new BytesRef(fieldVal.stringValue()) : fieldVal.binaryValue();

        currentPayload = tempPayload;
        currentContexts = tempContexts;
        currentWeight = getWeight(doc, currentDocId);
View Full Code Here


  public void testBinaryFieldInIndex()
    throws Exception
  {
    FieldType ft = new FieldType();
    ft.setStored(true);
    IndexableField binaryFldStored = new StoredField("binaryStored", binaryValStored.getBytes(StandardCharsets.UTF_8));
    IndexableField stringFldStored = new Field("stringStored", binaryValStored, ft);

    Document doc = new Document();
   
    doc.add(binaryFldStored);
   
View Full Code Here

    reader.close();
    dir.close();
  }
 
  public void testCompressionTools() throws Exception {
    IndexableField binaryFldCompressed = new StoredField("binaryCompressed", CompressionTools.compress(binaryValCompressed.getBytes(StandardCharsets.UTF_8)));
    IndexableField stringFldCompressed = new StoredField("stringCompressed", CompressionTools.compressString(binaryValCompressed));
   
    Document doc = new Document();
   
    doc.add(binaryFldCompressed);
    doc.add(stringFldCompressed);
View Full Code Here

     * Retrieves the value for the <code>weightField</code> if its stored (using <code>doc</code>)
     * or if its indexed as {@link NumericDocValues} (using <code>docId</code>) for the document.
     * If no value is found, then the weight is 0.
     */
    protected long getWeight(Document doc, int docId) {
      IndexableField weight = doc.getField(weightField);
      if (weight != null) { // found weight as stored
        return (weight.numericValue() != null) ? weight.numericValue().longValue() : 0;
      } else if (weightValues != null) {  // found weight as NumericDocValue
        return weightValues.get(docId);
      } else { // fall back
        return 0;
      }
View Full Code Here

  public void testBinaryField() throws Exception {
    Document doc = new Document();
   
    FieldType ft = new FieldType();
    ft.setStored(true);
    IndexableField stringFld = new Field("string", binaryVal, ft);
    IndexableField binaryFld = new StoredField("binary", binaryVal.getBytes(StandardCharsets.UTF_8));
    IndexableField binaryFld2 = new StoredField("binary", binaryVal2.getBytes(StandardCharsets.UTF_8));
   
    doc.add(stringFld);
    doc.add(binaryFld);
   
    assertEquals(2, doc.getFields().size());
View Full Code Here

      }

      // field does not store term vector info
      if (vector == null) {
        Document d = ir.document(docNum);
        IndexableField fields[] = d.getFields(fieldName);
        for (IndexableField field : fields) {
          final String stringValue = field.stringValue();
          if (stringValue != null) {
            addTermFrequencies(new StringReader(stringValue), termFreqMap, fieldName);
          }
View Full Code Here

            while ((id = docs.nextDoc()) != DocsEnum.NO_MORE_DOCS)
            {
                inIndex = true;
                Document doc = ir.document(id);

                IndexableField lastIndexed = doc.getField(LAST_INDEXED_FIELD);

                if (lastIndexed == null
                        || Long.parseLong(lastIndexed.stringValue()) < lastModified
                                .getTime())
                {
                    reindexItem = true;
                }
            }
View Full Code Here

  private LuceneIndexHelper() {

  }

  public static void fieldShouldExistInIndex(IndexReader reader, String fieldName) throws IOException {
    IndexableField field = reader.document(0).getField(fieldName);
    if (field == null || !field.fieldType().stored()) {
      throw new IllegalArgumentException("Field '" + fieldName + "' is possibly not stored since first document in index does not contain this field.");
    }
  }
View Full Code Here

    this.nullMarker = nullMarker;
  }

  @Override
  public Object get(String name, Document document) {
    final IndexableField field = document.getField( name );
    String stringValue = field.stringValue();
    if ( nullMarker.equals( stringValue ) ) {
      return null;
    }
    else {
      return fieldBridge.get( name, document );
View Full Code Here

    return stringBridge.objectToString( object );
  }

  @Override
  public Object get(String name, Document document) {
    final IndexableField field = document.getField( name );
    if ( field == null ) {
      return stringBridge.stringToObject( null );
    }
    else {
      String stringValue = DocumentBuilderHelper.extractStringFromFieldable( field );
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.IndexableField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.