Example usage for org.apache.lucene.search.suggest FileDictionary FileDictionary

List of usage examples for org.apache.lucene.search.suggest FileDictionary FileDictionary

Introduction

In this page you can find the example usage for org.apache.lucene.search.suggest FileDictionary FileDictionary.

Prototype

public FileDictionary(Reader reader) 

Source Link

Document

Creates a dictionary based on a reader.

Usage

From source file:org.apache.solr.spelling.suggest.Suggester.java

License:Apache License

@Override
public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {
    LOG.info("build()");
    if (sourceLocation == null) {
        reader = searcher.getIndexReader();
        dictionary = new HighFrequencyDictionary(reader, field, threshold);
    } else {/*from   w ww. j  a  v  a2s.  c o m*/
        try {
            dictionary = new FileDictionary(new InputStreamReader(
                    core.getResourceLoader().openResource(sourceLocation), IOUtils.CHARSET_UTF_8));
        } catch (UnsupportedEncodingException e) {
            // should not happen
            LOG.error("should not happen", e);
        }
    }

    lookup.build(dictionary);
    if (storeDir != null) {
        File target = new File(storeDir, factory.storeFileName());
        if (!lookup.store(new FileOutputStream(target))) {
            if (sourceLocation == null) {
                assert reader != null && field != null;
                LOG.error("Store Lookup build from index on field: " + field + " failed reader has: "
                        + reader.maxDoc() + " docs");
            } else {
                LOG.error("Store Lookup build from sourceloaction: " + sourceLocation + " failed");
            }
        } else {
            LOG.info("Stored suggest data to: " + target.getAbsolutePath());
        }
    }
}

From source file:org.dice.solrenhancements.spellchecker.DiceMultipleCaseSuggester.java

License:Apache License

@Override
public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {
    LOG.info("build()");
    if (sourceLocation == null) {
        reader = searcher.getIndexReader();
        dictionary = new HighFrequencyDictionary(reader, field, threshold);
    } else {//from   ww  w  .j  a v a  2 s . c  om
        try {

            final String fileDelim = ",";
            if (sourceLocation.contains(fileDelim)) {
                String[] files = sourceLocation.split(fileDelim);
                Reader[] readers = new Reader[files.length];
                for (int i = 0; i < files.length; i++) {
                    Reader reader = new InputStreamReader(core.getResourceLoader().openResource(files[i]),
                            IOUtils.CHARSET_UTF_8);
                    readers[i] = reader;
                }
                dictionary = new MultipleFileDictionary(readers);
            } else {
                dictionary = new FileDictionary(new InputStreamReader(
                        core.getResourceLoader().openResource(sourceLocation), IOUtils.CHARSET_UTF_8));
            }
        } catch (UnsupportedEncodingException e) {
            // should not happen
            LOG.error("should not happen", e);
        }
    }

    lookup.build(dictionary);
    if (storeDir != null) {
        File target = new File(storeDir, factory.storeFileName());
        if (!lookup.store(new FileOutputStream(target))) {
            if (sourceLocation == null) {
                assert reader != null && field != null;
                LOG.error("Store Lookup build from index on field: " + field + " failed reader has: "
                        + reader.maxDoc() + " docs");
            } else {
                LOG.error("Store Lookup build from sourceloaction: " + sourceLocation + " failed");
            }
        } else {
            LOG.info("Stored suggest data to: " + target.getAbsolutePath());
        }
    }
}