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


Java IndexOptions类代码示例

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


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

示例1: seek

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
void seek(TermInfo ti, Term term) throws IOException {
  count = 0;
  FieldInfo fi = fieldInfos.fieldInfo(term.field());
  this.indexOptions = (fi != null) ? fi.getIndexOptions() : IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
  currentFieldStoresPayloads = (fi != null) ? fi.hasPayloads() : false;
  if (ti == null) {
    df = 0;
  } else {
    df = ti.docFreq;
    doc = 0;
    freqBasePointer = ti.freqPointer;
    proxBasePointer = ti.proxPointer;
    skipPointer = freqBasePointer + ti.skipOffset;
    freqStream.seek(freqBasePointer);
    haveSkipped = false;
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:SegmentTermDocs.java

示例2: setField

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
@Override
public int setField(FieldInfo fieldInfo) {
  IndexOptions indexOptions = fieldInfo.getIndexOptions();
  fieldHasFreqs = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS) >= 0;
  fieldHasPositions = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
  fieldHasOffsets = indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
  fieldHasPayloads = fieldInfo.hasPayloads();
  skipWriter.setField(fieldHasPositions, fieldHasOffsets, fieldHasPayloads);
  lastState = emptyState;
  if (fieldHasPositions) {
    if (fieldHasPayloads || fieldHasOffsets) {
      return 3;  // doc + pos + pay FP
    } else {
      return 2;  // doc + pos FP
    }
  } else {
    return 1;    // doc FP
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:Lucene41PostingsWriter.java

示例3: testOmitTF

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
/** make sure all sims work if TF is omitted */
public void testOmitTF() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
  ft.setIndexOptions(IndexOptions.DOCS_ONLY);
  ft.freeze();
  Field f = newField("foo", "bar", ft);
  doc.add(f);
  iw.addDocument(doc);
  IndexReader ir = iw.getReader();
  iw.close();
  IndexSearcher is = newSearcher(ir);
  
  for (Similarity sim : sims) {
    is.setSimilarity(sim);
    BooleanQuery query = new BooleanQuery(true);
    query.add(new TermQuery(new Term("foo", "bar")), BooleanClause.Occur.SHOULD);
    assertEquals(1, is.search(query, 10).totalHits);
  }
  ir.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:TestSimilarity2.java

示例4: testChangeIndexOptions

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
public void testChangeIndexOptions() throws Exception {
  Directory dir = newDirectory();
  IndexWriter w = new IndexWriter(dir,
                                  new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));

  FieldType docsAndFreqs = new FieldType(TextField.TYPE_NOT_STORED);
  docsAndFreqs.setIndexOptions(IndexOptions.DOCS_AND_FREQS);

  FieldType docsOnly = new FieldType(TextField.TYPE_NOT_STORED);
  docsOnly.setIndexOptions(IndexOptions.DOCS_ONLY);

  Document doc = new Document();
  doc.add(new Field("field", "a b c", docsAndFreqs));
  w.addDocument(doc);
  w.addDocument(doc);

  doc = new Document();
  doc.add(new Field("field", "a b c", docsOnly));
  w.addDocument(doc);
  w.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:TestIndexWriter.java

示例5: SeedPostings

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
public SeedPostings(long seed, int minDocFreq, int maxDocFreq, Bits liveDocs, IndexOptions options) {
  random = new Random(seed);
  docRandom = new Random(random.nextLong());
  docFreq = TestUtil.nextInt(random, minDocFreq, maxDocFreq);
  this.liveDocs = liveDocs;

  // TODO: more realistic to inversely tie this to numDocs:
  maxDocSpacing = TestUtil.nextInt(random, 1, 100);

  if (random.nextInt(10) == 7) {
    // 10% of the time create big payloads:
    payloadSize = 1 + random.nextInt(3);
  } else {
    payloadSize = 1 + random.nextInt(1);
  }

  fixedPayloads = random.nextBoolean();
  byte[] payloadBytes = new byte[payloadSize];
  payload = new BytesRef(payloadBytes);
  this.options = options;
  doPositions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS.compareTo(options) <= 0;
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:BasePostingsFormatTestCase.java

示例6: getSeedPostings

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
private static SeedPostings getSeedPostings(String term, long seed, boolean withLiveDocs, IndexOptions options) {
  int minDocFreq, maxDocFreq;
  if (term.startsWith("big_")) {
    minDocFreq = RANDOM_MULTIPLIER * 50000;
    maxDocFreq = RANDOM_MULTIPLIER * 70000;
  } else if (term.startsWith("medium_")) {
    minDocFreq = RANDOM_MULTIPLIER * 3000;
    maxDocFreq = RANDOM_MULTIPLIER * 6000;
  } else if (term.startsWith("low_")) {
    minDocFreq = RANDOM_MULTIPLIER;
    maxDocFreq = RANDOM_MULTIPLIER * 40;
  } else {
    minDocFreq = 1;
    maxDocFreq = 3;
  }

  return new SeedPostings(seed, minDocFreq, maxDocFreq, withLiveDocs ? globalLiveDocs : null, options);
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:BasePostingsFormatTestCase.java

示例7: createFieldType

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
/**
 * Utility method to create a {@link org.apache.lucene.document.FieldType}
 * based on the {@link SchemaField}
 */
public static org.apache.lucene.document.FieldType createFieldType(SchemaField field) {
  if (!field.indexed() && !field.stored()) {
    if (log.isTraceEnabled())
      log.trace("Ignoring unindexed/unstored field: " + field);
    return null;
  }
  org.apache.lucene.document.FieldType newType = new org.apache.lucene.document.FieldType();
  newType.setIndexed(field.indexed());
  newType.setTokenized(field.isTokenized());
  newType.setStored(field.stored());
  newType.setOmitNorms(field.omitNorms());
  IndexOptions options = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
  if (field.omitTermFreqAndPositions()) {
    options = IndexOptions.DOCS_ONLY;
  } else if (field.omitPositions()) {
    options = IndexOptions.DOCS_AND_FREQS;
  } else if (field.storeOffsetsWithPositions()) {
    options = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
  }
  newType.setIndexOptions(options);
  newType.setStoreTermVectors(field.storeTermVector());
  newType.setStoreTermVectorOffsets(field.storeTermOffsets());
  newType.setStoreTermVectorPositions(field.storeTermPositions());
  return newType;
}
 
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:PreAnalyzedField.java

示例8: testTerms

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
private void testTerms(final Fields fieldsSource, final EnumSet<Option> options,
                       final IndexOptions maxTestOptions,
                       final IndexOptions maxIndexOptions,
                       final boolean alwaysTestMax) throws Exception {

  if (options.contains(Option.THREADS)) {
    int numThreads = TestUtil.nextInt(random(), 2, 5);
    Thread[] threads = new Thread[numThreads];
    for(int threadUpto=0;threadUpto<numThreads;threadUpto++) {
      threads[threadUpto] = new TestThread(this, fieldsSource, options, maxTestOptions, maxIndexOptions, alwaysTestMax);
      threads[threadUpto].start();
    }
    for(int threadUpto=0;threadUpto<numThreads;threadUpto++) {
      threads[threadUpto].join();
    }
  } else {
    testTermsOneThread(fieldsSource, options, maxTestOptions, maxIndexOptions, alwaysTestMax);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:BasePostingsFormatTestCase.java

示例9: testBasic

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
public void testBasic() throws Exception {   
  Directory dir = newDirectory();
  RandomIndexWriter w = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
  ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
  Field f = newField("foo", "this is a test test", ft);
  doc.add(f);
  for (int i = 0; i < 100; i++) {
    w.addDocument(doc);
  }
  
  IndexReader reader = w.getReader();
  w.close();
  
  assertNull(MultiFields.getTermPositionsEnum(reader, null, "foo", new BytesRef("test")));
  
  DocsEnum de = TestUtil.docs(random(), reader, "foo", new BytesRef("test"), null, null, DocsEnum.FLAG_FREQS);
  while (de.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
    assertEquals(2, de.freq());
  }
  
  reader.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:TestOmitPositions.java

示例10: decodeMetaData

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
private void decodeMetaData() {
  if (!didDecode) {
    buffer.reset(current.output.bytes, current.output.offset, current.output.length);
    docFreq = buffer.readVInt();
    if (field.getIndexOptions() != IndexOptions.DOCS_ONLY) {
      totalTermFreq = docFreq + buffer.readVLong();
    } else {
      totalTermFreq = -1;
    }
    postingsSpare.bytes = current.output.bytes;
    postingsSpare.offset = buffer.getPosition();
    postingsSpare.length = current.output.length - (buffer.getPosition() - current.output.offset);
    //System.out.println("  df=" + docFreq + " totTF=" + totalTermFreq + " offset=" + buffer.getPosition() + " len=" + current.output.length);
    didDecode = true;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:MemoryPostingsFormat.java

示例11: docsAndPositions

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
@Override
public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) {

  boolean hasOffsets = field.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
  if (field.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
    return null;
  }
  decodeMetaData();
  FSTDocsAndPositionsEnum docsAndPositionsEnum;
  if (reuse == null || !(reuse instanceof FSTDocsAndPositionsEnum)) {
    docsAndPositionsEnum = new FSTDocsAndPositionsEnum(field.hasPayloads(), hasOffsets);
  } else {
    docsAndPositionsEnum = (FSTDocsAndPositionsEnum) reuse;        
    if (!docsAndPositionsEnum.canReuse(field.hasPayloads(), hasOffsets)) {
      docsAndPositionsEnum = new FSTDocsAndPositionsEnum(field.hasPayloads(), hasOffsets);
    }
  }
  //System.out.println("D&P reset this=" + this);
  return docsAndPositionsEnum.reset(postingsSpare, liveDocs, docFreq);
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:MemoryPostingsFormat.java

示例12: testStats

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
/** test that when freqs are omitted, that totalTermFreq and sumTotalTermFreq are -1 */
public void testStats() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir,
      newIndexWriterConfig(new MockAnalyzer(random())));
  Document doc = new Document();
  FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
  ft.setIndexOptions(IndexOptions.DOCS_ONLY);
  ft.freeze();
  Field f = newField("foo", "bar", ft);
  doc.add(f);
  iw.addDocument(doc);
  IndexReader ir = iw.getReader();
  iw.close();
  assertEquals(-1, ir.totalTermFreq(new Term("foo", new BytesRef("bar"))));
  assertEquals(-1, ir.getSumTotalTermFreq("foo"));
  ir.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestOmitTf.java

示例13: startDoc

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
@Override
public void startDoc(int docID, int termDocFreq) throws IOException {
  if (!wroteTerm) {
    // we lazily do this, in case the term had zero docs
    write(TERM);
    write(term);
    newline();
    wroteTerm = true;
  }

  write(DOC);
  write(Integer.toString(docID));
  newline();
  if (indexOptions != IndexOptions.DOCS_ONLY) {
    write(FREQ);
    write(Integer.toString(termDocFreq));
    newline();
  }

  lastStartOffset = 0;
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:SimpleTextFieldsWriter.java

示例14: docsAndPositions

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
@Override
public DocsAndPositionsEnum docsAndPositions(Bits liveDocs, DocsAndPositionsEnum reuse, int flags) throws IOException {

  if (indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) < 0) {
    // Positions were not indexed
    return null;
  }

  SimpleTextDocsAndPositionsEnum docsAndPositionsEnum;
  if (reuse != null && reuse instanceof SimpleTextDocsAndPositionsEnum && ((SimpleTextDocsAndPositionsEnum) reuse).canReuse(SimpleTextFieldsReader.this.in)) {
    docsAndPositionsEnum = (SimpleTextDocsAndPositionsEnum) reuse;
  } else {
    docsAndPositionsEnum = new SimpleTextDocsAndPositionsEnum();
  } 
  return docsAndPositionsEnum.reset(docsStart, liveDocs, indexOptions, docFreq);
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:SimpleTextFieldsReader.java

示例15: checkTokens

import org.apache.lucene.index.FieldInfo.IndexOptions; //导入依赖的package包/类
private void checkTokens(Token[] tokens) throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter riw = new RandomIndexWriter(random(), dir, iwc);
  boolean success = false;
  try {
    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
    ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
    // store some term vectors for the checkindex cross-check
    ft.setStoreTermVectors(true);
    ft.setStoreTermVectorPositions(true);
    ft.setStoreTermVectorOffsets(true);
   
    Document doc = new Document();
    doc.add(new Field("body", new CannedTokenStream(tokens), ft));
    riw.addDocument(doc);
    success = true;
  } finally {
    if (success) {
      IOUtils.close(riw, dir);
    } else {
      IOUtils.closeWhileHandlingException(riw, dir);
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:TestPostingsOffsets.java


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