本文整理了Java中org.apache.lucene.util.Version
类的一些代码示例,展示了Version
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Version
类的具体详情如下:
包路径:org.apache.lucene.util.Version
类名称:Version
[英]Use by certain classes to match version compatibility across releases of Lucene.
WARNING: When changing the version parameter that you supply to components in Lucene, do not simply change the version at search-time, but instead also adjust your indexing code to match, and re-index.
[中]由某些类使用,以匹配Lucene各个版本的版本兼容性。
警告:更改Lucene中组件的版本参数时,不要在搜索时简单地更改版本,还要调整索引代码以匹配,然后重新索引。
代码示例来源:origin: org.apache.lucene/lucene-core
private static void setDiagnostics(SegmentInfo info, String source, Map<String,String> details) {
Map<String,String> diagnostics = new HashMap<>();
diagnostics.put("source", source);
diagnostics.put("lucene.version", Version.LATEST.toString());
diagnostics.put("os", Constants.OS_NAME);
diagnostics.put("os.arch", Constants.OS_ARCH);
diagnostics.put("os.version", Constants.OS_VERSION);
diagnostics.put("java.version", Constants.JAVA_VERSION);
diagnostics.put("java.vendor", Constants.JAVA_VENDOR);
// On IBM J9 JVM this is better than java.version which is just 1.7.0 (no update level):
diagnostics.put("java.runtime.version", System.getProperty("java.runtime.version", "undefined"));
// Hotspot version, e.g. 2.8 for J9:
diagnostics.put("java.vm.version", System.getProperty("java.vm.version", "undefined"));
diagnostics.put("timestamp", Long.toString(new Date().getTime()));
if (details != null) {
diagnostics.putAll(details);
}
info.setDiagnostics(diagnostics);
}
代码示例来源:origin: org.apache.lucene/lucene-core
/** Expert: Sole constructor. Public for use by custom {@link LeafReader} impls. */
public LeafMetaData(int createdVersionMajor, Version minVersion, Sort sort) {
this.createdVersionMajor = createdVersionMajor;
if (createdVersionMajor > Version.LATEST.major) {
throw new IllegalArgumentException("createdVersionMajor is in the future: " + createdVersionMajor);
}
if (createdVersionMajor < 6) {
throw new IllegalArgumentException("createdVersionMajor must be >= 6, got: " + createdVersionMajor);
}
if (minVersion != null && minVersion.onOrAfter(Version.LUCENE_7_0_0) == false) {
throw new IllegalArgumentException("minVersion must be >= 7.0.0: " + minVersion);
}
if (createdVersionMajor >= 7 && minVersion == null) {
throw new IllegalArgumentException("minVersion must be set when createdVersionMajor is >= 7");
}
this.minVersion = minVersion;
this.sort = sort;
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static Version parse(String toParse, Version defaultValue) {
if (Strings.hasLength(toParse)) {
try {
return Version.parseLeniently(toParse);
} catch (ParseException e) {
// pass to default
}
}
return defaultValue;
}
}
代码示例来源:origin: org.apache.lucene/lucene-core
if (oldest == null || version.onOrAfter(oldest) == false) {
oldest = version;
if (newest == null || version.onOrAfter(newest)) {
newest = version;
versionString = oldest.equals(newest) ? ( "version=" + oldest ) : ("versions=[" + oldest + " .. " + newest + "]");
代码示例来源:origin: org.apache.lucene/lucene-core
CodecUtil.checkIndexHeaderSuffix(input, Long.toString(generation, Character.MAX_RADIX));
Version luceneVersion = Version.fromBits(input.readVInt(), input.readVInt(), input.readVInt());
if (luceneVersion.onOrAfter(Version.LUCENE_6_0_0) == false) {
infos.minSegmentLuceneVersion = Version.fromBits(input.readVInt(), input.readVInt(), input.readVInt());
} else {
if (segmentVersion.onOrAfter(infos.minSegmentLuceneVersion) == false) {
throw new CorruptIndexException("segments file recorded minSegmentLuceneVersion=" + infos.minSegmentLuceneVersion + " but segment=" + info + " has older version=" + segmentVersion, input);
代码示例来源:origin: org.apache.lucene/lucene-analyzers
/** Constructs a {@link StandardTokenizer} filtered by a {@link
StandardFilter}, a {@link LowerCaseFilter}, a {@link StopFilter},
and a {@link SnowballFilter} */
@Override
public TokenStream tokenStream(String fieldName, Reader reader) {
TokenStream result = new StandardTokenizer(matchVersion, reader);
result = new StandardFilter(matchVersion, result);
// remove the possessive 's for english stemmers
if (matchVersion.onOrAfter(Version.LUCENE_31) &&
(name.equals("English") || name.equals("Porter") || name.equals("Lovins")))
result = new EnglishPossessiveFilter(result);
// Use a special lowercase filter for turkish, the stemmer expects it.
if (matchVersion.onOrAfter(Version.LUCENE_31) && name.equals("Turkish"))
result = new TurkishLowerCaseFilter(result);
else
result = new LowerCaseFilter(matchVersion, result);
if (stopSet != null)
result = new StopFilter(matchVersion,
result, stopSet);
result = new SnowballFilter(result, name);
return result;
}
代码示例来源:origin: com.vmware.dcp/dcp-common
private void upgradeIndex(Directory dir) throws IOException {
boolean doUpgrade = false;
IndexWriterConfig iwc = new IndexWriterConfig(null);
CheckIndex chkIndex = new CheckIndex(dir);
try {
for (CheckIndex.Status.SegmentInfoStatus segmentInfo : chkIndex
.checkIndex().segmentInfos) {
if (!segmentInfo.version.equals(Version.LATEST)) {
logInfo("Found Index version %s", segmentInfo.version.toString());
doUpgrade = true;
break;
}
}
} finally {
chkIndex.close();
}
if (doUpgrade) {
logInfo("Upgrading index to %s", Version.LATEST.toString());
new IndexUpgrader(dir, iwc, false).upgrade();
this.indexUpdateTimeMicros = Utils.getNowMicrosUtc();
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
if (result.oldestLuceneSegment().onOrAfter(versionTuple.v2()) == false) {
luceneVersion = result.oldestLuceneSegment();
int expectedPrimaryCount = metaData.index(index).getNumberOfShards();
if (primaryCount == metaData.index(index).getNumberOfShards()) {
updatedVersions.put(index, new Tuple<>(versionEntry.getValue().v1(), versionEntry.getValue().v2().toString()));
} else {
logger.warn("Not updating settings for the index [{}] because upgraded of some primary shards failed - " +
代码示例来源:origin: org.apache.lucene/lucene-core
/**
* Parse the given version number as a constant or dot based version.
* <p>This method allows to use {@code "LUCENE_X_Y"} constant names,
* or version numbers in the format {@code "x.y.z"}.
*
* @lucene.internal
*/
public static Version parseLeniently(String version) throws ParseException {
String versionOrig = version;
version = version.toUpperCase(Locale.ROOT);
switch (version) {
case "LATEST":
case "LUCENE_CURRENT":
return LATEST;
default:
version = version
.replaceFirst("^LUCENE_(\\d+)_(\\d+)_(\\d+)$", "$1.$2.$3")
.replaceFirst("^LUCENE_(\\d+)_(\\d+)$", "$1.$2.0")
.replaceFirst("^LUCENE_(\\d)(\\d)$", "$1.$2.0");
try {
return parse(version);
} catch (ParseException pe) {
ParseException pe2 = new ParseException("failed to parse lenient version string \"" + versionOrig + "\": " + pe.getMessage(), 0);
pe2.initCause(pe);
throw pe2;
}
}
}
代码示例来源:origin: org.apache.lucene/lucene-core
/** Returns if the given segment should be upgraded. The default implementation
* will return {@code !Version.LATEST.equals(si.getVersion())},
* so all segments created with a different version number than this Lucene version will
* get upgraded.
*/
protected boolean shouldUpgradeSegment(SegmentCommitInfo si) {
return !Version.LATEST.equals(si.info.getVersion());
}
代码示例来源:origin: org.apache.lucene/lucene-core
Lucene70SegmentInfoFormat.VERSION_CURRENT,
segmentID, "");
final Version version = Version.fromBits(input.readInt(), input.readInt(), input.readInt());
byte hasMinVersion = input.readByte();
final Version minVersion;
break;
case 1:
minVersion = Version.fromBits(input.readInt(), input.readInt(), input.readInt());
break;
default:
代码示例来源:origin: org.apache.lucene/lucene-analyzers
/**
* Creates
* {@link org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents}
* used to tokenize all the text in the provided {@link Reader}.
*
* @return {@link org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents}
* built from a {@link StandardTokenizer} filtered with
* {@link GreekLowerCaseFilter}, {@link StandardFilter},
* {@link StopFilter}, and {@link GreekStemFilter}
*/
@Override
protected TokenStreamComponents createComponents(String fieldName,
Reader reader) {
final Tokenizer source = new StandardTokenizer(matchVersion, reader);
TokenStream result = new GreekLowerCaseFilter(matchVersion, source);
if (matchVersion.onOrAfter(Version.LUCENE_31))
result = new StandardFilter(matchVersion, result);
result = new StopFilter(matchVersion, result, stopwords);
if (matchVersion.onOrAfter(Version.LUCENE_31))
result = new GreekStemFilter(result);
return new TokenStreamComponents(source, result);
}
}
代码示例来源:origin: vmware/xenon
private void upgradeIndex(Directory dir) throws IOException {
boolean doUpgrade = false;
String lastSegmentsFile = SegmentInfos.getLastCommitSegmentsFileName(dir.listAll());
SegmentInfos sis = SegmentInfos.readCommit(dir, lastSegmentsFile);
for (SegmentCommitInfo commit : sis) {
if (!commit.info.getVersion().equals(Version.LATEST)) {
logInfo("Found Index version %s", commit.info.getVersion().toString());
doUpgrade = true;
break;
}
}
if (doUpgrade) {
logInfo("Upgrading index to %s", Version.LATEST.toString());
IndexWriterConfig iwc = new IndexWriterConfig(null);
new IndexUpgrader(dir, iwc, false).upgrade();
this.writerUpdateTimeMicros = Utils.getNowMicrosUtc();
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
public static Version parseVersion(@Nullable String version, Version defaultVersion, Logger logger) {
if (version == null) {
return defaultVersion;
}
try {
return Version.parse(version);
} catch (ParseException e) {
logger.warn(() -> new ParameterizedMessage("no version match {}, default to {}", version, defaultVersion), e);
return defaultVersion;
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch
private static void checkLucene() {
if (Version.CURRENT.luceneVersion.equals(org.apache.lucene.util.Version.LATEST) == false) {
throw new AssertionError("Lucene version mismatch this version of Elasticsearch requires lucene version ["
+ Version.CURRENT.luceneVersion + "] but the current lucene version is [" + org.apache.lucene.util.Version.LATEST + "]");
}
}
代码示例来源:origin: org.apache.lucene/lucene-core
Lucene62SegmentInfoFormat.VERSION_CURRENT,
segmentID, "");
final Version version = Version.fromBits(input.readInt(), input.readInt(), input.readInt());
代码示例来源:origin: org.apache.lucene/lucene-analyzers
@Override
protected TokenStreamComponents createComponents(String fieldName,
Reader reader) {
if (matchVersion.onOrAfter(Version.LUCENE_36)) {
final Tokenizer source = new StandardTokenizer(matchVersion, reader);
// run the widthfilter first before bigramming, it sometimes combines characters.
TokenStream result = new CJKWidthFilter(source);
result = new LowerCaseFilter(matchVersion, result);
result = new CJKBigramFilter(result);
return new TokenStreamComponents(source, new StopFilter(matchVersion, result, stopwords));
} else {
final Tokenizer source = new CJKTokenizer(reader);
return new TokenStreamComponents(source, new StopFilter(matchVersion, source, stopwords));
}
}
}
代码示例来源:origin: org.apache.lucene/lucene-core
private void messageState() {
if (infoStream.isEnabled("IW") && didMessageState == false) {
didMessageState = true;
infoStream.message("IW", "\ndir=" + directoryOrig + "\n" +
"index=" + segString() + "\n" +
"version=" + Version.LATEST.toString() + "\n" +
config.toString());
final StringBuilder unmapInfo = new StringBuilder(Boolean.toString(MMapDirectory.UNMAP_SUPPORTED));
if (!MMapDirectory.UNMAP_SUPPORTED) {
unmapInfo.append(" (").append(MMapDirectory.UNMAP_NOT_SUPPORTED_REASON).append(")");
}
infoStream.message("IW", "MMapDirectory.UNMAP_SUPPORTED=" + unmapInfo);
}
}
代码示例来源:origin: org.apache.lucene/lucene-core
/** Confirms that the incoming index sort (if any) matches the existing index sort (if any).
* This is unfortunately just best effort, because it could be the old index only has unsorted flushed segments built
* before {@link Version#LUCENE_6_5_0} (flushed segments are sorted in Lucene 7.0). */
private void validateIndexSort() throws CorruptIndexException {
Sort indexSort = config.getIndexSort();
if (indexSort != null) {
for(SegmentCommitInfo info : segmentInfos) {
Sort segmentIndexSort = info.info.getIndexSort();
if (segmentIndexSort != null && indexSort.equals(segmentIndexSort) == false) {
throw new IllegalArgumentException("cannot change previous indexSort=" + segmentIndexSort + " (from segment=" + info + ") to new indexSort=" + indexSort);
} else if (segmentIndexSort == null && info.info.getVersion().onOrAfter(Version.LUCENE_6_5_0)) {
// Flushed segments are not sorted if they were built with a version prior to 6.5.0
throw new CorruptIndexException("segment not sorted with indexSort=" + segmentIndexSort, info.info.toString());
}
}
}
}
代码示例来源:origin: org.apache.lucene/lucene-analyzers-common
/**
* Initialize this factory via a set of key-value pairs.
*/
protected AbstractAnalysisFactory(Map<String,String> args) {
originalArgs = Collections.unmodifiableMap(new HashMap<>(args));
String version = get(args, LUCENE_MATCH_VERSION_PARAM);
if (version == null) {
luceneMatchVersion = Version.LATEST;
} else {
try {
luceneMatchVersion = Version.parseLeniently(version);
} catch (ParseException pe) {
throw new IllegalArgumentException(pe);
}
}
args.remove(CLASS_NAME); // consume the class arg
}
内容来源于网络,如有侵权,请联系作者删除!