Index: trunk/lucene-search-3/src/main/java/org/wikimedia/lsearch/analyzers/WikiQueryParser.java |
— | — | @@ -44,6 +44,10 @@ |
45 | 45 | * Parser for wiki query syntax |
46 | 46 | * |
47 | 47 | * @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 |
48 | 52 | */ |
49 | 53 | public class WikiQueryParser { |
50 | 54 | private static final int MAX_TERM_LEN = 255; |
— | — | @@ -470,7 +474,7 @@ |
471 | 475 | public HashSet<NamespaceFilter> getFieldNamespaces(String queryText) { |
472 | 476 | HashSet<String> fields = getFields(queryText); |
473 | 477 | HashSet<NamespaceFilter> ret = new HashSet<NamespaceFilter>(); |
474 | | - List ThreadingKeywords = new ArrayList(); |
| 478 | + List<String> ThreadingKeywords = new ArrayList<String>(); |
475 | 479 | ThreadingKeywords.add("inthread"); |
476 | 480 | |
477 | 481 | for (String field : fields) { |
— | — | @@ -1323,7 +1327,7 @@ |
1324 | 1328 | } |
1325 | 1329 | // don't returned nested if one query only |
1326 | 1330 | if (queries.size() == 1) { |
1327 | | - BooleanQuery q = (BooleanQuery) queries.get(0); |
| 1331 | + BooleanQuery q = queries.get(0); |
1328 | 1332 | // one nested clause |
1329 | 1333 | if (q.getClauses().length == 1) |
1330 | 1334 | return q.getClauses()[0].getQuery(); |
— | — | @@ -1535,7 +1539,6 @@ |
1536 | 1540 | /** |
1537 | 1541 | * Construct a full query on all the fields in the index from search text |
1538 | 1542 | */ |
1539 | | - @SuppressWarnings("unchecked") |
1540 | 1543 | public Query parse(String queryText, ParsingOptions options) { |
1541 | 1544 | this.wildcards = options.wildcards; |
1542 | 1545 | this.fuzzy = options.fuzzy; |
— | — | @@ -1689,7 +1692,11 @@ |
1690 | 1693 | return ret; |
1691 | 1694 | } |
1692 | 1695 | |
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 | + */ |
1694 | 1701 | private void filterStopWords(BooleanQuery bq) { |
1695 | 1702 | if (stopWords == null && stopWords.size() == 0) |
1696 | 1703 | return; |
— | — | @@ -1799,9 +1806,11 @@ |
1800 | 1807 | defaultBoost = olfDefaultBoost; |
1801 | 1808 | defaultAliasBoost = ALIAS_BOOST; |
1802 | 1809 | |
| 1810 | + // TODO: fix the bug in this logic - either add qt==null || qs==null or |
| 1811 | + // remove return |
1803 | 1812 | if (qt == qs || qt.equals(qs)) // either null, or category query |
1804 | 1813 | return qt; |
1805 | | - if (qt == null) |
| 1814 | + if (qt == null) // this cannot happen |
1806 | 1815 | return qs; |
1807 | 1816 | if (qs == null) |
1808 | 1817 | return qt; |
— | — | @@ -1811,7 +1820,9 @@ |
1812 | 1821 | return bq; |
1813 | 1822 | } |
1814 | 1823 | |
1815 | | - /** Extract MUST_NOT clauses form a query */ |
| 1824 | + /** |
| 1825 | + * Extract MUST_NOT clauses form a query |
| 1826 | + */ |
1816 | 1827 | protected static BooleanQuery extractForbidden(Query q) { |
1817 | 1828 | BooleanQuery bq = new BooleanQuery(); |
1818 | 1829 | extractForbiddenRecursive(bq, q); |
— | — | @@ -1821,7 +1832,9 @@ |
1822 | 1833 | return bq; |
1823 | 1834 | } |
1824 | 1835 | |
1825 | | - /** Recursivily extract all MUST_NOT clauses from query */ |
| 1836 | + /** |
| 1837 | + * Recursively extract all MUST_NOT clauses from query |
| 1838 | + */ |
1826 | 1839 | protected static void extractForbiddenRecursive(BooleanQuery forbidden, |
1827 | 1840 | Query q) { |
1828 | 1841 | if (q instanceof BooleanQuery) { |