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 1c42329d4..4afc67a54 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 @@ -59,7 +59,7 @@ import freemarker.template.Configuration; * through a Lucene search. */ -public class AutocompleteController extends FreemarkerHttpServlet implements Searcher{ +public class AutocompleteController extends BaseSearchController implements Searcher{ private static final long serialVersionUID = 1L; private static final Log log = LogFactory.getLog(AutocompleteController.class); @@ -282,12 +282,7 @@ 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 { - // 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 + "'"); + querystr = cleanQueryString(querystr); log.debug("Adding non-wildcard query for " + querystr); Query query = parser.parse(querystr); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/BaseSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/BaseSearchController.java new file mode 100644 index 000000000..055baa551 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/BaseSearchController.java @@ -0,0 +1,26 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.search.controller; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; + +public class BaseSearchController extends FreemarkerHttpServlet { + + private static final long serialVersionUID = 1L; + private static final Log log = LogFactory.getLog(AutocompleteController.class); + + protected String cleanQueryString(String querystr) { + log.debug("Query string is '" + 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. + querystr = querystr.replaceAll("([\\s^])[?*]", "$1"); + + log.debug("Cleaned query string is '" + querystr + "'"); + return querystr; + } +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/FreemarkerPagedSearchController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/FreemarkerPagedSearchController.java index 380da7cfe..4fc8d585f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/FreemarkerPagedSearchController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/search/controller/FreemarkerPagedSearchController.java @@ -83,7 +83,7 @@ import freemarker.template.Configuration; * Rewritten to use Freemarker: rjy7 * */ -public class FreemarkerPagedSearchController extends FreemarkerHttpServlet implements Searcher { +public class FreemarkerPagedSearchController extends BaseSearchController implements Searcher { private static final long serialVersionUID = 1L; private static final Log log = LogFactory.getLog(FreemarkerPagedSearchController.class.getName()); @@ -524,6 +524,8 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple return null; } QueryParser parser = getQueryParser(analyzer); + + querystr = cleanQueryString(querystr); query = parser.parse(querystr); String alpha = request.getParameter("alpha");