mraible commented on code in PR #225:
URL: https://github.com/apache/roller/pull/225#discussion_r4402281140


##########
app/src/main/java/org/apache/roller/weblogger/business/search/lucene/SearchOperation.java:
##########
@@ -229,4 +231,68 @@ public void setLocale(String locale) {
         this.locale = locale;
     }
 
+
+    /**
+     * Query parser that accepts explicit field names only for the fields that
+     * searches are meant to cover. Other index fields hold data that is not
+     * shown on the weblog, so a query naming one is a parse error.
+     */
+    static class SearchFieldsQueryParser extends MultiFieldQueryParser {
+
+        private final Set<String> searchFields;
+
+        SearchFieldsQueryParser(String[] fields, Analyzer analyzer) {
+            super(fields, analyzer);
+            this.searchFields = Set.of(fields);
+        }
+
+        private void checkField(String field) throws ParseException {
+            if (field != null && !searchFields.contains(field)) {
+                throw new ParseException("Cannot search field: " + field);
+            }
+        }
+
+        @Override
+        protected Query getFieldQuery(String field, String queryText, int 
slop) throws ParseException {
+            checkField(field);
+            return super.getFieldQuery(field, queryText, slop);
+        }
+
+        @Override
+        protected Query getFieldQuery(String field, String queryText, boolean 
quoted) throws ParseException {
+            checkField(field);
+            return super.getFieldQuery(field, queryText, quoted);
+        }
+
+        @Override
+        protected Query getFuzzyQuery(String field, String termStr, float 
minSimilarity) throws ParseException {
+            checkField(field);
+            return super.getFuzzyQuery(field, termStr, minSimilarity);
+        }
+
+        @Override
+        protected Query getPrefixQuery(String field, String termStr) throws 
ParseException {
+            checkField(field);
+            return super.getPrefixQuery(field, termStr);
+        }
+
+        @Override
+        protected Query getWildcardQuery(String field, String termStr) throws 
ParseException {
+            checkField(field);

Review Comment:
   Non-blocking: this also refuses `*:*`. Lucene sends that through 
`getWildcardQuery("*", "*")` to build a match-all query, so it now fails with 
"Cannot search field: *". If listing every entry should keep working, this 
override could let `field` "*" through when `termStr` is also "*". Otherwise, a 
line in CHANGES.md saying `*:*` is no longer accepted would help.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to