Package org.apache.lucene.document

Examples of org.apache.lucene.document.NumericField


    RandomIndexWriter writer = new RandomIndexWriter(random, directory,
        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))
        .setMaxBufferedDocs(_TestUtil.nextInt(random, 100, 1000))
        .setMergePolicy(newLogMergePolicy()));
   
    NumericField
      field8 = new NumericField("field8", 8, 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),
      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(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(ascfield4); doc.add(ascfield2);
   
    // Add a series of noDocs docs with increasing int values
    for (int l=0; l<noDocs; l++) {
      int val=distance*l+startOffset;
      field8.setIntValue(val);
      field4.setIntValue(val);
      field2.setIntValue(val);
      fieldNoTrie.setIntValue(val);

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


  @Test
  public void testInfiniteValues() throws Exception {
    Directory dir = newDirectory();
    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random)));
    Document doc = new Document();
    doc.add(new NumericField("float").setFloatValue(Float.NEGATIVE_INFINITY));
    doc.add(new NumericField("int").setIntValue(Integer.MIN_VALUE));
    writer.addDocument(doc);
   
    doc = new Document();
    doc.add(new NumericField("float").setFloatValue(Float.POSITIVE_INFINITY));
    doc.add(new NumericField("int").setIntValue(Integer.MAX_VALUE));
    writer.addDocument(doc);
   
    doc = new Document();
    doc.add(new NumericField("float").setFloatValue(0.0f));
    doc.add(new NumericField("int").setIntValue(0));
    writer.addDocument(doc);
    writer.close();
   
    IndexSearcher s = new IndexSearcher(dir);
   
View Full Code Here

    getLuceneDocument().add( (Fieldable) toSerializable( instanceAsByte, loader ) );
  }

  @Override
  public void addIntNumericField(int 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.setIntValue( value );
    getLuceneDocument().add( numField );
  }
View Full Code Here

    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

  private void buildDocument(Document document, Serializer serializer) {
    List<Fieldable> docFields = document.getFields();
    serializer.fields( docFields );
    for ( Fieldable fieldable : docFields ) {
      if ( fieldable instanceof NumericField ) {
        NumericField safeField = (NumericField) fieldable;
        LuceneNumericFieldContext context = new LuceneNumericFieldContext( (NumericField) fieldable );
        switch ( safeField.getDataType() ) {
          case INT:
            serializer.addIntNumericField(
                safeField.getNumericValue().intValue(),
                context
            );
            break;
          case LONG:
            serializer.addLongNumericField(
                safeField.getNumericValue().longValue(),
                context
            );
            break;
          case FLOAT:
            serializer.addFloatNumericField(
                safeField.getNumericValue().floatValue(),
                context
            );
            break;
          case DOUBLE:
            serializer.addDoubleNumericField(
                safeField.getNumericValue().doubleValue(),
                context
            );
            break;
          default:
            String dataType = safeField.getDataType() == null ? "null" : safeField.getDataType().toString();
            throw log.unknownNumericFieldType( dataType );
        }
      }
      else if (fieldable instanceof Field) {
        Field safeField = (Field) fieldable;
        if ( safeField.isBinary() ) {
          serializer.addFieldWithBinaryData( new LuceneFieldContext( safeField ) );
        }
        else if ( safeField.stringValue() != null ) {
          serializer.addFieldWithStringData( new LuceneFieldContext( safeField ) );
        }
        else if ( safeField.readerValue() != null && safeField.readerValue() instanceof Serializable ) {
          serializer.addFieldWithSerializableReaderData( new LuceneFieldContext( safeField ) );
        }
        else if ( safeField.readerValue() != null ) {
          throw log.conversionFromReaderToStringNotYetImplemented();
        }
        else if ( safeField.tokenStreamValue() != null ) {
          serializer.addFieldWithTokenStreamData( new LuceneFieldContext( safeField ) );
        }
        else {
          throw log.unknownFieldType( safeField.getClass() );
        }
      }
      else if ( fieldable instanceof Serializable ) { //Today Fieldable is Serializable but for how long?
        serializer.addFieldWithSerializableFieldable( toByteArray( fieldable ) );
      }
View Full Code Here

   
    while ((line = reader.readLine()) != null) {

      if (line.equals("")) {
        if (doc != null) {
          doc.add(new NumericField("title_len",
              NumericUtils.PRECISION_STEP_DEFAULT,
              Store.YES, true).setIntValue(titleLen));
          doc.add(new NumericField("content_len",
              NumericUtils.PRECISION_STEP_DEFAULT,
              Store.YES, true).setIntValue(contentLen));
          doc.add(new NumericField("desc_len",
              NumericUtils.PRECISION_STEP_DEFAULT,
              Store.YES, true).setIntValue(descLen));
          doc.add(new NumericField("audience_len",
              NumericUtils.PRECISION_STEP_DEFAULT,
              Store.YES, true).setDoubleValue(((double)audienceLen) / doc.getValues("audience").length));
          doc.add(new NumericField("subject_len",
              NumericUtils.PRECISION_STEP_DEFAULT,
              Store.YES, true).setDoubleValue(((double)subjectLen) / doc.getValues("subject").length));

          doc.add(new NumericField("num_audience",
              NumericUtils.PRECISION_STEP_DEFAULT,
              Store.YES, true).setIntValue(doc.getValues("audience").length));
          doc.add(new NumericField("num_educationLevel",
              NumericUtils.PRECISION_STEP_DEFAULT,
              Store.YES, true).setIntValue(doc.getValues("educationLevel").length));
          doc.add(new NumericField("num_subject",
              NumericUtils.PRECISION_STEP_DEFAULT,
              Store.YES, true).setIntValue(doc.getValues("subject").length));
          doc.add(new NumericField("num_sub",
              NumericUtils.PRECISION_STEP_DEFAULT,
              Store.YES, true).setIntValue(doc.getValues("sub").length));

//          if (titleLen != 0 && contentLen != 0 && descLen != 0 &&
//            doc.getValues("subject").length > 0 &&
View Full Code Here

    getLuceneDocument().add( (Fieldable) toSerializable( instanceAsByte, loader ) );
  }

  @Override
  public void addIntNumericField(int 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.setIntValue( value );
    getLuceneDocument().add( numField );
  }
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.