add getOffsetGap to field analyzer
This commit is contained in:
parent
8f7a8dabc1
commit
b315c5f848
|
@ -21,6 +21,7 @@ package org.elasticsearch.index.analysis;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.TokenStream;
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
|
import org.apache.lucene.document.Fieldable;
|
||||||
import org.elasticsearch.common.collect.ImmutableMap;
|
import org.elasticsearch.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -53,6 +54,10 @@ public class FieldNameAnalyzer extends Analyzer {
|
||||||
return getAnalyzer(fieldName).getPositionIncrementGap(fieldName);
|
return getAnalyzer(fieldName).getPositionIncrementGap(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public int getOffsetGap(Fieldable field) {
|
||||||
|
return getAnalyzer(field.name()).getOffsetGap(field);
|
||||||
|
}
|
||||||
|
|
||||||
private Analyzer getAnalyzer(String name) {
|
private Analyzer getAnalyzer(String name) {
|
||||||
Analyzer analyzer = analyzers.get(name);
|
Analyzer analyzer = analyzers.get(name);
|
||||||
if (analyzer != null) {
|
if (analyzer != null) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.TokenStream;
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
|
import org.apache.lucene.document.Fieldable;
|
||||||
import org.elasticsearch.common.collect.ImmutableMap;
|
import org.elasticsearch.common.collect.ImmutableMap;
|
||||||
import org.elasticsearch.common.collect.UnmodifiableIterator;
|
import org.elasticsearch.common.collect.UnmodifiableIterator;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
@ -380,14 +381,57 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SmartIndexNameSearchAnalyzer extends Analyzer {
|
class SmartIndexNameSearchAnalyzer extends Analyzer {
|
||||||
|
|
||||||
private final Analyzer defaultAnalyzer;
|
private final Analyzer defaultAnalyzer;
|
||||||
|
|
||||||
private SmartIndexNameSearchAnalyzer(Analyzer defaultAnalyzer) {
|
SmartIndexNameSearchAnalyzer(Analyzer defaultAnalyzer) {
|
||||||
this.defaultAnalyzer = defaultAnalyzer;
|
this.defaultAnalyzer = defaultAnalyzer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public int getPositionIncrementGap(String fieldName) {
|
||||||
|
int dotIndex = fieldName.indexOf('.');
|
||||||
|
if (dotIndex != -1) {
|
||||||
|
String possibleType = fieldName.substring(0, dotIndex);
|
||||||
|
DocumentMapper possibleDocMapper = mappers.get(possibleType);
|
||||||
|
if (possibleDocMapper != null) {
|
||||||
|
return possibleDocMapper.mappers().searchAnalyzer().getPositionIncrementGap(fieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FieldMappers mappers = fullNameFieldMappers.get(fieldName);
|
||||||
|
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) {
|
||||||
|
return mappers.mapper().searchAnalyzer().getPositionIncrementGap(fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
mappers = indexNameFieldMappers.get(fieldName);
|
||||||
|
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) {
|
||||||
|
return mappers.mapper().searchAnalyzer().getPositionIncrementGap(fieldName);
|
||||||
|
}
|
||||||
|
return defaultAnalyzer.getPositionIncrementGap(fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public int getOffsetGap(Fieldable field) {
|
||||||
|
String fieldName = field.name();
|
||||||
|
int dotIndex = fieldName.indexOf('.');
|
||||||
|
if (dotIndex != -1) {
|
||||||
|
String possibleType = fieldName.substring(0, dotIndex);
|
||||||
|
DocumentMapper possibleDocMapper = mappers.get(possibleType);
|
||||||
|
if (possibleDocMapper != null) {
|
||||||
|
return possibleDocMapper.mappers().searchAnalyzer().getOffsetGap(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FieldMappers mappers = fullNameFieldMappers.get(fieldName);
|
||||||
|
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) {
|
||||||
|
return mappers.mapper().searchAnalyzer().getOffsetGap(field);
|
||||||
|
}
|
||||||
|
|
||||||
|
mappers = indexNameFieldMappers.get(fieldName);
|
||||||
|
if (mappers != null && mappers.mapper() != null && mappers.mapper().searchAnalyzer() != null) {
|
||||||
|
return mappers.mapper().searchAnalyzer().getOffsetGap(field);
|
||||||
|
}
|
||||||
|
return defaultAnalyzer.getOffsetGap(field);
|
||||||
|
}
|
||||||
|
|
||||||
@Override public TokenStream tokenStream(String fieldName, Reader reader) {
|
@Override public TokenStream tokenStream(String fieldName, Reader reader) {
|
||||||
int dotIndex = fieldName.indexOf('.');
|
int dotIndex = fieldName.indexOf('.');
|
||||||
if (dotIndex != -1) {
|
if (dotIndex != -1) {
|
||||||
|
|
Loading…
Reference in New Issue