Create BaseSearchController which is subclassed by AutocompleteController and FreemarkerPagedSearchController, so they can share methods.
This commit is contained in:
parent
e4baea5b1f
commit
f0ef52f6e5
3 changed files with 31 additions and 8 deletions
|
@ -59,7 +59,7 @@ import freemarker.template.Configuration;
|
||||||
* through a Lucene search.
|
* 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 long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(AutocompleteController.class);
|
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
|
// of wildcard and non-wildcard queries. The query will look have only an implicit disjunction
|
||||||
// operator: e.g., +(name:tales name:tales*)
|
// operator: e.g., +(name:tales name:tales*)
|
||||||
try {
|
try {
|
||||||
// Prevent org.apache.lucene.queryParser.ParseException:
|
querystr = cleanQueryString(querystr);
|
||||||
// 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);
|
log.debug("Adding non-wildcard query for " + querystr);
|
||||||
Query query = parser.parse(querystr);
|
Query query = parser.parse(querystr);
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -83,7 +83,7 @@ import freemarker.template.Configuration;
|
||||||
* Rewritten to use Freemarker: rjy7
|
* 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 long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(FreemarkerPagedSearchController.class.getName());
|
private static final Log log = LogFactory.getLog(FreemarkerPagedSearchController.class.getName());
|
||||||
|
@ -524,6 +524,8 @@ public class FreemarkerPagedSearchController extends FreemarkerHttpServlet imple
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
QueryParser parser = getQueryParser(analyzer);
|
QueryParser parser = getQueryParser(analyzer);
|
||||||
|
|
||||||
|
querystr = cleanQueryString(querystr);
|
||||||
query = parser.parse(querystr);
|
query = parser.parse(querystr);
|
||||||
|
|
||||||
String alpha = request.getParameter("alpha");
|
String alpha = request.getParameter("alpha");
|
||||||
|
|
Loading…
Add table
Reference in a new issue