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


Java FieldsProducer.close方法代码示例

本文整理汇总了Java中org.apache.lucene.codecs.FieldsProducer.close方法的典型用法代码示例。如果您正苦于以下问题:Java FieldsProducer.close方法的具体用法?Java FieldsProducer.close怎么用?Java FieldsProducer.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.codecs.FieldsProducer的用法示例。


在下文中一共展示了FieldsProducer.close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fieldsProducer

import org.apache.lucene.codecs.FieldsProducer; //导入方法依赖的package包/类
@Override
public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
  FieldsProducer postings = PostingsFormat.forName("Lucene41").fieldsProducer(state);
  if (state.context.context != IOContext.Context.MERGE) {
    FieldsProducer loadedPostings;
    try {
      postings.checkIntegrity();
      loadedPostings = new DirectFields(state, postings, minSkipCount, lowFreqCutoff);
    } finally {
      postings.close();
    }
    return loadedPostings;
  } else {
    // Don't load postings for merge:
    return postings;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:DirectPostingsFormat.java

示例2: testFull

import org.apache.lucene.codecs.FieldsProducer; //导入方法依赖的package包/类
/** Indexes all fields/terms at the specified
 *  IndexOptions, and fully tests at that IndexOptions. */
private void testFull(IndexOptions options, boolean withPayloads) throws Exception {
  File path = createTempDir("testPostingsFormat.testExact");
  Directory dir = newFSDirectory(path);

  // TODO test thread safety of buildIndex too
  FieldsProducer fieldsProducer = buildIndex(dir, options, withPayloads, true);

  testFields(fieldsProducer);

  IndexOptions[] allOptions = IndexOptions.values();
  int maxIndexOption = Arrays.asList(allOptions).indexOf(options);

  for(int i=0;i<=maxIndexOption;i++) {
    testTerms(fieldsProducer, EnumSet.allOf(Option.class), allOptions[i], options, true);
    if (withPayloads) {
      // If we indexed w/ payloads, also test enums w/o accessing payloads:
      testTerms(fieldsProducer, EnumSet.complementOf(EnumSet.of(Option.PAYLOADS)), allOptions[i], options, true);
    }
  }

  fieldsProducer.close();
  dir.close();
  TestUtil.rm(path);
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:BasePostingsFormatTestCase.java

示例3: testRandom

import org.apache.lucene.codecs.FieldsProducer; //导入方法依赖的package包/类
public void testRandom() throws Exception {

    int iters = 5;

    for(int iter=0;iter<iters;iter++) {
      File path = createTempDir("testPostingsFormat");
      Directory dir = newFSDirectory(path);

      boolean indexPayloads = random().nextBoolean();
      // TODO test thread safety of buildIndex too
      FieldsProducer fieldsProducer = buildIndex(dir, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, indexPayloads, false);

      testFields(fieldsProducer);

      // NOTE: you can also test "weaker" index options than
      // you indexed with:
      testTerms(fieldsProducer, EnumSet.allOf(Option.class), IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, false);

      fieldsProducer.close();
      fieldsProducer = null;

      dir.close();
      TestUtil.rm(path);
    }
  }
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:BasePostingsFormatTestCase.java

示例4: fieldsProducer

import org.apache.lucene.codecs.FieldsProducer; //导入方法依赖的package包/类
@Override
public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
  FieldsProducer postings = PostingsFormat.forName("Lucene41").fieldsProducer(state);
  if (state.context.context != IOContext.Context.MERGE) {
    FieldsProducer loadedPostings;
    try {
      loadedPostings = new DirectFields(state, postings, minSkipCount, lowFreqCutoff);
    } finally {
      postings.close();
    }
    return loadedPostings;
  } else {
    // Don't load postings for merge:
    return postings;
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:17,代码来源:DirectPostingsFormat.java

示例5: testFull

import org.apache.lucene.codecs.FieldsProducer; //导入方法依赖的package包/类
/** Indexes all fields/terms at the specified
 *  IndexOptions, and fully tests at that IndexOptions. */
private void testFull(IndexOptions options, boolean withPayloads) throws Exception {
  File path = _TestUtil.getTempDir("testPostingsFormat.testExact");
  Directory dir = newFSDirectory(path);

  // TODO test thread safety of buildIndex too
  FieldsProducer fieldsProducer = buildIndex(dir, options, withPayloads, true);

  testFields(fieldsProducer);

  IndexOptions[] allOptions = IndexOptions.values();
  int maxIndexOption = Arrays.asList(allOptions).indexOf(options);

  for(int i=0;i<=maxIndexOption;i++) {
    testTerms(fieldsProducer, EnumSet.allOf(Option.class), allOptions[i], options, true);
    if (withPayloads) {
      // If we indexed w/ payloads, also test enums w/o accessing payloads:
      testTerms(fieldsProducer, EnumSet.complementOf(EnumSet.of(Option.PAYLOADS)), allOptions[i], options, true);
    }
  }

  fieldsProducer.close();
  dir.close();
  _TestUtil.rmDir(path);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:27,代码来源:BasePostingsFormatTestCase.java

示例6: testRandom

import org.apache.lucene.codecs.FieldsProducer; //导入方法依赖的package包/类
public void testRandom() throws Exception {

    int iters = 5;

    for(int iter=0;iter<iters;iter++) {
      File path = _TestUtil.getTempDir("testPostingsFormat");
      Directory dir = newFSDirectory(path);

      boolean indexPayloads = random().nextBoolean();
      // TODO test thread safety of buildIndex too
      FieldsProducer fieldsProducer = buildIndex(dir, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, indexPayloads, false);

      testFields(fieldsProducer);

      // NOTE: you can also test "weaker" index options than
      // you indexed with:
      testTerms(fieldsProducer, EnumSet.allOf(Option.class), IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, false);

      fieldsProducer.close();
      fieldsProducer = null;

      dir.close();
      _TestUtil.rmDir(path);
    }
  }
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:26,代码来源:BasePostingsFormatTestCase.java

示例7: testFixedPostings

import org.apache.lucene.codecs.FieldsProducer; //导入方法依赖的package包/类
public void testFixedPostings() throws Throwable {
  final int NUM_TERMS = 100;
  final TermData[] terms = new TermData[NUM_TERMS];
  for(int i=0;i<NUM_TERMS;i++) {
    final int[] docs = new int[] {i};
    final String text = Integer.toString(i, Character.MAX_RADIX);
    terms[i] = new TermData(text, docs, null);
  }

  final FieldInfos.Builder builder = new FieldInfos.Builder();

  final FieldData field = new FieldData("field", builder, terms, true, false);
  final FieldData[] fields = new FieldData[] {field};
  final FieldInfos fieldInfos = builder.finish();
  final Directory dir = newDirectory();
  this.write(fieldInfos, dir, fields, true);
  Codec codec = Codec.getDefault();
  final SegmentInfo si = new SegmentInfo(dir, Version.LATEST, SEGMENT, 10000, false, codec, null);

  final FieldsProducer reader = codec.postingsFormat().fieldsProducer(new SegmentReadState(dir, si, fieldInfos, newIOContext(random()), DirectoryReader.DEFAULT_TERMS_INDEX_DIVISOR));

  final Iterator<String> fieldsEnum = reader.iterator();
  String fieldName = fieldsEnum.next();
  assertNotNull(fieldName);
  final Terms terms2 = reader.terms(fieldName);
  assertNotNull(terms2);

  final TermsEnum termsEnum = terms2.iterator(null);

  DocsEnum docsEnum = null;
  for(int i=0;i<NUM_TERMS;i++) {
    final BytesRef term = termsEnum.next();
    assertNotNull(term);
    assertEquals(terms[i].text2, term.utf8ToString());

    // do this twice to stress test the codec's reuse, ie,
    // make sure it properly fully resets (rewinds) its
    // internal state:
    for(int iter=0;iter<2;iter++) {
      docsEnum = TestUtil.docs(random(), termsEnum, null,  docsEnum, DocsEnum.FLAG_NONE);
      assertEquals(terms[i].docs[0], docsEnum.nextDoc());
      assertEquals(DocIdSetIterator.NO_MORE_DOCS, docsEnum.nextDoc());
    }
  }
  assertNull(termsEnum.next());

  for(int i=0;i<NUM_TERMS;i++) {
    assertEquals(termsEnum.seekCeil(new BytesRef(terms[i].text2)), TermsEnum.SeekStatus.FOUND);
  }

  assertFalse(fieldsEnum.hasNext());
  reader.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:55,代码来源:TestCodecs.java

示例8: testFixedPostings

import org.apache.lucene.codecs.FieldsProducer; //导入方法依赖的package包/类
public void testFixedPostings() throws Throwable {
  final int NUM_TERMS = 100;
  final TermData[] terms = new TermData[NUM_TERMS];
  for(int i=0;i<NUM_TERMS;i++) {
    final int[] docs = new int[] {i};
    final String text = Integer.toString(i, Character.MAX_RADIX);
    terms[i] = new TermData(text, docs, null);
  }

  final FieldInfos.Builder builder = new FieldInfos.Builder();

  final FieldData field = new FieldData("field", builder, terms, true, false);
  final FieldData[] fields = new FieldData[] {field};
  final FieldInfos fieldInfos = builder.finish();
  final Directory dir = newDirectory();
  this.write(fieldInfos, dir, fields, true);
  Codec codec = Codec.getDefault();
  final SegmentInfo si = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null, null);

  final FieldsProducer reader = codec.postingsFormat().fieldsProducer(new SegmentReadState(dir, si, fieldInfos, newIOContext(random()), DirectoryReader.DEFAULT_TERMS_INDEX_DIVISOR));

  final Iterator<String> fieldsEnum = reader.iterator();
  String fieldName = fieldsEnum.next();
  assertNotNull(fieldName);
  final Terms terms2 = reader.terms(fieldName);
  assertNotNull(terms2);

  final TermsEnum termsEnum = terms2.iterator(null);

  DocsEnum docsEnum = null;
  for(int i=0;i<NUM_TERMS;i++) {
    final BytesRef term = termsEnum.next();
    assertNotNull(term);
    assertEquals(terms[i].text2, term.utf8ToString());

    // do this twice to stress test the codec's reuse, ie,
    // make sure it properly fully resets (rewinds) its
    // internal state:
    for(int iter=0;iter<2;iter++) {
      docsEnum = _TestUtil.docs(random(), termsEnum, null,  docsEnum, DocsEnum.FLAG_NONE);
      assertEquals(terms[i].docs[0], docsEnum.nextDoc());
      assertEquals(DocIdSetIterator.NO_MORE_DOCS, docsEnum.nextDoc());
    }
  }
  assertNull(termsEnum.next());

  for(int i=0;i<NUM_TERMS;i++) {
    assertEquals(termsEnum.seekCeil(new BytesRef(terms[i].text2)), TermsEnum.SeekStatus.FOUND);
  }

  assertFalse(fieldsEnum.hasNext());
  reader.close();
  dir.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:55,代码来源:TestCodecs.java

示例9: testFixedPostings

import org.apache.lucene.codecs.FieldsProducer; //导入方法依赖的package包/类
public void testFixedPostings() throws Throwable {
  final int NUM_TERMS = 100;
  final TermData[] terms = new TermData[NUM_TERMS];
  for(int i=0;i<NUM_TERMS;i++) {
    final int[] docs = new int[] {i};
    final String text = Integer.toString(i, Character.MAX_RADIX);
    terms[i] = new TermData(text, docs, null);
  }

  final FieldInfos.Builder builder = new FieldInfos.Builder();

  final FieldData field = new FieldData("field", builder, terms, true, false);
  final FieldData[] fields = new FieldData[] {field};
  final FieldInfos fieldInfos = builder.finish();
  final Directory dir = newDirectory();
  this.write(fieldInfos, dir, fields, true);
  Codec codec = Codec.getDefault();
  final SegmentInfo si = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null);

  final FieldsProducer reader = codec.postingsFormat().fieldsProducer(new SegmentReadState(dir, si, fieldInfos, newIOContext(random()), DirectoryReader.DEFAULT_TERMS_INDEX_DIVISOR));

  final Iterator<String> fieldsEnum = reader.iterator();
  String fieldName = fieldsEnum.next();
  assertNotNull(fieldName);
  final Terms terms2 = reader.terms(fieldName);
  assertNotNull(terms2);

  final TermsEnum termsEnum = terms2.iterator(null);

  DocsEnum docsEnum = null;
  for(int i=0;i<NUM_TERMS;i++) {
    final BytesRef term = termsEnum.next();
    assertNotNull(term);
    assertEquals(terms[i].text2, term.utf8ToString());

    // do this twice to stress test the codec's reuse, ie,
    // make sure it properly fully resets (rewinds) its
    // internal state:
    for(int iter=0;iter<2;iter++) {
      docsEnum = _TestUtil.docs(random(), termsEnum, null,  docsEnum, DocsEnum.FLAG_NONE);
      assertEquals(terms[i].docs[0], docsEnum.nextDoc());
      assertEquals(DocIdSetIterator.NO_MORE_DOCS, docsEnum.nextDoc());
    }
  }
  assertNull(termsEnum.next());

  for(int i=0;i<NUM_TERMS;i++) {
    assertEquals(termsEnum.seekCeil(new BytesRef(terms[i].text2)), TermsEnum.SeekStatus.FOUND);
  }

  assertFalse(fieldsEnum.hasNext());
  reader.close();
  dir.close();
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:55,代码来源:TestCodecs.java


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