You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ho...@apache.org on 2007/03/26 23:14:01 UTC

svn commit: r522629 - /lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java

Author: hossman
Date: Mon Mar 26 14:14:00 2007
New Revision: 522629

URL: http://svn.apache.org/viewvc?view=rev&rev=522629
Log:
whitespace reformatting to 2-space convention

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java?view=diff&rev=522629&r1=522628&r2=522629
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/SpellCheckerRequestHandler.java Mon Mar 26 14:14:00 2007
@@ -50,140 +50,140 @@
 
   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;
-
-    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;
+  /*
+   * 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;
     
-    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);
+  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);
         }
-    }
-
-    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 <code>termSourceField</code> 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();
-    }
-  
-    /**
-     * 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 //////////////////////
-
-    public String getVersion() {
-        return "$Revision$";
-    }
-
-    public String getDescription() {
-      return "The SpellChecker Solr request handler for SpellChecker index: " + dirDescription;
-    }
-
-    public String getSourceId() {
-        return "$Id$";
+        rsp.add("cmdExecuted","reopen");
+      } else {
+        throw new SolrException(400, "Unrecognized Command: " + cmd);
+      }
     }
 
-    public String getSource() {
-        return "$URL$";
+    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));
     }
+  }
 
-    public URL[] getDocs() {
-        return null;
+  /** Rebuilds the SpellChecker index using values from the <code>termSourceField</code> 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);
+  }
+
+  //////////////////////// SolrInfoMBeans methods //////////////////////
+
+  public String getVersion() {
+    return "$Revision$";
+  }
+
+  public String getDescription() {
+    return "The SpellChecker Solr request handler for SpellChecker index: " + dirDescription;
+  }
+
+  public String getSourceId() {
+    return "$Id$";
+  }
+
+  public String getSource() {
+    return "$URL$";
+  }
+
+  public URL[] getDocs() {
+    return null;
+  }
 }