r108955 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108954‎ | r108955 | r108956 >
Date:05:03, 15 January 2012
Author:oren
Status:ok
Tags:
Comment:
documented class
Modified paths:
  • /trunk/lucene-search-2/src/org/wikimedia/lsearch/spell/Suggest.java (modified) (history)

Diff [purge]

Index: trunk/lucene-search-2/src/org/wikimedia/lsearch/spell/Suggest.java
@@ -3,52 +3,49 @@
44 import java.io.IOException;
55 import java.io.Serializable;
66 import java.util.ArrayList;
7 -import java.util.Collection;
87 import java.util.Collections;
98 import java.util.Comparator;
109 import java.util.HashMap;
1110 import java.util.HashSet;
12 -import java.util.Iterator;
1311 import java.util.Map;
 12+import java.util.Map.Entry;
1413 import java.util.Set;
1514 import java.util.WeakHashMap;
16 -import java.util.Map.Entry;
1715
1816 import org.apache.log4j.Logger;
19 -import org.apache.lucene.analysis.Analyzer;
2017 import org.apache.lucene.analysis.Token;
21 -import org.apache.lucene.analysis.TokenStream;
2218 import org.apache.lucene.document.Document;
2319 import org.apache.lucene.index.IndexReader;
2420 import org.apache.lucene.index.Term;
2521 import org.apache.lucene.index.TermDocs;
2622 import org.apache.lucene.search.BooleanClause;
2723 import org.apache.lucene.search.BooleanQuery;
28 -import org.apache.lucene.search.Hits;
2924 import org.apache.lucene.search.IndexSearcher;
3025 import org.apache.lucene.search.Query;
3126 import org.apache.lucene.search.ScoreDoc;
3227 import org.apache.lucene.search.TermQuery;
3328 import org.apache.lucene.search.TopDocs;
34 -import org.wikimedia.lsearch.analyzers.Analyzers;
3529 import org.wikimedia.lsearch.analyzers.FastWikiTokenizerEngine;
36 -import org.wikimedia.lsearch.analyzers.FieldNameFactory;
3730 import org.wikimedia.lsearch.analyzers.FilterFactory;
38 -import org.wikimedia.lsearch.beans.ResultSet;
39 -import org.wikimedia.lsearch.beans.SearchResults;
4031 import org.wikimedia.lsearch.config.GlobalConfiguration;
4132 import org.wikimedia.lsearch.config.IndexId;
42 -import org.wikimedia.lsearch.ranks.ObjectCache;
4333 import org.wikimedia.lsearch.ranks.StringList;
4434 import org.wikimedia.lsearch.ranks.StringList.LookupSet;
4535 import org.wikimedia.lsearch.search.NamespaceFilter;
46 -import org.wikimedia.lsearch.search.FilterWrapper;
4736 import org.wikimedia.lsearch.search.SearcherCache;
4837 import org.wikimedia.lsearch.spell.api.NgramIndexer;
4938 import org.wikimedia.lsearch.spell.dist.DoubleMetaphone;
5039 import org.wikimedia.lsearch.spell.dist.EditDistance;
5140
52 -public class Suggest {
 41+
 42+/**
 43+ * The Suggest componnet of spell checking
 44+ *
 45+ * @author rainman
 46+ *
 47+ */
 48+public class Suggest
 49+{
5350 static Logger log = Logger.getLogger(Suggest.class);
5451 protected static GlobalConfiguration global=null;
5552 protected IndexId iid;
@@ -74,6 +71,7 @@
7572 public Metric(String word){
7673 this(word,true);
7774 }
 75+
7876 public Metric(String word, boolean useMetaphones){
7977 this.word = word;
8078 this.decomposed = FastWikiTokenizerEngine.decompose(word);
@@ -86,17 +84,21 @@
8785 sdmeta2 = new EditDistance(meta2,false);
8886 }
8987 }
 88+
9089 public boolean hasDecomposed(){
9190 return decomposed != word; // equals() not necessary since decompose() returns same object
9291 }
 92+
9393 /** Edit distance */
9494 public int distanceWithDecomposition(String w){
9595 return sd.getDistance(FastWikiTokenizerEngine.decompose(w));
9696 }
 97+
9798 /** Get distance when input words is already decomposed */
9899 public int distance(String w){
99100 return sd.getDistance(w);
100101 }
 102+
101103 /* Edit distance to decomposed word (input word is also decomposed) */
102104 /*public int decomposedDistance(String w){
103105 return sdd.getDistance(FastWikiTokenizerEngine.decompose(w));
@@ -187,6 +189,14 @@
188190 this(iid,null,true);
189191 }
190192
 193+ /**
 194+ * constructor
 195+ *
 196+ * @param iid
 197+ * @param searcher
 198+ * @param useLogging
 199+ * @throws IOException
 200+ */
191201 public Suggest(IndexId iid, IndexSearcher searcher, boolean useLogging) throws IOException{
192202 SearcherCache cache = SearcherCache.getInstance();
193203 this.iid = iid;
@@ -250,6 +260,8 @@
251261 *
252262 */
253263 public static class ExtraInfo implements Serializable {
 264+
 265+ private static final long serialVersionUID = 1L;
254266 protected HashSet<String> phrases;
255267 protected HashSet<String> foundInContext;
256268 protected HashSet<String> foundInTitles;
@@ -790,7 +802,6 @@
791803 return true;
792804 }
793805
794 - @SuppressWarnings("unchecked")
795806 private HashSet<String> getContext(String w, LookupSet allWords, Namespaces ns) throws IOException{
796807 if(ns == null || ns.additional){ // no context for nondefault namespaces
797808 TermDocs td = reader.termDocs(new Term("context_key",w));

Status & tagging log