Create BaseSearchController which is subclassed by AutocompleteController and FreemarkerPagedSearchController, so they can share methods.

This commit is contained in:
rjy7 2010-09-30 19:16:15 +00:00
parent e4baea5b1f
commit f0ef52f6e5
3 changed files with 31 additions and 8 deletions

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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");