diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java index 285bf62dd..1c42329d4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/AutocompleteController.java @@ -282,12 +282,19 @@ public class AutocompleteController extends FreemarkerHttpServlet implements Sea // of wildcard and non-wildcard queries. The query will look have only an implicit disjunction // operator: e.g., +(name:tales name:tales*) try { - Query query = parser.parse(querystr); + // Prevent org.apache.lucene.queryParser.ParseException: + // Cannot parse 'mary *': '*' or '?' not allowed as first character in WildcardQuery + // The * is redundant in this case anyway, so just remove it. + log.debug("Query string is '" + querystr + "'"); + querystr = querystr.replaceAll("([\\s^])[?*]", "$1"); + log.debug("Cleaned query string is '" + querystr + "'"); + log.debug("Adding non-wildcard query for " + querystr); + Query query = parser.parse(querystr); boolQuery.add(query, BooleanClause.Occur.SHOULD); - Query wildcardQuery = parser.parse(querystr + "*"); log.debug("Adding wildcard query for " + querystr); + Query wildcardQuery = parser.parse(querystr + "*"); boolQuery.add(wildcardQuery, BooleanClause.Occur.SHOULD); log.debug("Name query is: " + boolQuery.toString()); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java index 94c2c3847..89f50e00e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/PagedSearchController.java @@ -278,7 +278,7 @@ public class PagedSearchController extends VitroHttpServlet implements Searcher{ request.getRequestDispatcher(Controllers.BASIC_JSP).forward(request,response); } catch (Throwable e) { - log.error("SearchController.doGet(): " + e); + log.error("PagedSearchController.doGet(): " + e, e); doSearchError(request, response, e.getMessage(), null); return; } @@ -440,6 +440,14 @@ public class PagedSearchController extends VitroHttpServlet implements Searcher{ return null; } QueryParser parser = getQueryParser(analyzer); + + // Prevent org.apache.lucene.queryParser.ParseException: + // Cannot parse 'mary *': '*' or '?' not allowed as first character in WildcardQuery + // The * is redundant in this case anyway, so just remove it. + log.debug("Query string is '" + querystr + "'"); + querystr = querystr.replaceAll("([\\s^])[?*]", "$1"); + log.debug("Cleaned query string is '" + querystr + "'"); + query = parser.parse(querystr); String alpha = request.getParameter("alpha");