当前位置: 首页>>代码示例>>Java>>正文


Java Store类代码示例

本文整理汇总了Java中org.apache.lucene.document.Field.Store的典型用法代码示例。如果您正苦于以下问题:Java Store类的具体用法?Java Store怎么用?Java Store使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Store类属于org.apache.lucene.document.Field包,在下文中一共展示了Store类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
@BeforeClass
public static void setup() throws IOException {
    dir = newDirectory();
    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
    final int numDocs = TestUtil.nextInt(random(), 1, 20);
    for (int i = 0; i < numDocs; ++i) {
        final int numHoles = random().nextInt(5);
        for (int j = 0; j < numHoles; ++j) {
            w.addDocument(new Document());
        }
        Document doc = new Document();
        doc.add(new StringField("foo", "bar", Store.NO));
        w.addDocument(doc);
    }
    reader = w.getReader();
    w.close();
    Engine.Searcher engineSearcher = new Engine.Searcher("test", new IndexSearcher(reader));
    searcher = new ContextIndexSearcher(engineSearcher, IndexSearcher.getDefaultQueryCache(), MAYBE_CACHE_POLICY);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:QueryProfilerTests.java

示例2: addToDoc

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
void addToDoc(Document doc, String... values){
  Preconditions.checkArgument(valueType == String.class);
  if (isSorted()) {
    Preconditions.checkArgument(values.length < 2, "sorted fields cannot have multiple values");
  }

  // add distinct elements to doc
  final Iterable<String> nonNull = FluentIterable.from(Arrays.asList(values))
      .filter(new Predicate<String>() {
        @Override
        public boolean apply(@Nullable final String input) {
          return input != null;
        }
      });

  for (final String value : ImmutableSet.copyOf(nonNull)) {
    final String truncatedValue = StringUtils.abbreviate(value, MAX_STRING_LENGTH);
    doc.add(new StringField(indexFieldName, truncatedValue, stored ? Store.YES : Store.NO));
  }

  if (isSorted() && values.length == 1) {
    Preconditions.checkArgument(sortedValueType == SearchFieldSorting.FieldType.STRING);
    doc.add(new SortedDocValuesField(indexFieldName, new BytesRef(values[0])));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:26,代码来源:IndexKey.java

示例3: run

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
@Override
public void run() {
  try {
    for (int i = 0; i < 10000; ++i) {
      final Document document = new Document();
      final String key = "key" + i;
      final String val = "value" + i;
      document.add(new StringField(key, val, Field.Store.YES));
      document.add(new SortedDocValuesField(key, new BytesRef(val.getBytes())));
      index.add(document);
      data.put(key, val);
      sleep(1);
    }
  } catch (InterruptedException e) {
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:TestLuceneIndexer.java

示例4: initializeProfanitySet

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
/**
 * Initializes profanity set.
 * 
 * @param dictFilePath
 *          dictionary file path
 */
private void initializeProfanitySet(String dictFilePath) {
  if (dictFilePath != null) {
    File file = new File(dictFilePath);
    if (file.exists() && file.isFile()) {
      try {
        IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, analyzer);
        IndexWriter indexWriter = new IndexWriter(directory, config);
        BufferedReader reader = new BufferedReader(new FileReader(file));
        Set<String> bannedWords = new HashSet<String>();
        String line = null;
        while ((line = reader.readLine()) != null) {
          bannedWords.add(line.trim());
          Document doc = new Document();
          doc.add(new StringField(LUCENE_FIELD_NAME, line, Store.NO));
          indexWriter.addDocument(doc);
        }
        this.bannedWords = bannedWords;
        indexWriter.close();
        reader.close();
      } catch (Exception ex) {
        LOG.error("Error reading file", ex);
      }
    }
  }
}
 
开发者ID:sematext,项目名称:related-searches,代码行数:32,代码来源:AbstractProfanityRemovingOutputWriter.java

示例5: initFieldTypes

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
/**
 * initialzie field list
 * @param target target class
 */
@SuppressWarnings("unchecked")
protected void initFieldTypes(Class<T> target) {
	this.target = target;

	List<String> fieldNames = new ArrayList<String>();
	List<Class<? extends Field>> fieldTypes = new ArrayList<Class<? extends Field>>();
	List<Store> stores = new ArrayList<Store>();
	List<Boolean> isMultiples = new ArrayList<Boolean>();

	initList("", target, fieldNames, fieldTypes, stores, isMultiples, null);

	this.fieldNames = fieldNames.toArray(new String[0]);
	this.fieldTypes = fieldTypes.toArray(new Class[0]);
	this.stores = stores.toArray(new Store[0]);
	this.isMultiples = isMultiples.toArray(new Boolean[0]);

	this.fieldTypeEnums = new FieldEnum[fieldTypes.size()];
	for(int i=0;i<fieldTypes.size();i++) {
		this.fieldTypeEnums[i] = FieldEnum.valueOf(fieldTypes.get(i).getSimpleName());
	}
	this.fieldsIndex = new HashMap<String, Integer>();
	for(int i=0;i<fieldNames.size();i++) {
		this.fieldsIndex.put(fieldNames.get(i), i);
	}
}
 
开发者ID:ksgwr,项目名称:LuceneDB,代码行数:30,代码来源:LuceneObjectValuesDB.java

示例6: index

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
/** Build the example index. */
private void index() throws IOException {
  IndexWriter indexWriter = new IndexWriter(indexDir, new IndexWriterConfig(FacetExamples.EXAMPLES_VER, 
      new WhitespaceAnalyzer()));

  // Writes facet ords to a separate directory from the main index
  DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);

  Document doc = new Document();
  doc.add(new TextField("c", "foo bar", Store.NO));
  doc.add(new NumericDocValuesField("popularity", 5L));
  doc.add(new FacetField("A", "B"));
  indexWriter.addDocument(config.build(taxoWriter, doc));

  doc = new Document();
  doc.add(new TextField("c", "foo foo bar", Store.NO));
  doc.add(new NumericDocValuesField("popularity", 3L));
  doc.add(new FacetField("A", "C"));
  indexWriter.addDocument(config.build(taxoWriter, doc));
  
  indexWriter.close();
  taxoWriter.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:ExpressionAggregationFacetsExample.java

示例7: testIndexedBit

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
public void testIndexedBit() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter w = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  FieldType onlyStored = new FieldType();
  onlyStored.setStored(true);
  doc.add(new Field("field", "value", onlyStored));
  doc.add(new StringField("field2", "value", Field.Store.YES));
  w.addDocument(doc);
  IndexReader r = w.getReader();
  w.close();
  assertFalse(r.document(0).getField("field").fieldType().indexed());
  assertTrue(r.document(0).getField("field2").fieldType().indexed());
  r.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:BaseStoredFieldsFormatTestCase.java

示例8: testBulkMergeWithDeletes

import org.apache.lucene.document.Field.Store; //导入依赖的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();
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:BaseStoredFieldsFormatTestCase.java

示例9: testDisableImpersonation

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
public void testDisableImpersonation() throws Exception {
  Codec[] oldCodecs = new Codec[] { new Lucene40RWCodec(), new Lucene41RWCodec(), new Lucene42RWCodec() };
  Directory dir = newDirectory();
  IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
  conf.setCodec(oldCodecs[random().nextInt(oldCodecs.length)]);
  IndexWriter writer = new IndexWriter(dir, conf);
  
  Document doc = new Document();
  doc.add(new StringField("f", "bar", Store.YES));
  doc.add(new NumericDocValuesField("n", 18L));
  writer.addDocument(doc);
  
  OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false;
  try {
    writer.close();
    fail("should not have succeeded to impersonate an old format!");
  } catch (UnsupportedOperationException e) {
    writer.rollback();
  } finally {
    OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
  }
  
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:TestCodecs.java

示例10: testUpdateSameDocMultipleTimes

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
public void testUpdateSameDocMultipleTimes() throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
  IndexWriter writer = new IndexWriter(dir, conf);
  
  Document doc = new Document();
  doc.add(new StringField("key", "doc", Store.NO));
  doc.add(new BinaryDocValuesField("bdv", toBytes(5L)));
  writer.addDocument(doc); // flushed document
  writer.commit();
  writer.addDocument(doc); // in-memory document
  
  writer.updateBinaryDocValue(new Term("key", "doc"), "bdv", toBytes(17L)); // update existing field
  writer.updateBinaryDocValue(new Term("key", "doc"), "bdv", toBytes(3L)); // update existing field 2nd time in this commit
  writer.close();
  
  final DirectoryReader reader = DirectoryReader.open(dir);
  final AtomicReader r = SlowCompositeReaderWrapper.wrap(reader);
  BinaryDocValues bdv = r.getBinaryDocValues("bdv");
  for (int i = 0; i < r.maxDoc(); i++) {
    assertEquals(3, getValue(bdv, i));
  }
  reader.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:TestBinaryDocValuesUpdates.java

示例11: testUpdateBinaryDVFieldWithSameNameAsPostingField

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
public void testUpdateBinaryDVFieldWithSameNameAsPostingField() throws Exception {
  // this used to fail because FieldInfos.Builder neglected to update
  // globalFieldMaps.docValueTypes map
  Directory dir = newDirectory();
  IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
  IndexWriter writer = new IndexWriter(dir, conf);
  
  Document doc = new Document();
  doc.add(new StringField("f", "mock-value", Store.NO));
  doc.add(new BinaryDocValuesField("f", toBytes(5L)));
  writer.addDocument(doc);
  writer.commit();
  writer.updateBinaryDocValue(new Term("f", "mock-value"), "f", toBytes(17L));
  writer.close();
  
  DirectoryReader r = DirectoryReader.open(dir);
  BinaryDocValues bdv = r.leaves().get(0).reader().getBinaryDocValues("f");
  assertEquals(17, getValue(bdv, 0));
  r.close();
  
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:TestBinaryDocValuesUpdates.java

示例12: testUpdatesOrder

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
public void testUpdatesOrder() throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
  IndexWriter writer = new IndexWriter(dir, conf);
  
  Document doc = new Document();
  doc.add(new StringField("upd", "t1", Store.NO));
  doc.add(new StringField("upd", "t2", Store.NO));
  doc.add(new BinaryDocValuesField("f1", toBytes(1L)));
  doc.add(new BinaryDocValuesField("f2", toBytes(1L)));
  writer.addDocument(doc);
  writer.updateBinaryDocValue(new Term("upd", "t1"), "f1", toBytes(2L)); // update f1 to 2
  writer.updateBinaryDocValue(new Term("upd", "t1"), "f2", toBytes(2L)); // update f2 to 2
  writer.updateBinaryDocValue(new Term("upd", "t2"), "f1", toBytes(3L)); // update f1 to 3
  writer.updateBinaryDocValue(new Term("upd", "t2"), "f2", toBytes(3L)); // update f2 to 3
  writer.updateBinaryDocValue(new Term("upd", "t1"), "f1", toBytes(4L)); // update f1 to 4 (but not f2)
  writer.close();
  
  DirectoryReader reader = DirectoryReader.open(dir);
  assertEquals(4, getValue(reader.leaves().get(0).reader().getBinaryDocValues("f1"), 0));
  assertEquals(3, getValue(reader.leaves().get(0).reader().getBinaryDocValues("f2"), 0));
  reader.close();
  
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:TestBinaryDocValuesUpdates.java

示例13: testUpdateAllDeletedSegment

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
public void testUpdateAllDeletedSegment() throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
  IndexWriter writer = new IndexWriter(dir, conf);
  
  Document doc = new Document();
  doc.add(new StringField("id", "doc", Store.NO));
  doc.add(new BinaryDocValuesField("f1", toBytes(1L)));
  writer.addDocument(doc);
  writer.addDocument(doc);
  writer.commit();
  writer.deleteDocuments(new Term("id", "doc")); // delete all docs in the first segment
  writer.addDocument(doc);
  writer.updateBinaryDocValue(new Term("id", "doc"), "f1", toBytes(2L));
  writer.close();
  
  DirectoryReader reader = DirectoryReader.open(dir);
  assertEquals(1, reader.leaves().size());
  assertEquals(2L, getValue(reader.leaves().get(0).reader().getBinaryDocValues("f1"), 0));
  reader.close();
  
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:TestBinaryDocValuesUpdates.java

示例14: testUpdateTwoNonexistingTerms

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
public void testUpdateTwoNonexistingTerms() throws Exception {
  Directory dir = newDirectory();
  IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
  IndexWriter writer = new IndexWriter(dir, conf);
  
  Document doc = new Document();
  doc.add(new StringField("id", "doc", Store.NO));
  doc.add(new BinaryDocValuesField("f1", toBytes(1L)));
  writer.addDocument(doc);
  // update w/ multiple nonexisting terms in same field
  writer.updateBinaryDocValue(new Term("c", "foo"), "f1", toBytes(2L));
  writer.updateBinaryDocValue(new Term("c", "bar"), "f1", toBytes(2L));
  writer.close();
  
  DirectoryReader reader = DirectoryReader.open(dir);
  assertEquals(1, reader.leaves().size());
  assertEquals(1L, getValue(reader.leaves().get(0).reader().getBinaryDocValues("f1"), 0));
  reader.close();
  
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:TestBinaryDocValuesUpdates.java

示例15: createIndex

import org.apache.lucene.document.Field.Store; //导入依赖的package包/类
private static Directory createIndex ()
  throws IOException
{
  Directory directory = new RAMDirectory();

  IndexWriter writer = getWriter(directory);

  for (int i = 0; i < 10; i++) {
    Document doc = new Document();
    doc.add(new StringField("foo", String.valueOf(i), Store.YES));
    writer.addDocument(doc);
  }

  writer.commit();
  writer.close();

  return directory;
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TestTryDelete.java


注:本文中的org.apache.lucene.document.Field.Store类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。