List of usage examples for org.apache.lucene.search.spell LuceneDictionary LuceneDictionary
public LuceneDictionary(IndexReader reader, String field)
field
in the provided reader
From source file:suonos.controllers.SearchController.java
License:Apache License
/** * GET /api/search/suggestions?q=rock// w ww . j a v a 2 s .co m * * @throws IOException */ @Action public Object suggestions() throws IOException { QueryResults<?> objects; String q = ctx.param("q"); NIOFSDirectory directory = lib.luceneIndex().getLuceneDirectory(); IndexReader rdr = DirectoryReader.open(directory); Dictionary dict = new LuceneDictionary(rdr, "track_title"); // Problem is track_title is all lower case!!! ?? // // Also need a composite "search" field for searching: // ie seach "bach", or search "schiff" should return all albums // containing terms bach, schiff, etc. // "<artists> <composers> <arrangers> <album title>" // // would we ever search for tracks: // "artists composers arrangers title" // // Could search for tracks and then get the album id from lucene???? // List<LookupResult> results; if (false) { // http://lucene.apache.org/core/4_4_0/suggest/index.html AnalyzingSuggester as1 = new AnalyzingSuggester(new StandardAnalyzer()); as1.build(dict); results = as1.lookup(q, false, 10); } else { // Returns suggestions. // Eg: for "ba" - // "bach", "bat", "banner" // try (AnalyzingInfixSuggester as = new AnalyzingInfixSuggester(directory, new StandardAnalyzer())) { as.build(dict); results = as.lookup(q, false, 10); } } // Return back as a json object. // return jsonData(results); }