List of usage examples for org.apache.solr.schema IndexSchema getFieldTypes
public Map<String, FieldType> getFieldTypes()
From source file:com.doculibre.constellio.utils.SolrSchemaUtils.java
License:Open Source License
public static void main(String[] args) throws Exception { ConnectorType connectorType = new ConnectorType(); connectorType.setName("mail"); IndexSchema schema = getSchema(connectorType); Map<String, FieldType> fieldTypes = schema.getFieldTypes(); for (String key : fieldTypes.keySet()) { FieldType fieldType = fieldTypes.get(key); System.out.print(key + ":"); System.out.print(fieldType.getClass()); System.out.print("\n"); System.out.print(fieldType.getAnalyzer().getClass()); }/*from w w w .j av a2 s .c o m*/ }
From source file:org.dice.solrenhancements.spellchecker.DiceMultipleCaseSuggester.java
License:Apache License
@Override public String init(NamedList config, SolrCore core) { LOG.info("init: " + config); String name = super.init(config, core); threshold = config.get(THRESHOLD_TOKEN_FREQUENCY) == null ? 0.0f : (Float) config.get(THRESHOLD_TOKEN_FREQUENCY); sourceLocation = (String) config.get(LOCATION); lookupImpl = (String) config.get(LOOKUP_IMPL); IndexSchema schema = core.getLatestSchema(); suggestionAnalyzerFieldTypeName = (String) config.get(SUGGESTION_ANALYZER_FIELDTYPE); if (schema.getFieldTypes().containsKey(suggestionAnalyzerFieldTypeName)) { FieldType fieldType = schema.getFieldTypes().get(suggestionAnalyzerFieldTypeName); suggestionAnalyzer = fieldType.getQueryAnalyzer(); }//from ww w .j a va2s. c o m // support the old classnames without -Factory for config file backwards compatibility. if (lookupImpl == null || "org.apache.solr.spelling.suggest.jaspell.JaspellLookup".equals(lookupImpl)) { lookupImpl = JaspellLookupFactory.class.getName(); } else if ("org.apache.solr.spelling.suggest.tst.TSTLookup".equals(lookupImpl)) { lookupImpl = TSTLookupFactory.class.getName(); } else if ("org.apache.solr.spelling.suggest.fst.FSTLookup".equals(lookupImpl)) { lookupImpl = FSTLookupFactory.class.getName(); } factory = core.getResourceLoader().newInstance(lookupImpl, LookupFactory.class); lookup = factory.create(config, core); String store = (String) config.get(STORE_DIR); if (store != null) { storeDir = new File(store); if (!storeDir.isAbsolute()) { storeDir = new File(core.getDataDir() + File.separator + storeDir); } if (!storeDir.exists()) { storeDir.mkdirs(); } else { // attempt reload of the stored lookup try { lookup.load(new FileInputStream(new File(storeDir, factory.storeFileName()))); } catch (IOException e) { LOG.warn("Loading stored lookup data failed", e); } } } return name; }
From source file:org.dice.solrenhancements.spellchecker.DiceSpellCheckComponent.java
License:Apache License
@Override public void inform(SolrCore core) { if (initParams != null) { LOG.info("Initializing spell checkers"); boolean hasDefault = false; for (int i = 0; i < initParams.size(); i++) { if (initParams.getName(i).equals("spellchecker")) { NamedList spellchecker = (NamedList) initParams.getVal(i); String className = (String) spellchecker.get("classname"); // TODO: this is a little bit sneaky: warn if class isnt supplied // so that its mandatory in a future release? if (className == null) className = IndexBasedSpellChecker.class.getName(); SolrResourceLoader loader = core.getResourceLoader(); SolrSpellChecker checker = loader.newInstance(className, SolrSpellChecker.class); if (checker != null) { String dictionary = checker.init(spellchecker, core); if (dictionary != null) { boolean isDefault = dictionary.equals(SolrSpellChecker.DEFAULT_DICTIONARY_NAME); if (isDefault == true && hasDefault == false) { hasDefault = true; } else if (isDefault == true && hasDefault == true) { throw new RuntimeException("More than one dictionary is missing name."); }//www . j a va 2 s . c o m spellCheckers.put(dictionary, checker); } else { if (hasDefault == false) { spellCheckers.put(SolrSpellChecker.DEFAULT_DICTIONARY_NAME, checker); hasDefault = true; } else { throw new RuntimeException("More than one dictionary is missing name."); } } // Register event listeners for this SpellChecker core.registerFirstSearcherListener(new SpellCheckerListener(core, checker, false, false)); boolean buildOnCommit = Boolean.parseBoolean((String) spellchecker.get("buildOnCommit")); boolean buildOnOptimize = Boolean .parseBoolean((String) spellchecker.get("buildOnOptimize")); if (buildOnCommit || buildOnOptimize) { LOG.info("Registering newSearcher listener for spellchecker: " + checker.getDictionaryName()); core.registerNewSearcherListener( new SpellCheckerListener(core, checker, buildOnCommit, buildOnOptimize)); } } else { throw new RuntimeException("Can't load spell checker: " + className); } } } Map<String, QueryConverter> queryConverters = new HashMap<String, QueryConverter>(); core.initPlugins(queryConverters, QueryConverter.class); //ensure that there is at least one query converter defined if (queryConverters.size() == 0) { LOG.info("No queryConverter defined, using default converter"); queryConverters.put("queryConverter", new SpellingQueryConverter()); } //there should only be one if (queryConverters.size() == 1) { queryConverter = queryConverters.values().iterator().next(); IndexSchema schema = core.getLatestSchema(); String fieldTypeName = (String) initParams.get("queryAnalyzerFieldType"); FieldType fieldType = schema.getFieldTypes().get(fieldTypeName); Analyzer analyzer = fieldType == null ? new WhitespaceAnalyzer(core.getSolrConfig().luceneMatchVersion) : fieldType.getQueryAnalyzer(); //TODO: There's got to be a better way! Where's Spring when you need it? queryConverter.setAnalyzer(analyzer); } } }