Package org.apache.lucene.document

Examples of org.apache.lucene.document.NumericField


    getLuceneDocument().add( numField );
  }

  @Override
  public void addLongNumericField(long value, String name, int precisionStep, SerializableStore store, boolean indexed, float boost, boolean omitNorms, boolean omitTermFreqAndPositions) {
    NumericField numField = buildNumericField(
        name,
        precisionStep,
        store,
        indexed,
        boost,
        omitNorms,
        omitTermFreqAndPositions
    );
    numField.setLongValue( value );
    getLuceneDocument().add( numField );
  }
View Full Code Here


    getLuceneDocument().add( numField );
  }

  @Override
  public void addFloatNumericField(float value, String name, int precisionStep, SerializableStore store, boolean indexed, float boost, boolean omitNorms, boolean omitTermFreqAndPositions) {
    NumericField numField = buildNumericField(
        name,
        precisionStep,
        store,
        indexed,
        boost,
        omitNorms,
        omitTermFreqAndPositions
    );
    numField.setFloatValue( value );
    getLuceneDocument().add( numField );
  }
View Full Code Here

    numField.setFloatValue( value );
    getLuceneDocument().add( numField );
  }

  private NumericField buildNumericField(String name, int precisionStep, SerializableStore store, boolean indexed, float boost, boolean omitNorms, boolean omitTermFreqAndPositions) {
    NumericField numField = new NumericField(
        name,
        precisionStep,
        getStore( store ),
        indexed
    );
    numField.setBoost( boost );
    numField.setOmitNorms( omitNorms );
    numField.setOmitTermFreqAndPositions( omitTermFreqAndPositions );
    return numField;
  }
View Full Code Here

    return numField;
  }

  @Override
  public void addDoubleNumericField(double value, String name, int precisionStep, SerializableStore store, boolean indexed, float boost, boolean omitNorms, boolean omitTermFreqAndPositions) {
    NumericField numField = buildNumericField(
        name,
        precisionStep,
        store,
        indexed,
        boost,
        omitNorms,
        omitTermFreqAndPositions
    );
    numField.setDoubleValue( value );
    getLuceneDocument().add( numField );
  }
View Full Code Here

  public void addNumericFieldToDocument(String fieldName, Object value, Document document) {
    if ( storeType == Store.COMPRESS ) {
      throw new SearchException( "Error indexing field " + fieldName + ", @NumericField cannot be compressed" );
    }
    if ( value != null ) {
      NumericField numericField = new NumericField(
          fieldName, precisionStep, storeType != Store.NO ? Field.Store.YES : Field.Store.NO, true
      );
      NumericFieldUtils.setNumericValue( value, numericField );
      numericField.setBoost( boost );

      if ( numericField.getNumericValue() != null ) {
        document.add( numericField );
      }
    }
  }
View Full Code Here

  public void addNumericFieldToDocument(String fieldName, Object value, Document document) {
    if ( storeType == Store.COMPRESS ) {
      throw new SearchException( "Error indexing field " + fieldName + ", @NumericField cannot be compressed" );
    }
    if ( value != null ) {
      NumericField numericField = new NumericField(
          fieldName, precisionStep, storeType != Store.NO ? Field.Store.YES : Field.Store.NO, true
      );
      NumericFieldUtils.setNumericValue( value, numericField );
      numericField.setBoost( boost );

      if ( numericField.getNumericValue() != null ) {
        document.add( numericField );
      }
    }
  }
View Full Code Here

    directory = newDirectory();
    RandomIndexWriter writer = new RandomIndexWriter(random, directory,
        newIndexWriterConfig(TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT))
        .setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
   
    NumericField
      field8 = new NumericField("field8", 8, Field.Store.YES, true),
      field6 = new NumericField("field6", 6, Field.Store.YES, true),
      field4 = new NumericField("field4", 4, Field.Store.YES, true),
      field2 = new NumericField("field2", 2, Field.Store.YES, true),
      fieldNoTrie = new NumericField("field"+Integer.MAX_VALUE, Integer.MAX_VALUE, Field.Store.YES, true),
      ascfield8 = new NumericField("ascfield8", 8, Field.Store.NO, true),
      ascfield6 = new NumericField("ascfield6", 6, Field.Store.NO, true),
      ascfield4 = new NumericField("ascfield4", 4, Field.Store.NO, true),
      ascfield2 = new NumericField("ascfield2", 2, Field.Store.NO, true);
   
    Document doc = new Document();
    // add fields, that have a distance to test general functionality
    doc.add(field8); doc.add(field6); doc.add(field4); doc.add(field2); doc.add(fieldNoTrie);
    // add ascending fields with a distance of 1, beginning at -noDocs/2 to test the correct splitting of range and inclusive/exclusive
    doc.add(ascfield8); doc.add(ascfield6); doc.add(ascfield4); doc.add(ascfield2);
   
    // Add a series of noDocs docs with increasing long values, by updating the fields
    for (int l=0; l<noDocs; l++) {
      long val=distance*l+startOffset;
      field8.setLongValue(val);
      field6.setLongValue(val);
      field4.setLongValue(val);
      field2.setLongValue(val);
      fieldNoTrie.setLongValue(val);

      val=l-(noDocs/2);
      ascfield8.setLongValue(val);
      ascfield6.setLongValue(val);
      ascfield4.setLongValue(val);
      ascfield2.setLongValue(val);
      writer.addDocument(doc);
    }
 
    reader = writer.getReader();
    searcher=newSearcher(reader);
View Full Code Here

  public void testInfiniteValues() throws Exception {
    Directory dir = newDirectory();
    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(
        TEST_VERSION_CURRENT, new WhitespaceAnalyzer(TEST_VERSION_CURRENT)));
    Document doc = new Document();
    doc.add(new NumericField("double").setDoubleValue(Double.NEGATIVE_INFINITY));
    doc.add(new NumericField("long").setLongValue(Long.MIN_VALUE));
    writer.addDocument(doc);
   
    doc = new Document();
    doc.add(new NumericField("double").setDoubleValue(Double.POSITIVE_INFINITY));
    doc.add(new NumericField("long").setLongValue(Long.MAX_VALUE));
    writer.addDocument(doc);
   
    doc = new Document();
    doc.add(new NumericField("double").setDoubleValue(0.0));
    doc.add(new NumericField("long").setLongValue(0L));
    writer.addDocument(doc);
    writer.close();
   
    IndexSearcher s = new IndexSearcher(dir);
   
View Full Code Here

      doc.add(new Field("compressed", BINARY_TO_COMPRESS, Field.Store.COMPRESS));   
      doc.add(new Field("compressedSize", Integer.toString(BINARY_COMPRESSED_LENGTH), Field.Store.YES, Field.Index.NOT_ANALYZED));
    }
    */
    // add numeric fields, to test if later versions preserve encoding
    doc.add(new NumericField("trieInt", 4).setIntValue(id));
    doc.add(new NumericField("trieLong", 4).setLongValue(id));
    writer.addDocument(doc);
  }
View Full Code Here

    IndexWriter writer = new IndexWriter(ramDir, new StandardAnalyzer(), true);
    for (int i = 0; i < texts.length; i++) {
      addDoc(writer, texts[i]);
    }
    Document doc = new Document();
    NumericField nfield = new NumericField(NUMERIC_FIELD_NAME, Store.YES, true);
    nfield.setIntValue(1);
    doc.add(nfield);
    writer.addDocument(doc, analyzer);
    nfield = new NumericField(NUMERIC_FIELD_NAME, Store.YES, true);
    nfield.setIntValue(3);
    doc = new Document();
    doc.add(nfield);
    writer.addDocument(doc, analyzer);
    nfield = new NumericField(NUMERIC_FIELD_NAME, Store.YES, true);
    nfield.setIntValue(5);
    doc = new Document();
    doc.add(nfield);
    writer.addDocument(doc, analyzer);
    nfield = new NumericField(NUMERIC_FIELD_NAME, Store.YES, true);
    nfield.setIntValue(7);
    doc = new Document();
    doc.add(nfield);
    writer.addDocument(doc, analyzer);
    writer.optimize();
    writer.close();
View Full Code Here

TOP

Related Classes of org.apache.lucene.document.NumericField

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.