Example usage for org.apache.solr.spelling.suggest SolrSuggester getStoreFile

List of usage examples for org.apache.solr.spelling.suggest SolrSuggester getStoreFile

Introduction

In this page you can find the example usage for org.apache.solr.spelling.suggest SolrSuggester getStoreFile.

Prototype

public File getStoreFile() 

Source Link

Usage

From source file:org.alfresco.solr.component.AsyncBuildSuggestComponent.java

License:Open Source License

@Override
public void inform(SolrCore core) {
    if (initParams != null) {
        LOG.info("Initializing SuggestComponent");
        boolean hasDefault = false;
        for (int i = 0; i < initParams.size(); i++) {
            if (initParams.getName(i).equals(CONFIG_PARAM_LABEL)) {
                NamedList suggesterParams = (NamedList) initParams.getVal(i);
                SolrSuggester suggester = new SolrSuggester();
                boolean buildOnStartup;
                Object buildOnStartupObj = suggesterParams.get(BUILD_ON_STARTUP_LABEL);
                if (buildOnStartupObj == null) {
                    File storeFile = suggester.getStoreFile();
                    buildOnStartup = storeFile == null || !storeFile.exists();
                } else {
                    buildOnStartup = Boolean.parseBoolean((String) buildOnStartupObj);
                }/*from   w  ww. ja v a  2 s . co  m*/
                boolean buildOnCommit = Boolean
                        .parseBoolean((String) suggesterParams.get(BUILD_ON_COMMIT_LABEL));
                boolean buildOnOptimize = Boolean
                        .parseBoolean((String) suggesterParams.get(BUILD_ON_OPTIMIZE_LABEL));
                boolean enabled = Boolean.parseBoolean((String) suggesterParams.get(ENABLED_LABEL));
                long minSecsBetweenBuilds = Long
                        .parseLong(core.getCoreDescriptor().getCoreProperty(MIN_SECS_BETWEEN_BUILDS, "-1"));
                SuggesterCache suggesterCache = new SuggesterCache(core, suggesterParams, enabled,
                        buildOnCommit, buildOnOptimize, buildOnStartup);

                String dictionary = suggester.init(suggesterParams, core);
                if (dictionary != null) {
                    boolean isDefault = dictionary.equals(DEFAULT_DICT_NAME);
                    if (isDefault && !hasDefault) {
                        hasDefault = true;
                    } else if (isDefault) {
                        throw new RuntimeException("More than one dictionary is missing name.");
                    }
                    suggesterCache.setBeanName(dictionary);
                    suggesters.put(dictionary, suggesterCache);
                } else {
                    if (!hasDefault) {
                        suggesterCache.setBeanName(DEFAULT_DICT_NAME);
                        suggesters.put(DEFAULT_DICT_NAME, suggesterCache);
                        hasDefault = true;
                    } else {
                        throw new RuntimeException("More than one dictionary is missing name.");
                    }
                }

                try {
                    suggesterCache.afterPropertiesSet();
                } catch (Exception e) {
                    LOG.error("Unable to initialise SuggesterCache.", e);
                    throw new RuntimeException("Unable to initialise SuggesterCache.", e);
                }

                // Register event listeners for this Suggester
                core.registerFirstSearcherListener(new SuggesterListener(suggesterCache, minSecsBetweenBuilds));
                if (buildOnCommit || buildOnOptimize) {
                    LOG.debug("Registering newSearcher listener for suggester: " + suggester.getName());
                    core.registerNewSearcherListener(
                            new SuggesterListener(suggesterCache, minSecsBetweenBuilds));
                }
            }
        }
    }
}

From source file:org.alfresco.solr.component.AsyncBuildSuggestComponent.java

License:Open Source License

private void reloadSuggester(SolrSuggester suggester, SolrCore core, SolrIndexSearcher searcher)
        throws IOException {
    File storeFile = suggester.getStoreFile();
    if (storeFile == null || !storeFile.exists()) {
        suggester.build(core, searcher);
    } else {//from  w w w  . j a va2  s .c om
        suggester.reload(core, searcher);
    }
}