r109810 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109809‎ | r109810 | r109811 >
Date:09:03, 23 January 2012
Author:oren
Status:deferred
Tags:
Comment:
some comments
Modified paths:
  • /trunk/lucene-search-3/src/main/java/org/wikimedia/lsearch/analyzers/WikiQueryParser.java (modified) (history)

Diff [purge]

Index: trunk/lucene-search-3/src/main/java/org/wikimedia/lsearch/analyzers/WikiQueryParser.java
@@ -44,6 +44,10 @@
4545 * Parser for wiki query syntax
4646 *
4747 * @author rainman
 48+ * note: cutstom queries used imply the need for a special query parser
 49+ * however, hand crafted query parsers are notorious for being buggy -
 50+ * consider using a grammer based grammar or using one of the built in
 51+ * QueryParsers
4852 */
4953 public class WikiQueryParser {
5054 private static final int MAX_TERM_LEN = 255;
@@ -470,7 +474,7 @@
471475 public HashSet<NamespaceFilter> getFieldNamespaces(String queryText) {
472476 HashSet<String> fields = getFields(queryText);
473477 HashSet<NamespaceFilter> ret = new HashSet<NamespaceFilter>();
474 - List ThreadingKeywords = new ArrayList();
 478+ List<String> ThreadingKeywords = new ArrayList<String>();
475479 ThreadingKeywords.add("inthread");
476480
477481 for (String field : fields) {
@@ -1323,7 +1327,7 @@
13241328 }
13251329 // don't returned nested if one query only
13261330 if (queries.size() == 1) {
1327 - BooleanQuery q = (BooleanQuery) queries.get(0);
 1331+ BooleanQuery q = queries.get(0);
13281332 // one nested clause
13291333 if (q.getClauses().length == 1)
13301334 return q.getClauses()[0].getQuery();
@@ -1535,7 +1539,6 @@
15361540 /**
15371541 * Construct a full query on all the fields in the index from search text
15381542 */
1539 - @SuppressWarnings("unchecked")
15401543 public Query parse(String queryText, ParsingOptions options) {
15411544 this.wildcards = options.wildcards;
15421545 this.fuzzy = options.fuzzy;
@@ -1689,7 +1692,11 @@
16901693 return ret;
16911694 }
16921695
1693 - /** Recursively transverse queries and put stop words to SHOULD */
 1696+ /**
 1697+ * Recursively transverse queries and put stop words to SHOULD
 1698+ *
 1699+ * @deprecated - unused private method
 1700+ */
16941701 private void filterStopWords(BooleanQuery bq) {
16951702 if (stopWords == null && stopWords.size() == 0)
16961703 return;
@@ -1799,9 +1806,11 @@
18001807 defaultBoost = olfDefaultBoost;
18011808 defaultAliasBoost = ALIAS_BOOST;
18021809
 1810+ // TODO: fix the bug in this logic - either add qt==null || qs==null or
 1811+ // remove return
18031812 if (qt == qs || qt.equals(qs)) // either null, or category query
18041813 return qt;
1805 - if (qt == null)
 1814+ if (qt == null) // this cannot happen
18061815 return qs;
18071816 if (qs == null)
18081817 return qt;
@@ -1811,7 +1820,9 @@
18121821 return bq;
18131822 }
18141823
1815 - /** Extract MUST_NOT clauses form a query */
 1824+ /**
 1825+ * Extract MUST_NOT clauses form a query
 1826+ */
18161827 protected static BooleanQuery extractForbidden(Query q) {
18171828 BooleanQuery bq = new BooleanQuery();
18181829 extractForbiddenRecursive(bq, q);
@@ -1821,7 +1832,9 @@
18221833 return bq;
18231834 }
18241835
1825 - /** Recursivily extract all MUST_NOT clauses from query */
 1836+ /**
 1837+ * Recursively extract all MUST_NOT clauses from query
 1838+ */
18261839 protected static void extractForbiddenRecursive(BooleanQuery forbidden,
18271840 Query q) {
18281841 if (q instanceof BooleanQuery) {

Status & tagging log