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


Java StringHelper.getVersionComparator方法代码示例

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


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

示例1: testOldVersions

import org.apache.lucene.util.StringHelper; //导入方法依赖的package包/类
/** 
 * Test that we didn't forget to bump the current Constants.LUCENE_MAIN_VERSION.
 * This is important so that we can determine which version of lucene wrote the segment.
 */
public void testOldVersions() throws Exception {
  // first create a little index with the current code and get the version
  Directory currentDir = newDirectory();
  RandomIndexWriter riw = new RandomIndexWriter(random(), currentDir);
  riw.addDocument(new Document());
  riw.close();
  DirectoryReader ir = DirectoryReader.open(currentDir);
  SegmentReader air = (SegmentReader)ir.leaves().get(0).reader();
  String currentVersion = air.getSegmentInfo().info.getVersion();
  assertNotNull(currentVersion); // only 3.0 segments can have a null version
  ir.close();
  currentDir.close();
  
  Comparator<String> comparator = StringHelper.getVersionComparator();
  
  // now check all the old indexes, their version should be < the current version
  for (String name : oldNames) {
    Directory dir = oldIndexDirs.get(name);
    DirectoryReader r = DirectoryReader.open(dir);
    for (AtomicReaderContext context : r.leaves()) {
      air = (SegmentReader) context.reader();
      String oldVersion = air.getSegmentInfo().info.getVersion();
      // TODO: does preflex codec actually set "3.0" here? This is safe to do I think.
      // assertNotNull(oldVersion);
      assertTrue("current Constants.LUCENE_MAIN_VERSION is <= an old index: did you forget to bump it?!",
          oldVersion == null || comparator.compare(oldVersion, currentVersion) < 0);
    }
    r.close();
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:35,代码来源:TestBackwardsCompatibility3x.java

示例2: testOldVersions

import org.apache.lucene.util.StringHelper; //导入方法依赖的package包/类
/** 
 * Test that we didn't forget to bump the current Constants.LUCENE_MAIN_VERSION.
 * This is important so that we can determine which version of lucene wrote the segment.
 */
public void testOldVersions() throws Exception {
  // first create a little index with the current code and get the version
  Directory currentDir = newDirectory();
  RandomIndexWriter riw = new RandomIndexWriter(random(), currentDir);
  riw.addDocument(new Document());
  riw.close();
  DirectoryReader ir = DirectoryReader.open(currentDir);
  SegmentReader air = (SegmentReader)ir.leaves().get(0).reader();
  String currentVersion = air.getSegmentInfo().info.getVersion();
  assertNotNull(currentVersion); // only 3.0 segments can have a null version
  ir.close();
  currentDir.close();
  
  Comparator<String> comparator = StringHelper.getVersionComparator();
  
  // now check all the old indexes, their version should be < the current version
  for (String name : oldNames) {
    Directory dir = oldIndexDirs.get(name);
    DirectoryReader r = DirectoryReader.open(dir);
    for (AtomicReaderContext context : r.leaves()) {
      air = (SegmentReader) context.reader();
      String oldVersion = air.getSegmentInfo().info.getVersion();
      assertNotNull(oldVersion); // only 3.0 segments can have a null version
      assertTrue("current Constants.LUCENE_MAIN_VERSION is <= an old index: did you forget to bump it?!",
          comparator.compare(oldVersion, currentVersion) < 0);
    }
    r.close();
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:34,代码来源:TestBackwardsCompatibility.java


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