Java 类org.apache.lucene.document.StoredField 实例源码

项目:elasticsearch_my    文件:NumberFieldMapper.java   
@Override
public List<Field> createFields(String name, Number value,
                                boolean indexed, boolean docValued, boolean stored) {
    List<Field> fields = new ArrayList<>();
    if (indexed) {
        fields.add(new HalfFloatPoint(name, value.floatValue()));
    }
    if (docValued) {
        fields.add(new SortedNumericDocValuesField(name,
            HalfFloatPoint.halfFloatToSortableShort(value.floatValue())));
    }
    if (stored) {
        fields.add(new StoredField(name, value.floatValue()));
    }
    return fields;
}
项目:elasticsearch_my    文件:NumberFieldMapper.java   
@Override
public List<Field> createFields(String name, Number value,
                                boolean indexed, boolean docValued, boolean stored) {
    List<Field> fields = new ArrayList<>();
    if (indexed) {
        fields.add(new FloatPoint(name, value.floatValue()));
    }
    if (docValued) {
        fields.add(new SortedNumericDocValuesField(name,
            NumericUtils.floatToSortableInt(value.floatValue())));
    }
    if (stored) {
        fields.add(new StoredField(name, value.floatValue()));
    }
    return fields;
}
项目:elasticsearch_my    文件:NumberFieldMapper.java   
@Override
public List<Field> createFields(String name, Number value,
                                boolean indexed, boolean docValued, boolean stored) {
    List<Field> fields = new ArrayList<>();
    if (indexed) {
        fields.add(new DoublePoint(name, value.doubleValue()));
    }
    if (docValued) {
        fields.add(new SortedNumericDocValuesField(name,
            NumericUtils.doubleToSortableLong(value.doubleValue())));
    }
    if (stored) {
        fields.add(new StoredField(name, value.doubleValue()));
    }
    return fields;
}
项目:elasticsearch_my    文件:SimpleAllTests.java   
public void testNoTokens() throws Exception {
    Directory dir = new RAMDirectory();
    IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(Lucene.KEYWORD_ANALYZER));

    FieldType allFt = getAllFieldType();
    Document doc = new Document();
    doc.add(new Field("_id", "1", StoredField.TYPE));
    doc.add(new AllField("_all", "", 2.0f, allFt));
    indexWriter.addDocument(doc);

    IndexReader reader = DirectoryReader.open(indexWriter);
    IndexSearcher searcher = new IndexSearcher(reader);

    TopDocs docs = searcher.search(new MatchAllDocsQuery(), 10);
    assertThat(docs.totalHits, equalTo(1));
    assertThat(docs.scoreDocs[0].doc, equalTo(0));
}
项目:elasticsearch_my    文件:Murmur3FieldMapper.java   
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields)
        throws IOException {
    final Object value;
    if (context.externalValueSet()) {
        value = context.externalValue();
    } else {
        value = context.parser().textOrNull();
    }
    if (value != null) {
        final BytesRef bytes = new BytesRef(value.toString());
        final long hash = MurmurHash3.hash128(bytes.bytes, bytes.offset, bytes.length, 0, new MurmurHash3.Hash128()).h1;
        fields.add(new SortedNumericDocValuesField(fieldType().name(), hash));
        if (fieldType().stored()) {
            fields.add(new StoredField(name(), hash));
        }
    }
}
项目:Reinickendorf_SER316    文件:NoteIndexer.java   
private Document noteToDocument(Note note, String noteHtmlContents) {
    Document d = new Document ();

    String id = note.getId ();

    Project project = note.getProject();

    String projectId = project.getID();
    String projectName = project.getTitle();
    String title = note.getTitle ();        
    String date = note.getDate() != null ? new SimpleDateFormat ("yyyy-MM-dd").format(note.getDate().getDate()) : null;

    d.add (new StringField ("id", id, Field.Store.YES));
    d.add (new StringField ("project_id", projectId, Field.Store.YES));
    d.add (new StoredField ("project_name", projectName));
    d.add (new TextField ("title", title, Field.Store.YES));
    d.add (new TextField ("title_cs", title, Field.Store.YES));
    d.add (new TextField ("date", date != null ? date : "", Field.Store.YES));
    d.add (new TextField ("body", noteHtmlContents, Field.Store.YES));

    return d;
}
项目:Reinickendorf_SER316    文件:EventIndexer.java   
private Document eventToDocument(Event newEvent) {
    Document d = new Document ();

    String eventId = newEvent.getId ();
    String eventText = newEvent.getText();

    String eventStartDate = newEvent.getStartDate() != null ? new SimpleDateFormat ("yyyy-MM-dd").format(newEvent.getStartDate().getDate()) : null;

    String eventStartTime = newEvent.getTimeString();

    if (eventStartDate != null) eventStartTime = eventStartDate + " @ " + eventStartTime;

    d.add (new StringField ("id", eventId, Field.Store.YES));
    d.add (new TextField ("text", eventText, Field.Store.YES));
    d.add (new TextField ("text_cs", eventText, Field.Store.YES));
    d.add (new StoredField ("original_start_date", eventStartTime != null ? eventStartTime : ""));
    return d;
}
项目:tripod    文件:ExampleIndexTransformer.java   
@Override
public Document transform(final Example input) throws TransformException {
    final Document doc = new Document();

    doc.add(new Field(ExampleField.ID.getName(), input.getId(), StringField.TYPE_STORED));
    doc.add(new SortedDocValuesField(ExampleField.ID.getName(), new BytesRef(input.getId())));

    doc.add(new Field(ExampleField.TITLE.getName(), input.getTitle(), TextField.TYPE_STORED));
    doc.add(new Field(ExampleField.BODY.getName(), input.getBody(), TextField.TYPE_STORED));

    doc.add(new Field(ExampleField.COLOR.getName(), input.getColor(), StringField.TYPE_STORED));
    doc.add(new SortedSetDocValuesFacetField(ExampleField.COLOR.getName(), input.getColor()));

    final Date createDate = input.getCreateDate();
    doc.add(new NumericDocValuesField(ExampleField.CREATE_DATE.getName(), createDate.getTime()));
    doc.add(new StoredField(ExampleField.CREATE_DATE.getName(), createDate.getTime()));

    return doc;
}
项目:elasticsearch-learning-to-rank    文件:ExplorerQueryTests.java   
@Before
public void setupIndex() throws Exception {
    dir = new RAMDirectory();

    try(IndexWriter indexWriter = new IndexWriter(dir, new IndexWriterConfig(Lucene.STANDARD_ANALYZER))) {
        for (int i = 0; i < docs.length; i++) {
            Document doc = new Document();
            doc.add(new Field("_id", Integer.toString(i + 1), StoredField.TYPE));
            doc.add(newTextField("text", docs[i], Field.Store.YES));
            indexWriter.addDocument(doc);
        }
    }

    reader = DirectoryReader.open(dir);
    searcher = new IndexSearcher(reader);
}
项目:orientdb-spatial    文件:OLuceneSpatialIndexEngineAbstract.java   
protected Document newGeoDocument(OIdentifiable oIdentifiable, Shape shape) {

    FieldType ft = new FieldType();
    ft.setIndexOptions(IndexOptions.DOCS);
    ft.setStored(true);

    Document doc = new Document();

    doc.add(OLuceneIndexType
        .createField(RID, oIdentifiable.getIdentity().toString(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
    for (IndexableField f : strategy.createIndexableFields(shape)) {
      doc.add(f);
    }

    doc.add(new StoredField(strategy.getFieldName(), ctx.toString(shape)));
    return doc;
  }
项目:LuceneDB    文件:LuceneObjectKVS.java   
@Override
public StoredField writeValue(V val, String valueFieldName) throws IOException {
    ByteArrayOutputStream bos = null;
    byte[] data;
    try {
        bos = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(bos);
        out.writeObject(val);
        data = bos.toByteArray();
    } finally {
        if (bos != null) {
            bos.close();
        }
    }
    return new StoredField(valueFieldName, data);
}
项目:search    文件:SpatialOpRecursivePrefixTreeTest.java   
@Override
protected Document newDoc(String id, Shape shape) {
  Document doc = new Document();
  doc.add(new StringField("id", id, Field.Store.YES));
  if (shape != null) {
    Collection<Shape> shapes;
    if (shape instanceof ShapePair) {
      shapes = new ArrayList<>(2);
      shapes.add(((ShapePair)shape).shape1);
      shapes.add(((ShapePair)shape).shape2);
    } else {
      shapes = Collections.singleton(shape);
    }
    for (Shape shapei : shapes) {
      for (Field f : strategy.createIndexableFields(shapei)) {
        doc.add(f);
      }
    }
    if (storeShape)//just for diagnostics
      doc.add(new StoredField(strategy.getFieldName(), shape.toString()));
  }
  return doc;
}
项目:search    文件:RandomSpatialOpFuzzyPrefixTreeTest.java   
@Override
protected Document newDoc(String id, Shape shape) {
  Document doc = new Document();
  doc.add(new StringField("id", id, Field.Store.YES));
  if (shape != null) {
    Collection<Shape> shapes;
    if (shape instanceof ShapePair) {
      shapes = new ArrayList<>(2);
      shapes.add(((ShapePair)shape).shape1);
      shapes.add(((ShapePair)shape).shape2);
    } else {
      shapes = Collections.singleton(shape);
    }
    for (Shape shapei : shapes) {
      for (Field f : strategy.createIndexableFields(shapei)) {
        doc.add(f);
      }
    }
    if (storeShape)//just for diagnostics
      doc.add(new StoredField(strategy.getFieldName(), shape.toString()));
  }
  return doc;
}
项目:search    文件:SpatialExample.java   
private Document newSampleDocument(int id, Shape... shapes) {
  Document doc = new Document();
  doc.add(new IntField("id", id, Field.Store.YES));
  //Potentially more than one shape in this field is supported by some
  // strategies; see the javadocs of the SpatialStrategy impl to see.
  for (Shape shape : shapes) {
    for (IndexableField f : strategy.createIndexableFields(shape)) {
      doc.add(f);
    }
    //store it too; the format is up to you
    //  (assume point in this example)
    Point pt = (Point) shape;
    doc.add(new StoredField(strategy.getFieldName(), pt.getX()+" "+pt.getY()));
  }

  return doc;
}
项目:search    文件:StrategyTestCase.java   
protected List<Document> getDocuments(Iterator<SpatialTestData> sampleData) {
  List<Document> documents = new ArrayList<>();
  while (sampleData.hasNext()) {
    SpatialTestData data = sampleData.next();
    Document document = new Document();
    document.add(new StringField("id", data.id, Field.Store.YES));
    document.add(new StringField("name", data.name, Field.Store.YES));
    Shape shape = data.shape;
    shape = convertShapeFromGetDocuments(shape);
    if (shape != null) {
      for (Field f : strategy.createIndexableFields(shape)) {
        document.add(f);
      }
      if (storeShape)//just for diagnostics
        document.add(new StoredField(strategy.getFieldName(), shape.toString()));
    }

    documents.add(document);
  }
  return documents;
}
项目:search    文件:DocumentValueSourceDictionaryTest.java   
private Map<String, Document> generateIndexDocuments(int ndocs) {
  Map<String, Document> docs = new HashMap<>();
  for(int i = 0; i < ndocs ; i++) {
    Field field = new TextField(FIELD_NAME, "field_" + i, Field.Store.YES);
    Field payload = new StoredField(PAYLOAD_FIELD_NAME, new BytesRef("payload_" + i));
    Field weight1 = new NumericDocValuesField(WEIGHT_FIELD_NAME_1, 10 + i);
    Field weight2 = new NumericDocValuesField(WEIGHT_FIELD_NAME_2, 20 + i);
    Field weight3 = new NumericDocValuesField(WEIGHT_FIELD_NAME_3, 30 + i);
    Field contexts = new StoredField(CONTEXTS_FIELD_NAME, new BytesRef("ctx_"  + i + "_0"));
    Document doc = new Document();
    doc.add(field);
    doc.add(payload);
    doc.add(weight1);
    doc.add(weight2);
    doc.add(weight3);
    doc.add(contexts);
    for(int j = 1; j < atLeast(3); j++) {
      contexts.setBytesValue(new BytesRef("ctx_" + i + "_" + j));
      doc.add(contexts);
    }
    docs.put(field.stringValue(), doc);
  }
  return docs;
}
项目:search    文件:BaseStoredFieldsFormatTestCase.java   
public void testBulkMergeWithDeletes() throws IOException {
  final int numDocs = atLeast(200);
  Directory dir = newDirectory();
  RandomIndexWriter w = new RandomIndexWriter(random(), dir, newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(NoMergePolicy.INSTANCE));
  for (int i = 0; i < numDocs; ++i) {
    Document doc = new Document();
    doc.add(new StringField("id", Integer.toString(i), Store.YES));
    doc.add(new StoredField("f", TestUtil.randomSimpleString(random())));
    w.addDocument(doc);
  }
  final int deleteCount = TestUtil.nextInt(random(), 5, numDocs);
  for (int i = 0; i < deleteCount; ++i) {
    final int id = random().nextInt(numDocs);
    w.deleteDocuments(new Term("id", Integer.toString(id)));
  }
  w.commit();
  w.close();
  w = new RandomIndexWriter(random(), dir);
  w.forceMerge(TestUtil.nextInt(random(), 1, 3));
  w.commit();
  w.close();
  TestUtil.checkIndex(dir);
  dir.close();
}
项目:search    文件:TestIndexWriterExceptions.java   
/** test a null string value doesn't abort the entire segment */
public void testNullStoredField() throws Exception {
  Directory dir = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
  // add good document
  Document doc = new Document();
  iw.addDocument(doc);
  try {
    // set to null value
    String value = null;
    doc.add(new StoredField("foo", value));
    iw.addDocument(doc);
    fail("didn't get expected exception");
  } catch (IllegalArgumentException expected) {}
  iw.close();
  // make sure we see our good doc
  DirectoryReader r = DirectoryReader.open(dir);
  assertEquals(1, r.numDocs());
  r.close();
  dir.close();
}
项目:search    文件:TestIndexWriterExceptions.java   
/** test a null string value doesn't abort the entire segment */
public void testNullStoredFieldReuse() throws Exception {
  Directory dir = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
  // add good document
  Document doc = new Document();
  Field theField = new StoredField("foo", "hello");
  doc.add(theField);
  iw.addDocument(doc);
  try {
    // set to null value
    theField.setStringValue(null);
    iw.addDocument(doc);
    fail("didn't get expected exception");
  } catch (IllegalArgumentException expected) {}
  iw.close();
  // make sure we see our good doc
  DirectoryReader r = DirectoryReader.open(dir);
  assertEquals(1, r.numDocs());
  r.close();
  dir.close();
}
项目:search    文件:TestIndexWriterExceptions.java   
/** test a null byte[] value doesn't abort the entire segment */
public void testNullStoredBytesField() throws Exception {
  Directory dir = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
  // add good document
  Document doc = new Document();
  iw.addDocument(doc);

  try {
    // set to null value
    byte v[] = null;
    Field theField = new StoredField("foo", v);
    doc.add(theField);
    iw.addDocument(doc);
    fail("didn't get expected exception");
  } catch (NullPointerException expected) {}
  iw.close();
  // make sure we see our good doc
  DirectoryReader r = DirectoryReader.open(dir);
  assertEquals(1, r.numDocs());
  r.close();
  dir.close();
}
项目:search    文件:TestIndexWriterExceptions.java   
/** test a null byte[] value doesn't abort the entire segment */
public void testNullStoredBytesFieldReuse() throws Exception {
  Directory dir = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
  // add good document
  Document doc = new Document();
  Field theField = new StoredField("foo", new BytesRef("hello").bytes);
  doc.add(theField);
  iw.addDocument(doc);
  try {
    // set to null value
    byte v[] = null;
    theField.setBytesValue(v);
    iw.addDocument(doc);
    fail("didn't get expected exception");
  } catch (NullPointerException expected) {}
  iw.close();
  // make sure we see our good doc
  DirectoryReader r = DirectoryReader.open(dir);
  assertEquals(1, r.numDocs());
  r.close();
  dir.close();
}
项目:search    文件:TestIndexWriterExceptions.java   
/** test a null bytesref value doesn't abort the entire segment */
public void testNullStoredBytesRefField() throws Exception {
  Directory dir = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
  // add good document
  Document doc = new Document();
  iw.addDocument(doc);

  try {
    // set to null value
    BytesRef v = null;
    Field theField = new StoredField("foo", v);
    doc.add(theField);
    iw.addDocument(doc);
    fail("didn't get expected exception");
  } catch (IllegalArgumentException expected) {}
  iw.close();
  // make sure we see our good doc
  DirectoryReader r = DirectoryReader.open(dir);
  assertEquals(1, r.numDocs());
  r.close();
  dir.close();
}
项目:search    文件:TestIndexWriterExceptions.java   
/** test a null bytesref value doesn't abort the entire segment */
public void testNullStoredBytesRefFieldReuse() throws Exception {
  Directory dir = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
  // add good document
  Document doc = new Document();
  Field theField = new StoredField("foo", new BytesRef("hello"));
  doc.add(theField);
  iw.addDocument(doc);
  try {
    // set to null value
    BytesRef v = null;
    theField.setBytesValue(v);
    iw.addDocument(doc);
    fail("didn't get expected exception");
  } catch (IllegalArgumentException expected) {}
  iw.close();
  // make sure we see our good doc
  DirectoryReader r = DirectoryReader.open(dir);
  assertEquals(1, r.numDocs());
  r.close();
  dir.close();
}
项目:search    文件:TestTermVectorsWriter.java   
public void testNoAbortOnBadTVSettings() throws Exception {
  Directory dir = newDirectory();
  // Don't use RandomIndexWriter because we want to be sure both docs go to 1 seg:
  IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
  IndexWriter iw = new IndexWriter(dir, iwc);

  Document doc = new Document();
  iw.addDocument(doc);
  FieldType ft = new FieldType(StoredField.TYPE);
  ft.setStoreTermVectors(true);
  ft.freeze();
  doc.add(new Field("field", "value", ft));
  try {
    iw.addDocument(doc);
    fail("should have hit exc");
  } catch (IllegalArgumentException iae) {
    // expected
  }
  IndexReader r = DirectoryReader.open(iw, true);

  // Make sure the exc didn't lose our first document:
  assertEquals(1, r.numDocs());
  iw.close();
  r.close();
  dir.close();
}
项目:semanticvectors    文件:FilePositionDoc.java   
public static Document Document(File f)
     throws java.io.FileNotFoundException {
  Document doc = new Document();
  doc.add(new StoredField("path", f.getPath()));
  doc.add(new StoredField("modified",
                    DateTools.timeToString(f.lastModified(), DateTools.Resolution.MINUTE)));

  //create new FieldType to store term positions (TextField is not sufficiently configurable)
  FieldType ft = new FieldType();
  ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
  ft.setTokenized(true);
  ft.setStoreTermVectors(true);
  ft.setStoreTermVectorPositions(true);
  Field contentsField = new Field("contents", new FileReader(f), ft);

  doc.add(contentsField);
  return doc;
}
项目:SourcererCC    文件:DocumentMaker.java   
public void indexWFMEntry(String word, long frequency) {
// Create the document and fields only once, for no GC
if (wfmEntry == null) {
    wfmEntry = new Document();
    wordField = new StringField("key", word,
                       Field.Store.NO);
    wfmEntry.add(wordField);
    freqField = new StoredField("frequency", frequency);
    wfmEntry.add(freqField);
}
else {
    wordField.setStringValue(word);
    freqField.setLongValue(frequency);
}

       try {
    this.indexWriter.updateDocument(new Term("key", word), wfmEntry);
       } catch (IOException e) {
           logger.error("EXCEPTION caught while indexing document for wfm entry "
                           + word + ":" + frequency);
           e.printStackTrace();
       }
   }
项目:SourcererCC    文件:DocumentMaker.java   
public Document prepareDocumentForFwdIndex(Bag bag) {
    Document document = new Document();
    StringField idField = new StringField("id", bag.getId() + "",
            Field.Store.NO);
    //idField.fieldType().setIndexed(true);
    //idField.fieldType().freeze();
    document.add(idField);

    StringBuilder tokenString = new StringBuilder();
    for (TokenFrequency tf : bag) {
        // System.out.println(tf.getToken().getValue() +
        // ":"+tf.getFrequency());
        tokenString.append(tf.getToken().getValue() + ":" + tf.getFrequency() + "::");
    }
    StoredField strField = new StoredField("tokens", tokenString.toString().trim());
    document.add(strField);
    return document;
}
项目:lire    文件:SiftDocumentBuilder.java   
@Override
public Field[] createDescriptorFields(BufferedImage image) {
    Field[] result = null;
    try {
        // extract features from image:
        List<Feature> features = extractor.computeSiftFeatures(image);
        result = new Field[features.size()];
        int count = 0;
        // create new document:
        for (Iterator<Feature> fit = features.iterator(); fit.hasNext(); ) {
            Feature f = fit.next();
            result[count] = new StoredField(DocumentBuilder.FIELD_NAME_SIFT, f.getByteArrayRepresentation());
            count++;
        }
    } catch (IOException e) {
        logger.severe(e.getMessage());
    }
    return result;
}
项目:lire    文件:SiftDocumentBuilder.java   
public Document createDocument(BufferedImage image, String identifier) {
    Document doc = null;
    try {
        // extract features from image:
        List<Feature> features = extractor.computeSiftFeatures(image);
        // create new document:
        doc = new Document();
        for (Iterator<Feature> fit = features.iterator(); fit.hasNext(); ) {
            Feature f = fit.next();
            // add each feature to the document:
            doc.add(new StoredField(DocumentBuilder.FIELD_NAME_SIFT, f.getByteArrayRepresentation()));
        }
        if (identifier != null)
            doc.add(new StringField(DocumentBuilder.FIELD_NAME_IDENTIFIER, identifier, Field.Store.YES));
    } catch (IOException e) {
        logger.severe(e.getMessage());
    }
    return doc;
}
项目:lire    文件:ChainedDocumentBuilder.java   
public Document createDocument(BufferedImage image, String identifier) throws FileNotFoundException {
    docsCreated = true;
    Document doc = new Document();
    if (identifier != null)
        doc.add(new StoredField(DocumentBuilder.FIELD_NAME_IDENTIFIER, identifier));
    if (builders.size() >= 1) {
        for (DocumentBuilder builder : builders) {
            Field[] fields = builder.createDescriptorFields(image);
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                doc.add(field);
            }
        }
    }
    return doc;
}
项目:lucenelab    文件:AnnotatorTeeSinkFilterExample.java   
@SuppressWarnings("resource")
private static void addDocument(IndexWriter writer, String text) throws IOException {
    final Tokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setReader(new StringReader(text));
    final TeeSinkTokenFilter textStream = new TeeSinkTokenFilter(tokenizer);
    final TokenStream colorsStream = new AnnotatorTokenFilter(
            textStream.newSinkTokenStream(), ColorAnnotator.withDefaultColors());
    final TokenStream animalsStream = new AnnotatorTokenFilter(
            textStream.newSinkTokenStream(), AnimalAnnotator.withDefaultAnimals());

    final Document doc = new Document();
    doc.add(new StoredField(TEXT_FIELD, text));
    doc.add(new TextField(TEXT_FIELD, textStream));
    doc.add(new TextField(COLOR_FIELD, colorsStream));
    doc.add(new TextField(ANIMAL_FIELD, animalsStream));
    writer.addDocument(doc);
}
项目:lucenelab    文件:AnnotatorAnyExample.java   
@SuppressWarnings("resource")
private static void addDocument(IndexWriter writer, String text) throws IOException {
    final Tokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setReader(new StringReader(text));
    final TeeSinkTokenFilter textStream = new TeeSinkTokenFilter(tokenizer);
    final TokenStream colorsStream = new AnyAnnotationTokenFilter(new AnnotatorTokenFilter(
            textStream.newSinkTokenStream(), ColorAnnotator.withDefaultColors()));
    final TokenStream animalsStream = new AnyAnnotationTokenFilter(new AnnotatorTokenFilter(
            textStream.newSinkTokenStream(), AnimalAnnotator.withDefaultAnimals()));

    final Document doc = new Document();
    doc.add(new StoredField(TEXT_FIELD, text));
    doc.add(new TextField(TEXT_FIELD, textStream));
    doc.add(new TextField(COLOR_FIELD, colorsStream));
    doc.add(new TextField(ANIMAL_FIELD, animalsStream));
    writer.addDocument(doc);
}
项目:orientdb-lucene    文件:OLuceneSpatialIndexManager.java   
private Document newGeoDocument(OIdentifiable oIdentifiable, Shape shape) {

    FieldType ft = new FieldType();
    ft.setIndexed(true);
    ft.setStored(true);

    Document doc = new Document();

    doc.add(OLuceneIndexType.createField(RID, oIdentifiable.getIdentity().toString(), Field.Store.YES,
        Field.Index.NOT_ANALYZED_NO_NORMS));
    for (IndexableField f : strategy.createIndexableFields(shape)) {
      doc.add(f);
    }

    doc.add(new StoredField(strategy.getFieldName(), ctx.toString(shape)));

    return doc;
  }
项目:NYBC    文件:StrategyTestCase.java   
protected List<Document> getDocuments(Iterator<SampleData> sampleData) {
  List<Document> documents = new ArrayList<Document>();
  while (sampleData.hasNext()) {
    SampleData data = sampleData.next();
    Document document = new Document();
    document.add(new StringField("id", data.id, Field.Store.YES));
    document.add(new StringField("name", data.name, Field.Store.YES));
    Shape shape = ctx.readShape(data.shape);
    shape = convertShapeFromGetDocuments(shape);
    if (shape != null) {
      for (Field f : strategy.createIndexableFields(shape)) {
        document.add(f);
      }
      if (storeShape)
        document.add(new StoredField(strategy.getFieldName(), ctx.toString(shape)));
    }

    documents.add(document);
  }
  return documents;
}
项目:incubator-blur    文件:BaseSpatialFieldTypeDefinition.java   
@Override
public Iterable<? extends Field> getFieldsForColumn(String family, Column column) {
  synchronized (_strategy) {
    String name = getName(family, column.getName());
    if (!_strategy.getFieldName().equals(name)) {
      throw new RuntimeException("Strategy name and column name do not match.");
    }
    List<Field> fields = new ArrayList<Field>();
    Shape shape = getShape(column);
    checkShape(shape);
    for (Field f : _strategy.createIndexableFields(shape)) {
      fields.add(f);
    }
    fields.add(new StoredField(name, column.getValue()));
    return fields;
  }
}
项目:lqt    文件:LuceneQueryToolTest.java   
@Test
public void testBinaryField() throws IOException, ParseException {
    Directory dir = new RAMDirectory();
    Analyzer analyzer = new StandardAnalyzer();
    IndexWriterConfig config = new IndexWriterConfig(analyzer);
    IndexWriter writer = new IndexWriter(dir, config);
    Document doc = new Document();
    doc.add(new Field("id", "1", StringField.TYPE_STORED));
    doc.add(new Field("binary-field", "ABC".getBytes(Charsets.UTF_8), StoredField.TYPE));
    writer.addDocument(doc);
    writer.close();
    reader = DirectoryReader.open(dir);

    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(bytes);
    LuceneQueryTool lqt = new LuceneQueryTool(reader, out);
    lqt.run(new String[]{"id:1"});
    String result = Joiner.on('\n').join(getOutput(bytes));
    assertTrue(result.contains("0x414243"));  // binary rep of "ABC"
}
项目:Xponents    文件:SolrUtil.java   
/**
 *
 * @param d solr doc
 * @param f field name
 * @return a list of strings for this field from that document.; Or null if
 *         none found.
 */
public static List<String> getStrings(SolrDocument d, String f) {
    List<String> vals = new LinkedList<String>();

    Collection<Object> objlist = d.getFieldValues(f);
    if (objlist == null) {
        return null;
    }

    for (Object o : objlist) {
        if (o instanceof StoredField) {
            vals.add(((StoredField) o).stringValue());
        } else if (o instanceof String) {
            vals.add((String) o);
        } else {
            vals.add(o.toString());
        }
    }
    return vals;
}
项目:Xponents    文件:SolrUtil.java   
/**
 * Get an integer from a record
 */
public static int getInteger(SolrDocument d, String f) {
    Object obj = d.getFieldValue(f);
    if (obj == null) {
        return 0;
    }

    if (obj instanceof StoredField) {
        return ((StoredField) obj).numericValue().intValue();
    } else if (obj instanceof Integer) {
        return ((Integer) obj).intValue();
    } else {
        Integer v = Integer.valueOf(obj.toString());
        return v.intValue();
    }
}
项目:Xponents    文件:SolrUtil.java   
/**
 * get integer value from input document.
 * @param d doc
 * @param f field name
 * @return int
 */
public static int getInteger(SolrInputDocument d, String f){
    Object obj = d.getFieldValue(f);
    if (obj == null) {
        return 0;
    }

    if (obj instanceof StoredField) {
        return ((StoredField) obj).numericValue().intValue();
    } else if (obj instanceof Integer) {
        return ((Integer) obj).intValue();
    } else {
        Integer v = Integer.valueOf(obj.toString());
        return v.intValue();
    }
}
项目:Xponents    文件:SolrUtil.java   
/**
 *
 * Get a double from a record
 */
public static double getDouble(SolrDocument solrDoc, String name) {
    Object obj = solrDoc.getFirstValue(name);
    if (obj == null) {
        return Double.NaN;
    }
    if (obj instanceof StoredField) {
        return ((StoredField) obj).numericValue().floatValue();
    }        
    if (obj instanceof Number) {
        Number number = (Number) obj;
        return number.doubleValue();
    } else {
        return Double.valueOf(obj.toString());
    }
}