Package org.apache.lucene.document

Examples of org.apache.lucene.document.NumericField


    for (int l=0; l<5000; l++) {
      Document doc = new Document();
      for (int m=0, c=rnd.nextInt(10); m<=c; m++) {
        int value = rnd.nextInt(Integer.MAX_VALUE);
        doc.add(new Field("asc", format.format(value), Field.Store.NO, Field.Index.NOT_ANALYZED));
        doc.add(new NumericField("trie", Field.Store.NO, true).setIntValue(value));
      }
      writer.addDocument(doc);
   
    writer.close();
   
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

  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

  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 != null ) { //Today Fieldable is Serializable but for how long?
        serializer.addFieldWithSerializableFieldable( toByteArray( fieldable ) );
      }
View Full Code Here

        final Document doc = new Document();

        doc.add(new Field("title", docTitle, Store.YES, Index.ANALYZED));
        doc.add(new Field("author", docAuthor, Store.YES, Index.ANALYZED));
        doc.add(new Field("text", docText, Store.YES, Index.ANALYZED));
        doc.add(new NumericField("year", Store.YES, true).setIntValue(docYear));
        doc.add(new NumericField("gross", Store.YES, true)
                .setDoubleValue(docGross));

        return doc;
    }
View Full Code Here

        doc.add(new Field("title", new StringReader("Jurassic Park")));
        doc.add(new Field("author", new StringReader("Michael Crichton")));
        doc.add(new Field("text", new StringReader("It's a UNIX system! I know this!")));
        doc.add(new Field("rating", new StringReader("Good")));
        doc.add(new Field("publisher", "", Store.YES, Index.ANALYZED));
        doc.add(new NumericField("year", Store.YES, true).setIntValue(1990));
        doc.add(new NumericField("gross", Store.YES, true).setDoubleValue(900.00));

        doc.add(new NumericField("longField", Store.YES, true).setLongValue(1));
        doc.add(new NumericField("shortField", Store.YES, true).setIntValue(1));
        doc.add(new NumericField("byteField", Store.YES, true).setIntValue(1));
        doc.add(new NumericField("floatField", Store.YES, true).setFloatValue(1));

        return doc;
    }
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( ( Serializable ) fieldable ) );
      }
View Full Code Here

    IndexWriter writer = new IndexWriter(ramDir, new StandardAnalyzer(TEST_VERSION), true, IndexWriter.MaxFieldLength.UNLIMITED);
    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

  // ... has multiple jobs
  private Document makeJob(String skill, int year) {
    Document job = new Document();
    job.add(newField("skill", skill, Field.Store.YES, Field.Index.NOT_ANALYZED));
    job.add(new NumericField("year").setIntValue(year));
    return job;
  }
View Full Code Here

  // ... has multiple qualifications
  private Document makeQualification(String qualification, int year) {
    Document job = new Document();
    job.add(newField("qualification", qualification, Field.Store.YES, Field.Index.NOT_ANALYZED));
    job.add(new NumericField("year").setIntValue(year));
    return job;
  }
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.