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


Java Version类代码示例

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


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

示例1: incrementToken

import org.apache.lucene.util.Version; //导入依赖的package包/类
@Override
public boolean incrementToken() throws IOException {
  if (!input.incrementToken()) {
    return false;
  }
  
  final char[] buffer = termAtt.buffer();
  final int bufferLength = termAtt.length();
  
  if (bufferLength >= 2 && 
      (buffer[bufferLength-2] == '\'' || 
       (matchVersion.onOrAfter(Version.LUCENE_3_6) && (buffer[bufferLength-2] == '\u2019' || buffer[bufferLength-2] == '\uFF07'))) &&
      (buffer[bufferLength-1] == 's' || buffer[bufferLength-1] == 'S')) {
    termAtt.setLength(bufferLength - 2); // Strip last 2 characters off
  }

  return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:EnglishPossessiveFilter.java

示例2: FbEntitySearcher

import org.apache.lucene.util.Version; //导入依赖的package包/类
public FbEntitySearcher(String indexDir, int numOfDocs, String searchingStrategy) throws IOException {

    LogInfo.begin_track("Constructing Searcher");
    if (!searchingStrategy.equals("exact") && !searchingStrategy.equals("inexact"))
      throw new RuntimeException("Bad searching strategy: " + searchingStrategy);
    this.searchStrategy = searchingStrategy;

    queryParser = new QueryParser(
        Version.LUCENE_44,
        FbIndexField.TEXT.fieldName(),
        searchingStrategy.equals("exact") ? new KeywordAnalyzer() : new StandardAnalyzer(Version.LUCENE_44));
    LogInfo.log("Opening index dir: " + indexDir);
    IndexReader indexReader = DirectoryReader.open(SimpleFSDirectory.open(new File(indexDir)));
    indexSearcher = new IndexSearcher(indexReader);
    LogInfo.log("Opened index with " + indexReader.numDocs() + " documents.");

    this.numOfDocs = numOfDocs;
    LogInfo.end_track();
  }
 
开发者ID:cgraywang,项目名称:TextHIN,代码行数:20,代码来源:FbEntitySearcher.java

示例3: parse

import org.apache.lucene.util.Version; //导入依赖的package包/类
/**
 * @deprecated Use {@link #parse(String, String[], BooleanClause.Occur[], Analyzer)}
 */
@Deprecated
public static Query parse(Version matchVersion, String query, String[] fields,
      BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException {
  if (fields.length != flags.length)
    throw new IllegalArgumentException("fields.length != flags.length");
  BooleanQuery bQuery = new BooleanQuery();
  for (int i = 0; i < fields.length; i++) {
    QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
    Query q = qp.parse(query);
    if (q!=null && // q never null, just being defensive 
        (!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length>0)) {
      bQuery.add(q, flags[i]);
    }
  }
  return bQuery;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:MultiFieldQueryParser.java

示例4: checksumFromLuceneFile

import org.apache.lucene.util.Version; //导入依赖的package包/类
private static void checksumFromLuceneFile(Directory directory, String file, ImmutableMap.Builder<String, StoreFileMetaData> builder, ESLogger logger, Version version, boolean readFileAsHash) throws IOException {
    final String checksum;
    final BytesRefBuilder fileHash = new BytesRefBuilder();
    try (final IndexInput in = directory.openInput(file, IOContext.READONCE)) {
        final long length;
        try {
            length = in.length();
            if (length < CodecUtil.footerLength()) {
                // truncated files trigger IAE if we seek negative... these files are really corrupted though
                throw new CorruptIndexException("Can't retrieve checksum from file: " + file + " file length must be >= " + CodecUtil.footerLength() + " but was: " + in.length(), in);
            }
            if (readFileAsHash) {
                final VerifyingIndexInput verifyingIndexInput = new VerifyingIndexInput(in); // additional safety we checksum the entire file we read the hash for...
                hashFile(fileHash, new InputStreamIndexInput(verifyingIndexInput, length), length);
                checksum = digestToString(verifyingIndexInput.verify());
            } else {
                checksum = digestToString(CodecUtil.retrieveChecksum(in));
            }

        } catch (Throwable ex) {
            logger.debug("Can retrieve checksum from file [{}]", ex, file);
            throw ex;
        }
        builder.put(file, new StoreFileMetaData(file, length, checksum, version, fileHash.get()));
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:27,代码来源:Store.java

示例5: inform

import org.apache.lucene.util.Version; //导入依赖的package包/类
@Override
public void inform(ResourceLoader loader) throws IOException {
  InputStream stream = null;
  try {
    if (dictFile != null) // the dictionary can be empty.
      dictionary = getWordSet(loader, dictFile, false);
    // TODO: Broken, because we cannot resolve real system id
    // ResourceLoader should also supply method like ClassLoader to get resource URL
    stream = loader.openResource(hypFile);
    final InputSource is = new InputSource(stream);
    is.setEncoding(encoding); // if it's null let xml parser decide
    is.setSystemId(hypFile);
    if (luceneMatchVersion.onOrAfter(Version.LUCENE_4_4_0)) {
      hyphenator = HyphenationCompoundWordTokenFilter.getHyphenationTree(is);
    } else {
      hyphenator = Lucene43HyphenationCompoundWordTokenFilter.getHyphenationTree(is);
    }
  } finally {
    IOUtils.closeWhileHandlingException(stream);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:HyphenationCompoundWordTokenFilterFactory.java

示例6: init

import org.apache.lucene.util.Version; //导入依赖的package包/类
private void init(Version version, int minGram, int maxGram, boolean edgesOnly) {
  if (!version.onOrAfter(Version.LUCENE_4_4_0)) {
    throw new IllegalArgumentException("This class only works with Lucene 4.4+. To emulate the old (broken) behavior of NGramTokenizer, use Lucene43NGramTokenizer/Lucene43EdgeNGramTokenizer");
  }
  charUtils = version.onOrAfter(Version.LUCENE_4_4_0)
      ? CharacterUtils.getInstance(version)
      : CharacterUtils.getJava4Instance();
  if (minGram < 1) {
    throw new IllegalArgumentException("minGram must be greater than zero");
  }
  if (minGram > maxGram) {
    throw new IllegalArgumentException("minGram must not be greater than maxGram");
  }
  this.minGram = minGram;
  this.maxGram = maxGram;
  this.edgesOnly = edgesOnly;
  charBuffer = CharacterUtils.newCharacterBuffer(2 * maxGram + 1024); // 2 * maxGram in case all code points require 2 chars and + 1024 for buffering to not keep polling the Reader
  buffer = new int[charBuffer.getBuffer().length];
  // Make the term att large enough
  termAtt.resizeBuffer(2 * maxGram);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:NGramTokenizer.java

示例7: KeepWordFilterFactory

import org.apache.lucene.util.Version; //导入依赖的package包/类
@Inject
public KeepWordFilterFactory(Index index, IndexSettingsService indexSettingsService,
                             Environment env, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);

    final String[] arrayKeepWords = settings.getAsArray(KEEP_WORDS_KEY, null);
    final String keepWordsPath = settings.get(KEEP_WORDS_PATH_KEY, null);
    if ((arrayKeepWords == null && keepWordsPath == null) || (arrayKeepWords != null && keepWordsPath != null)) {
        // we don't allow both or none
        throw new IllegalArgumentException("keep requires either `" + KEEP_WORDS_KEY + "` or `"
                + KEEP_WORDS_PATH_KEY + "` to be configured");
    }
    if (version.onOrAfter(Version.LUCENE_4_4) && settings.get(ENABLE_POS_INC_KEY) != null) {
        throw new IllegalArgumentException(ENABLE_POS_INC_KEY + " is not supported anymore. Please fix your analysis chain or use"
                + " an older compatibility version (<=4.3) but beware that it might cause highlighting bugs.");
    }
    enablePositionIncrements = version.onOrAfter(Version.LUCENE_4_4) ? true : settings.getAsBoolean(ENABLE_POS_INC_KEY, true);

    this.keepWords = Analysis.getWordSet(env, settings, KEEP_WORDS_KEY);

}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:KeepWordFilterFactory.java

示例8: PortugueseAnalyzer

import org.apache.lucene.util.Version; //导入依赖的package包/类
/**
 * @deprecated Use {@link #PortugueseAnalyzer(CharArraySet, CharArraySet)}
 */
@Deprecated
public PortugueseAnalyzer(Version matchVersion, CharArraySet stopwords, CharArraySet stemExclusionSet) {
  super(matchVersion, stopwords);
  this.stemExclusionSet = CharArraySet.unmodifiableSet(CharArraySet.copy(
      matchVersion, stemExclusionSet));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:PortugueseAnalyzer.java

示例9: parseAnalysisVersion

import org.apache.lucene.util.Version; //导入依赖的package包/类
public static Version parseAnalysisVersion(Settings indexSettings, Settings settings, Logger logger) {
    // check for explicit version on the specific analyzer component
    String sVersion = settings.get("version");
    if (sVersion != null) {
        return Lucene.parseVersion(sVersion, Version.LATEST, logger);
    }
    // check for explicit version on the index itself as default for all analysis components
    sVersion = indexSettings.get("index.analysis.version");
    if (sVersion != null) {
        return Lucene.parseVersion(sVersion, Version.LATEST, logger);
    }
    // resolve the analysis version based on the version the index was created with
    return org.elasticsearch.Version.indexCreated(indexSettings).luceneVersion;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:Analysis.java

示例10: getWordSet

import org.apache.lucene.util.Version; //导入依赖的package包/类
public static CharArraySet getWordSet(Environment env, org.elasticsearch.Version indexCreatedVersion, Settings settings,
                                      String settingsPrefix) {
    List<String> wordList = getWordList(env, settings, settingsPrefix);
    if (wordList == null) {
        return null;
    }
    boolean ignoreCase =
        settings.getAsBooleanLenientForPreEs6Indices(indexCreatedVersion, settingsPrefix + "_case", false, deprecationLogger);
    return new CharArraySet(wordList, ignoreCase);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:Analysis.java

示例11: StoreFileMetaData

import org.apache.lucene.util.Version; //导入依赖的package包/类
public StoreFileMetaData(String name, long length, String checksum, Version writtenBy, BytesRef hash) {
    // its possible here to have a _na_ checksum or an unsupported writtenBy version, if the
    // file is a segments_N file, but that is fine in the case of a segments_N file because
    // we handle that case upstream
    assert name.startsWith("segments_") || (writtenBy != null && writtenBy.onOrAfter(FIRST_LUCENE_CHECKSUM_VERSION)) :
        "index version less that " + FIRST_LUCENE_CHECKSUM_VERSION + " are not supported but got: " + writtenBy;
    this.name = Objects.requireNonNull(name, "name must not be null");
    this.length = length;
    this.checksum = Objects.requireNonNull(checksum, "checksum must not be null");
    this.writtenBy = Objects.requireNonNull(writtenBy, "writtenBy must not be null");
    this.hash = hash == null ? new BytesRef() : hash;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:StoreFileMetaData.java

示例12: create

import org.apache.lucene.util.Version; //导入依赖的package包/类
@Override
public TokenStream create(TokenStream tokenStream) {
    if (version.onOrAfter(Version.LUCENE_4_4_0)) {
        return new DictionaryCompoundWordTokenFilter(tokenStream, wordList, minWordSize, 
                                                     minSubwordSize, maxSubwordSize, onlyLongestMatch);
    } else {
        return new Lucene43DictionaryCompoundWordTokenFilter(tokenStream, wordList, minWordSize,
                                                             minSubwordSize, maxSubwordSize, onlyLongestMatch);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:DictionaryCompoundWordTokenFilterFactory.java

示例13: testToFromXContent

import org.apache.lucene.util.Version; //导入依赖的package包/类
public void testToFromXContent() throws IOException {
    final int iters = scaledRandomIntBetween(1, 10);
    for (int iter = 0; iter < iters; iter++) {
        final BytesRef hash = new BytesRef(scaledRandomIntBetween(0, 1024 * 1024));
        hash.length = hash.bytes.length;
        for (int i = 0; i < hash.length; i++) {
            hash.bytes[i] = randomByte();
        }
        StoreFileMetaData meta = new StoreFileMetaData("foobar", Math.abs(randomLong()), randomAsciiOfLengthBetween(1, 10), Version.LATEST, hash);
        ByteSizeValue size = new ByteSizeValue(Math.abs(randomLong()));
        BlobStoreIndexShardSnapshot.FileInfo info = new BlobStoreIndexShardSnapshot.FileInfo("_foobar", meta, size);
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint();
        BlobStoreIndexShardSnapshot.FileInfo.toXContent(info, builder, ToXContent.EMPTY_PARAMS);
        byte[] xcontent = BytesReference.toBytes(shuffleXContent(builder).bytes());

        final BlobStoreIndexShardSnapshot.FileInfo parsedInfo;
        try (XContentParser parser = createParser(JsonXContent.jsonXContent, xcontent)) {
            parser.nextToken();
            parsedInfo = BlobStoreIndexShardSnapshot.FileInfo.fromXContent(parser);
        }
        assertThat(info.name(), equalTo(parsedInfo.name()));
        assertThat(info.physicalName(), equalTo(parsedInfo.physicalName()));
        assertThat(info.length(), equalTo(parsedInfo.length()));
        assertThat(info.checksum(), equalTo(parsedInfo.checksum()));
        assertThat(info.partSize(), equalTo(parsedInfo.partSize()));
        assertThat(parsedInfo.metadata().hash().length, equalTo(hash.length));
        assertThat(parsedInfo.metadata().hash(), equalTo(hash));
        assertThat(parsedInfo.metadata().writtenBy(), equalTo(Version.LATEST));
        assertThat(parsedInfo.isSame(info.metadata()), is(true));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:FileInfoTests.java

示例14: testStoreStats

import org.apache.lucene.util.Version; //导入依赖的package包/类
public void testStoreStats() throws IOException {
    final ShardId shardId = new ShardId("index", "_na_", 1);
    DirectoryService directoryService = new LuceneManagedDirectoryService(random());
    Settings settings = Settings.builder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, org.elasticsearch.Version.CURRENT)
            .put(Store.INDEX_STORE_STATS_REFRESH_INTERVAL_SETTING.getKey(), TimeValue.timeValueMinutes(0)).build();
    Store store = new Store(shardId, IndexSettingsModule.newIndexSettings("index", settings), directoryService, new DummyShardLock(shardId));
    long initialStoreSize = 0;
    for (String extraFiles : store.directory().listAll()) {
        assertTrue("expected extraFS file but got: " + extraFiles, extraFiles.startsWith("extra"));
        initialStoreSize += store.directory().fileLength(extraFiles);
    }
    StoreStats stats = store.stats();
    assertEquals(stats.getSize().getBytes(), initialStoreSize);

    Directory dir = store.directory();
    final long length;
    try (IndexOutput output = dir.createOutput("foo.bar", IOContext.DEFAULT)) {
        int iters = scaledRandomIntBetween(10, 100);
        for (int i = 0; i < iters; i++) {
            BytesRef bytesRef = new BytesRef(TestUtil.randomRealisticUnicodeString(random(), 10, 1024));
            output.writeBytes(bytesRef.bytes, bytesRef.offset, bytesRef.length);
        }
        length = output.getFilePointer();
    }

    assertTrue(numNonExtraFiles(store) > 0);
    stats = store.stats();
    assertEquals(stats.getSizeInBytes(), length + initialStoreSize);

    deleteContent(store.directory());
    IOUtils.close(store);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:StoreTests.java

示例15: create

import org.apache.lucene.util.Version; //导入依赖的package包/类
@Override
public TokenStream create(TokenStream tokenStream) {
    if (version.onOrAfter(Version.LUCENE_4_4)) {
        return new KeepWordFilter(tokenStream, keepWords);
    } else {
        @SuppressWarnings("deprecation")
        final TokenStream filter = new Lucene43KeepWordFilter(enablePositionIncrements, tokenStream, keepWords);
        return filter;
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:KeepWordFilterFactory.java


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