本文整理汇总了Java中org.apache.solr.schema.FieldType.getIndexAnalyzer方法的典型用法代码示例。如果您正苦于以下问题:Java FieldType.getIndexAnalyzer方法的具体用法?Java FieldType.getIndexAnalyzer怎么用?Java FieldType.getIndexAnalyzer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.schema.FieldType
的用法示例。
在下文中一共展示了FieldType.getIndexAnalyzer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TokenizeText
import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
public TokenizeText(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
super(builder, config, parent, child, context);
this.inputFieldName = getConfigs().getString(config, "inputField");
this.outputFieldName = getConfigs().getString(config, "outputField");
String solrFieldType = getConfigs().getString(config, "solrFieldType");
Config solrLocatorConfig = getConfigs().getConfig(config, "solrLocator");
SolrLocator locator = new SolrLocator(solrLocatorConfig, context);
LOG.debug("solrLocator: {}", locator);
IndexSchema schema = locator.getIndexSchema();
FieldType fieldType = schema.getFieldTypeByName(solrFieldType);
if (fieldType == null) {
throw new MorphlineCompilationException("Missing Solr field type in schema.xml for name: " + solrFieldType, config);
}
this.analyzer = fieldType.getIndexAnalyzer();
Preconditions.checkNotNull(analyzer);
try { // register CharTermAttribute for later (implicit) reuse
this.token = analyzer.tokenStream("content", reader).addAttribute(CharTermAttribute.class);
} catch (IOException e) {
throw new MorphlineCompilationException("Cannot create token stream", config, e);
}
Preconditions.checkNotNull(token);
validateArguments();
}
示例2: create
import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
Object fieldTypeName = params.get(QUERY_ANALYZER);
if (fieldTypeName == null) {
throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
}
FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
if (ft == null) {
throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
}
Analyzer indexAnalyzer = ft.getIndexAnalyzer();
Analyzer queryAnalyzer = ft.getQueryAnalyzer();
int grams = (params.get(NGRAMS) != null)
? Integer.parseInt(params.get(NGRAMS).toString())
: FreeTextSuggester.DEFAULT_GRAMS;
byte separator = (params.get(SEPARATOR) != null)
? params.get(SEPARATOR).toString().getBytes(StandardCharsets.UTF_8)[0]
: FreeTextSuggester.DEFAULT_SEPARATOR;
return new FreeTextSuggester(indexAnalyzer, queryAnalyzer, grams, separator);
}
示例3: testStandardTokenizerVersions
import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
public void testStandardTokenizerVersions() throws Exception {
assertEquals(DEFAULT_VERSION, solrConfig.luceneMatchVersion);
final IndexSchema schema = h.getCore().getLatestSchema();
FieldType type = schema.getFieldType("textDefault");
TokenizerChain ana = (TokenizerChain) type.getIndexAnalyzer();
assertEquals(DEFAULT_VERSION, (ana.getTokenizerFactory()).getLuceneMatchVersion());
assertEquals(DEFAULT_VERSION, (ana.getTokenFilterFactories()[2]).getLuceneMatchVersion());
type = schema.getFieldType("text40");
ana = (TokenizerChain) type.getIndexAnalyzer();
assertEquals(Version.LUCENE_4_0_0_ALPHA, (ana.getTokenizerFactory()).getLuceneMatchVersion());
assertEquals(Version.LUCENE_4_3_0, (ana.getTokenFilterFactories()[2]).getLuceneMatchVersion());
type = schema.getFieldType("textTurkishAnalyzerDefault");
Analyzer ana1 = type.getIndexAnalyzer();
assertTrue(ana1 instanceof TurkishAnalyzer);
assertEquals(DEFAULT_VERSION, ana1.getVersion());
type = schema.getFieldType("textTurkishAnalyzer40");
ana1 = type.getIndexAnalyzer();
assertTrue(ana1 instanceof TurkishAnalyzer);
assertEquals(Version.LUCENE_4_0_0_ALPHA, ana1.getVersion());
}
示例4: selectAnalyzer
import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
private Analyzer selectAnalyzer(FieldType fieldType) {
if(mode == null)
{
return fieldType.getAnalyzer();
}
else if(mode == Mode.INDEX)
{
return fieldType.getIndexAnalyzer();
}
else if(mode == Mode.QUERY)
{
return fieldType.getQueryAnalyzer();
}
else
{
return null;
}
}
示例5: create
import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(@SuppressWarnings("rawtypes") NamedList params, SolrCore core) {
// mandatory parameter
Object fieldTypeName = params.get(QUERY_ANALYZER);
if (fieldTypeName == null) {
throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
}
FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
if (ft == null) {
throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
}
Analyzer indexAnalyzer = ft.getIndexAnalyzer();
Analyzer queryAnalyzer = ft.getQueryAnalyzer();
// optional parameters
String indexPath = params.get(INDEX_PATH) != null ?
params.get(INDEX_PATH).toString() :
DEFAULT_INDEX_PATH;
int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
: AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;
Boolean highlight = params.getBooleanArg(HIGHLIGHT);
if (highlight == null) {
highlight = DEFAULT_HIGHLIGHT;
}
try {
return new SafariInfixSuggester(core.getSolrConfig().luceneMatchVersion,
FSDirectory.open(new File(indexPath)), indexAnalyzer,
queryAnalyzer, minPrefixChars, highlight);
} catch (IOException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
}
示例6: getDictionaryByFieldType
import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
private Dictionary getDictionaryByFieldType(String fieldTypeName) {
FieldType ft = h.getCore().getLatestSchema().getFieldTypeByName(fieldTypeName);
Analyzer a = ft.getIndexAnalyzer();
Assert.assertEquals(a.getClass(), TokenizerChain.class);
TokenizerChain tc = (TokenizerChain) a;
TokenizerFactory tf = tc.getTokenizerFactory();
Assert.assertEquals(tf.getClass(), MMSegTokenizerFactory.class);
MMSegTokenizerFactory mtf = (MMSegTokenizerFactory) tf;
Assert.assertNotNull(mtf.dic);
return mtf.dic;
}
示例7: create
import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
// mandatory parameter
Object fieldTypeName = params.get(QUERY_ANALYZER);
if (fieldTypeName == null) {
throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
}
FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
if (ft == null) {
throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
}
Analyzer indexAnalyzer = ft.getIndexAnalyzer();
Analyzer queryAnalyzer = ft.getQueryAnalyzer();
// optional parameters
String indexPath = params.get(INDEX_PATH) != null
? params.get(INDEX_PATH).toString()
: DEFAULT_INDEX_PATH;
if (new File(indexPath).isAbsolute() == false) {
indexPath = core.getDataDir() + File.separator + indexPath;
}
int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
: AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;
BlenderType blenderType = getBlenderType(params.get(BLENDER_TYPE));
int numFactor = params.get(NUM_FACTOR) != null
? Integer.parseInt(params.get(NUM_FACTOR).toString())
: BlendedInfixSuggester.DEFAULT_NUM_FACTOR;
try {
return new BlendedInfixSuggester(core.getSolrConfig().luceneMatchVersion,
FSDirectory.open(new File(indexPath)),
indexAnalyzer, queryAnalyzer, minPrefixChars,
blenderType, numFactor) {
@Override
public List<LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, int num, boolean allTermsRequired, boolean doHighlight) throws IOException {
List<LookupResult> res = super.lookup(key, contexts, num, allTermsRequired, doHighlight);
if (doHighlight) {
List<LookupResult> res2 = new ArrayList<>();
for(LookupResult hit : res) {
res2.add(new LookupResult(hit.highlightKey.toString(),
hit.highlightKey,
hit.value,
hit.payload,
hit.contexts));
}
res = res2;
}
return res;
}
};
} catch (IOException e) {
throw new RuntimeException();
}
}
示例8: create
import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
// mandatory parameter
Object fieldTypeName = params.get(AnalyzingLookupFactory.QUERY_ANALYZER);
if (fieldTypeName == null) {
throw new IllegalArgumentException("Error in configuration: " + AnalyzingLookupFactory.QUERY_ANALYZER + " parameter is mandatory");
}
// retrieve index and query analyzers for the field
FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
if (ft == null) {
throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
}
Analyzer indexAnalyzer = ft.getIndexAnalyzer();
Analyzer queryAnalyzer = ft.getQueryAnalyzer();
// optional parameters
boolean exactMatchFirst = (params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST) != null)
? Boolean.valueOf(params.get(AnalyzingLookupFactory.EXACT_MATCH_FIRST).toString())
: true;
boolean preserveSep = (params.get(AnalyzingLookupFactory.PRESERVE_SEP) != null)
? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_SEP).toString())
: true;
int options = 0;
if (exactMatchFirst) {
options |= FuzzySuggester.EXACT_FIRST;
}
if (preserveSep) {
options |= FuzzySuggester.PRESERVE_SEP;
}
int maxSurfaceFormsPerAnalyzedForm = (params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS) != null)
? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_SURFACE_FORMS).toString())
: 256;
int maxGraphExpansions = (params.get(AnalyzingLookupFactory.MAX_EXPANSIONS) != null)
? Integer.parseInt(params.get(AnalyzingLookupFactory.MAX_EXPANSIONS).toString())
: -1;
boolean preservePositionIncrements = params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS) != null
? Boolean.valueOf(params.get(AnalyzingLookupFactory.PRESERVE_POSITION_INCREMENTS).toString())
: false;
int maxEdits = (params.get(MAX_EDITS) != null)
? Integer.parseInt(params.get(MAX_EDITS).toString())
: FuzzySuggester.DEFAULT_MAX_EDITS;
boolean transpositions = (params.get(TRANSPOSITIONS) != null)
? Boolean.parseBoolean(params.get(TRANSPOSITIONS).toString())
: FuzzySuggester.DEFAULT_TRANSPOSITIONS;
int nonFuzzyPrefix = (params.get(NON_FUZZY_PREFIX) != null)
? Integer.parseInt(params.get(NON_FUZZY_PREFIX).toString())
:FuzzySuggester.DEFAULT_NON_FUZZY_PREFIX;
int minFuzzyLength = (params.get(MIN_FUZZY_LENGTH) != null)
? Integer.parseInt(params.get(MIN_FUZZY_LENGTH).toString())
:FuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH;
boolean unicodeAware = (params.get(UNICODE_AWARE) != null)
? Boolean.valueOf(params.get(UNICODE_AWARE).toString())
: FuzzySuggester.DEFAULT_UNICODE_AWARE;
return new FuzzySuggester(indexAnalyzer, queryAnalyzer, options, maxSurfaceFormsPerAnalyzedForm,
maxGraphExpansions, preservePositionIncrements, maxEdits, transpositions, nonFuzzyPrefix,
minFuzzyLength, unicodeAware);
}
示例9: create
import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
// mandatory parameter
Object fieldTypeName = params.get(QUERY_ANALYZER);
if (fieldTypeName == null) {
throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
}
FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
if (ft == null) {
throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
}
Analyzer indexAnalyzer = ft.getIndexAnalyzer();
Analyzer queryAnalyzer = ft.getQueryAnalyzer();
// optional parameters
String indexPath = params.get(INDEX_PATH) != null
? params.get(INDEX_PATH).toString()
: DEFAULT_INDEX_PATH;
if (new File(indexPath).isAbsolute() == false) {
indexPath = core.getDataDir() + File.separator + indexPath;
}
int minPrefixChars = params.get(MIN_PREFIX_CHARS) != null
? Integer.parseInt(params.get(MIN_PREFIX_CHARS).toString())
: AnalyzingInfixSuggester.DEFAULT_MIN_PREFIX_CHARS;
try {
return new AnalyzingInfixSuggester(core.getSolrConfig().luceneMatchVersion,
FSDirectory.open(new File(indexPath)), indexAnalyzer,
queryAnalyzer, minPrefixChars) {
@Override
public List<LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, int num, boolean allTermsRequired, boolean doHighlight) throws IOException {
List<LookupResult> res = super.lookup(key, contexts, num, allTermsRequired, doHighlight);
if (doHighlight) {
List<LookupResult> res2 = new ArrayList<>();
for(LookupResult hit : res) {
res2.add(new LookupResult(hit.highlightKey.toString(),
hit.highlightKey,
hit.value,
hit.payload,
hit.contexts));
}
res = res2;
}
return res;
}
};
} catch (IOException e) {
throw new RuntimeException();
}
}
示例10: create
import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
@Override
public Lookup create(NamedList params, SolrCore core) {
// mandatory parameter
Object fieldTypeName = params.get(QUERY_ANALYZER);
if (fieldTypeName == null) {
throw new IllegalArgumentException("Error in configuration: " + QUERY_ANALYZER + " parameter is mandatory");
}
FieldType ft = core.getLatestSchema().getFieldTypeByName(fieldTypeName.toString());
if (ft == null) {
throw new IllegalArgumentException("Error in configuration: " + fieldTypeName.toString() + " is not defined in the schema");
}
Analyzer indexAnalyzer = ft.getIndexAnalyzer();
Analyzer queryAnalyzer = ft.getQueryAnalyzer();
// optional parameters
boolean exactMatchFirst = params.get(EXACT_MATCH_FIRST) != null
? Boolean.valueOf(params.get(EXACT_MATCH_FIRST).toString())
: true;
boolean preserveSep = params.get(PRESERVE_SEP) != null
? Boolean.valueOf(params.get(PRESERVE_SEP).toString())
: true;
int flags = 0;
if (exactMatchFirst) {
flags |= AnalyzingSuggester.EXACT_FIRST;
}
if (preserveSep) {
flags |= AnalyzingSuggester.PRESERVE_SEP;
}
int maxSurfaceFormsPerAnalyzedForm = params.get(MAX_SURFACE_FORMS) != null
? Integer.parseInt(params.get(MAX_SURFACE_FORMS).toString())
: 256;
int maxGraphExpansions = params.get(MAX_EXPANSIONS) != null
? Integer.parseInt(params.get(MAX_EXPANSIONS).toString())
: -1;
boolean preservePositionIncrements = params.get(PRESERVE_POSITION_INCREMENTS) != null
? Boolean.valueOf(params.get(PRESERVE_POSITION_INCREMENTS).toString())
: false;
return new AnalyzingSuggester(indexAnalyzer, queryAnalyzer, flags, maxSurfaceFormsPerAnalyzedForm,
maxGraphExpansions, preservePositionIncrements);
}