當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。