Analysis: fields that are `not_analyzed` should automatically default to keyword analyzer, closes #229.
This commit is contained in:
parent
60bd8f34d2
commit
8e4c139c8b
|
@ -30,12 +30,13 @@ import org.apache.lucene.util.Version;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.trove.TIntArrayList;
|
import org.elasticsearch.common.trove.TIntArrayList;
|
||||||
|
import org.elasticsearch.index.analysis.AnalyzerScope;
|
||||||
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kimchy (Shay Banon)
|
* @author kimchy (shay.banon)
|
||||||
*/
|
*/
|
||||||
public class Lucene {
|
public class Lucene {
|
||||||
|
|
||||||
|
@ -43,8 +44,8 @@ public class Lucene {
|
||||||
public static Version ANALYZER_VERSION = VERSION;
|
public static Version ANALYZER_VERSION = VERSION;
|
||||||
public static Version QUERYPARSER_VERSION = VERSION;
|
public static Version QUERYPARSER_VERSION = VERSION;
|
||||||
|
|
||||||
public static final NamedAnalyzer STANDARD_ANALYZER = new NamedAnalyzer("_standard", new StandardAnalyzer(ANALYZER_VERSION));
|
public static final NamedAnalyzer STANDARD_ANALYZER = new NamedAnalyzer("_standard", AnalyzerScope.GLOBAL, new StandardAnalyzer(ANALYZER_VERSION));
|
||||||
public static final NamedAnalyzer KEYWORD_ANALYZER = new NamedAnalyzer("_keyword", new KeywordAnalyzer());
|
public static final NamedAnalyzer KEYWORD_ANALYZER = new NamedAnalyzer("_keyword", AnalyzerScope.GLOBAL, new KeywordAnalyzer());
|
||||||
|
|
||||||
public static final int NO_DOC = -1;
|
public static final int NO_DOC = -1;
|
||||||
|
|
||||||
|
|
|
@ -24,5 +24,6 @@ package org.elasticsearch.index.analysis;
|
||||||
*/
|
*/
|
||||||
public enum AnalyzerScope {
|
public enum AnalyzerScope {
|
||||||
INDEX,
|
INDEX,
|
||||||
INDICES
|
INDICES,
|
||||||
|
GLOBAL
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,4 +92,8 @@ public class NamedAnalyzer extends Analyzer {
|
||||||
@Override public void close() {
|
@Override public void close() {
|
||||||
analyzer.close();
|
analyzer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public String toString() {
|
||||||
|
return "analyzer name[" + name + "], analyzer [" + analyzer + "]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.Fieldable;
|
import org.apache.lucene.document.Fieldable;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.search.*;
|
import org.apache.lucene.search.*;
|
||||||
|
import org.elasticsearch.common.lucene.Lucene;
|
||||||
import org.elasticsearch.common.lucene.search.TermFilter;
|
import org.elasticsearch.common.lucene.search.TermFilter;
|
||||||
import org.elasticsearch.common.xcontent.builder.XContentBuilder;
|
import org.elasticsearch.common.xcontent.builder.XContentBuilder;
|
||||||
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
||||||
|
@ -211,8 +212,16 @@ public abstract class XContentFieldMapper<T> implements FieldMapper<T>, XContent
|
||||||
this.boost = boost;
|
this.boost = boost;
|
||||||
this.omitNorms = omitNorms;
|
this.omitNorms = omitNorms;
|
||||||
this.omitTermFreqAndPositions = omitTermFreqAndPositions;
|
this.omitTermFreqAndPositions = omitTermFreqAndPositions;
|
||||||
this.indexAnalyzer = indexAnalyzer;
|
if (indexAnalyzer == null && !index.isAnalyzed()) {
|
||||||
this.searchAnalyzer = searchAnalyzer;
|
this.indexAnalyzer = Lucene.KEYWORD_ANALYZER;
|
||||||
|
} else {
|
||||||
|
this.indexAnalyzer = indexAnalyzer;
|
||||||
|
}
|
||||||
|
if (searchAnalyzer == null && !index.isAnalyzed()) {
|
||||||
|
this.searchAnalyzer = Lucene.KEYWORD_ANALYZER;
|
||||||
|
} else {
|
||||||
|
this.searchAnalyzer = searchAnalyzer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String name() {
|
@Override public String name() {
|
||||||
|
|
Loading…
Reference in New Issue