From 4e34a79136f0bfbf6f557feaef4188977cd2b4b2 Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Mon, 26 Mar 2007 21:14:00 +0000 Subject: [PATCH] whitespace reformatting to 2-space convention git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@522629 13f79535-47bb-0310-9956-ffa450edef68 --- .../handler/SpellCheckerRequestHandler.java | 242 +++++++++--------- 1 file changed, 121 insertions(+), 121 deletions(-) diff --git a/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java b/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java index 02f929ee415..8013d80f2d8 100644 --- a/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java +++ b/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java @@ -50,140 +50,140 @@ public class SpellCheckerRequestHandler extends RequestHandlerBase { private static Logger log = Logger.getLogger(SpellCheckerRequestHandler.class.getName()); - private SpellChecker spellChecker; + private SpellChecker spellChecker; - /* - * From http://wiki.apache.org/jakarta-lucene/SpellChecker - * If reader and restrictToField are both not null: - * 1. The returned words are restricted only to the words presents in the field - * "restrictToField "of the Lucene Index "reader". - * - * 2. The list is also sorted with a second criterium: the popularity (the - * frequence) of the word in the user field. - * - * 3. If "onlyMorePopular" is true and the mispelled word exist in the user field, - * return only the words more frequent than this. - * - */ - private static IndexReader nullReader = null; - private String restrictToField = null; - private boolean onlyMorePopular = false; + /* + * From http://wiki.apache.org/jakarta-lucene/SpellChecker + * If reader and restrictToField are both not null: + * 1. The returned words are restricted only to the words presents in the field + * "restrictToField "of the Lucene Index "reader". + * + * 2. The list is also sorted with a second criterium: the popularity (the + * frequence) of the word in the user field. + * + * 3. If "onlyMorePopular" is true and the mispelled word exist in the user field, + * return only the words more frequent than this. + * + */ + private static IndexReader nullReader = null; + private String restrictToField = null; + private boolean onlyMorePopular = false; - private Directory spellcheckerIndexDir = new RAMDirectory(); - private String dirDescription = "(ramdir)"; - private String termSourceField; - private static final float DEFAULT_ACCURACY = 0.5f; - private static final int DEFAULT_NUM_SUGGESTIONS = 1; + private Directory spellcheckerIndexDir = new RAMDirectory(); + private String dirDescription = "(ramdir)"; + private String termSourceField; + private static final float DEFAULT_ACCURACY = 0.5f; + private static final int DEFAULT_NUM_SUGGESTIONS = 1; - public void init(NamedList args) { - super.init(args); - SolrParams p = SolrParams.toSolrParams(args); - termSourceField = p.get("termSourceField"); + public void init(NamedList args) { + super.init(args); + SolrParams p = SolrParams.toSolrParams(args); + termSourceField = p.get("termSourceField"); - try { - String dir = p.get("spellcheckerIndexDir"); - if (null != dir) { - File f = new File(dir); - if ( ! f.isAbsolute() ) { - f = new File(SolrCore.getSolrCore().getDataDir(), dir); - } - dirDescription = f.getAbsolutePath(); - log.info("using spell directory: " + dirDescription); - spellcheckerIndexDir = FSDirectory.getDirectory(f); - } else { - log.info("using RAM based spell directory"); - } - spellChecker = new SpellChecker(spellcheckerIndexDir); - } catch (IOException e) { - throw new RuntimeException("Cannot open SpellChecker index", e); + try { + String dir = p.get("spellcheckerIndexDir"); + if (null != dir) { + File f = new File(dir); + if ( ! f.isAbsolute() ) { + f = new File(SolrCore.getSolrCore().getDataDir(), dir); } - } - - public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) - throws Exception { - SolrParams p = req.getParams(); - String words = p.get("q"); - String cmd = p.get("cmd"); - if (cmd != null) { - cmd = cmd.trim(); - if (cmd.equals("rebuild")) { - rebuild(req); - rsp.add("cmdExecuted","rebuild"); - } else if (cmd.equals("reopen")) { - reopen(); - rsp.add("cmdExecuted","reopen"); - } else { - throw new SolrException(400, "Unrecognized Command: " + cmd); - } - } - - Float accuracy; - int numSug; - try { - accuracy = p.getFloat("accuracy", DEFAULT_ACCURACY); - spellChecker.setAccuracy(accuracy); - } catch (NumberFormatException e) { - throw new RuntimeException("Accuracy must be a valid positive float", e); - } - try { - numSug = p.getInt("suggestionCount", DEFAULT_NUM_SUGGESTIONS); - } catch (NumberFormatException e) { - throw new RuntimeException("Spelling suggestion count must be a valid positive integer", e); - } - - if (null != words && !"".equals(words.trim())) { - String[] suggestions = - spellChecker.suggestSimilar(words, numSug, - nullReader, restrictToField, - onlyMorePopular); - - rsp.add("suggestions", Arrays.asList(suggestions)); - } - } - - /** Rebuilds the SpellChecker index using values from the termSourceField from the - * index pointed to by the current {@link IndexSearcher}. - */ - private void rebuild(SolrQueryRequest req) throws IOException, SolrException { - if (null == termSourceField) { - throw new SolrException - (500, "can't rebuild spellchecker index without termSourceField configured"); + dirDescription = f.getAbsolutePath(); + log.info("using spell directory: " + dirDescription); + spellcheckerIndexDir = FSDirectory.getDirectory(f); + } else { + log.info("using RAM based spell directory"); } - - IndexReader indexReader = req.getSearcher().getReader(); - Dictionary dictionary = new LuceneDictionary(indexReader, termSourceField); - spellChecker.indexDictionary(dictionary); + spellChecker = new SpellChecker(spellcheckerIndexDir); + } catch (IOException e) { + throw new RuntimeException("Cannot open SpellChecker index", e); + } + } + + public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) + throws Exception { + SolrParams p = req.getParams(); + String words = p.get("q"); + String cmd = p.get("cmd"); + if (cmd != null) { + cmd = cmd.trim(); + if (cmd.equals("rebuild")) { + rebuild(req); + rsp.add("cmdExecuted","rebuild"); + } else if (cmd.equals("reopen")) { reopen(); + rsp.add("cmdExecuted","reopen"); + } else { + throw new SolrException(400, "Unrecognized Command: " + cmd); + } } + + Float accuracy; + int numSug; + try { + accuracy = p.getFloat("accuracy", DEFAULT_ACCURACY); + spellChecker.setAccuracy(accuracy); + } catch (NumberFormatException e) { + throw new RuntimeException("Accuracy must be a valid positive float", e); + } + try { + numSug = p.getInt("suggestionCount", DEFAULT_NUM_SUGGESTIONS); + } catch (NumberFormatException e) { + throw new RuntimeException("Spelling suggestion count must be a valid positive integer", e); + } + + if (null != words && !"".equals(words.trim())) { + String[] suggestions = + spellChecker.suggestSimilar(words, numSug, + nullReader, restrictToField, + onlyMorePopular); + + rsp.add("suggestions", Arrays.asList(suggestions)); + } + } + + /** Rebuilds the SpellChecker index using values from the termSourceField from the + * index pointed to by the current {@link IndexSearcher}. + */ + private void rebuild(SolrQueryRequest req) throws IOException, SolrException { + if (null == termSourceField) { + throw new SolrException + (500, "can't rebuild spellchecker index without termSourceField configured"); + } + + IndexReader indexReader = req.getSearcher().getReader(); + Dictionary dictionary = new LuceneDictionary(indexReader, termSourceField); + spellChecker.indexDictionary(dictionary); + reopen(); + } - /** - * Reopens the SpellChecker index directory. - * Useful if an external process is responsible for building - * the spell checker index. - */ - private void reopen() throws IOException { - spellChecker.setSpellIndex(spellcheckerIndexDir); - } + /** + * Reopens the SpellChecker index directory. + * Useful if an external process is responsible for building + * the spell checker index. + */ + private void reopen() throws IOException { + spellChecker.setSpellIndex(spellcheckerIndexDir); + } - //////////////////////// SolrInfoMBeans methods ////////////////////// + //////////////////////// SolrInfoMBeans methods ////////////////////// - public String getVersion() { - return "$Revision$"; - } + public String getVersion() { + return "$Revision$"; + } - public String getDescription() { - return "The SpellChecker Solr request handler for SpellChecker index: " + dirDescription; - } + public String getDescription() { + return "The SpellChecker Solr request handler for SpellChecker index: " + dirDescription; + } - public String getSourceId() { - return "$Id$"; - } + public String getSourceId() { + return "$Id$"; + } - public String getSource() { - return "$URL$"; - } + public String getSource() { + return "$URL$"; + } - public URL[] getDocs() { - return null; - } + public URL[] getDocs() { + return null; + } }