本文整理汇总了Java中org.apache.lucene.document.StoredField类的典型用法代码示例。如果您正苦于以下问题:Java StoredField类的具体用法?Java StoredField怎么用?Java StoredField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StoredField类属于org.apache.lucene.document包,在下文中一共展示了StoredField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFields
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
@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;
}
示例2: testNoTokens
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
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));
}
示例3: parseCreateField
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
@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));
}
}
}
示例4: noteToDocument
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
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;
}
示例5: eventToDocument
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
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;
}
示例6: transform
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
@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;
}
示例7: setupIndex
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
@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);
}
示例8: newGeoDocument
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
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;
}
示例9: writeValue
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
@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);
}
示例10: newDoc
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
@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;
}
示例11: newSampleDocument
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
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;
}
示例12: getDocuments
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
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;
}
示例13: generateIndexDocuments
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
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;
}
示例14: testBulkMergeWithDeletes
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
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();
}
示例15: testNullStoredField
import org.apache.lucene.document.StoredField; //导入依赖的package包/类
/** 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();
}