NIHVIVO-646 Reimplement uri filtering in AutoCompleteController so it's part of the query, instead of removing from query results afterward
This commit is contained in:
parent
cad57c2c88
commit
444d37bd5a
3 changed files with 30 additions and 15 deletions
|
@ -64,10 +64,11 @@ public class AutocompleteController extends FreeMarkerHttpServlet implements Sea
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Log log = LogFactory.getLog(AutocompleteController.class.getName());
|
private static final Log log = LogFactory.getLog(AutocompleteController.class.getName());
|
||||||
|
|
||||||
|
private static String QUERY_PARAMETER_NAME = "term";
|
||||||
|
private static String EXCLUDE_URI_PARAMETER_NAME = "excludeUri";
|
||||||
|
|
||||||
private IndexSearcher searcher = null;
|
private IndexSearcher searcher = null;
|
||||||
String NORESULT_MSG = "";
|
String NORESULT_MSG = "";
|
||||||
private String QUERY_PARAMETER_NAME = "term";
|
|
||||||
private int defaultHitsPerPage = 25;
|
|
||||||
private int defaultMaxSearchSize= 1000;
|
private int defaultMaxSearchSize= 1000;
|
||||||
|
|
||||||
public void init(ServletConfig config) throws ServletException {
|
public void init(ServletConfig config) throws ServletException {
|
||||||
|
@ -116,16 +117,17 @@ public class AutocompleteController extends FreeMarkerHttpServlet implements Sea
|
||||||
|
|
||||||
String qtxt = vreq.getParameter(QUERY_PARAMETER_NAME);
|
String qtxt = vreq.getParameter(QUERY_PARAMETER_NAME);
|
||||||
Analyzer analyzer = getAnalyzer(getServletContext());
|
Analyzer analyzer = getAnalyzer(getServletContext());
|
||||||
Query query = getQuery(vreq, portalFlag, analyzer, indexDir, qtxt);
|
|
||||||
log.debug("query for '" + qtxt +"' is " + query.toString());
|
|
||||||
|
|
||||||
// Get the list of uris that should be excluded from the results
|
// Get the list of individual uris that should be excluded from the search
|
||||||
String filters[] = vreq.getParameterValues("filter");
|
String filters[] = vreq.getParameterValues(EXCLUDE_URI_PARAMETER_NAME);
|
||||||
List<String> urisToExclude = new ArrayList<String>();
|
List<String> urisToExclude = null;
|
||||||
if (filters != null) {
|
if (filters != null) {
|
||||||
urisToExclude = Arrays.asList(vreq.getParameterValues("filter"));
|
urisToExclude = Arrays.asList(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Query query = getQuery(vreq, portalFlag, analyzer, indexDir, qtxt, urisToExclude);
|
||||||
|
log.debug("query for '" + qtxt +"' is " + query.toString());
|
||||||
|
|
||||||
if (query == null ) {
|
if (query == null ) {
|
||||||
doNoQuery(templateName, map, config, response);
|
doNoQuery(templateName, map, config, response);
|
||||||
return;
|
return;
|
||||||
|
@ -167,9 +169,6 @@ public class AutocompleteController extends FreeMarkerHttpServlet implements Sea
|
||||||
try{
|
try{
|
||||||
Document doc = searcherForRequest.doc(topDocs.scoreDocs[i].doc);
|
Document doc = searcherForRequest.doc(topDocs.scoreDocs[i].doc);
|
||||||
String uri = doc.get(Entity2LuceneDoc.term.URI);
|
String uri = doc.get(Entity2LuceneDoc.term.URI);
|
||||||
if (urisToExclude.contains(uri)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Individual ind = iDao.getIndividualByURI(uri);
|
Individual ind = iDao.getIndividualByURI(uri);
|
||||||
if (ind != null) {
|
if (ind != null) {
|
||||||
String name = ind.getName();
|
String name = ind.getName();
|
||||||
|
@ -210,7 +209,7 @@ public class AutocompleteController extends FreeMarkerHttpServlet implements Sea
|
||||||
}
|
}
|
||||||
|
|
||||||
private Query getQuery(VitroRequest request, PortalFlag portalState,
|
private Query getQuery(VitroRequest request, PortalFlag portalState,
|
||||||
Analyzer analyzer, String indexDir, String querystr ) throws SearchException{
|
Analyzer analyzer, String indexDir, String querystr, List<String> urisToExclude ) throws SearchException{
|
||||||
Query query = null;
|
Query query = null;
|
||||||
try{
|
try{
|
||||||
if( querystr == null){
|
if( querystr == null){
|
||||||
|
@ -240,6 +239,17 @@ public class AutocompleteController extends FreeMarkerHttpServlet implements Sea
|
||||||
query = boolQuery;
|
query = boolQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (urisToExclude != null) {
|
||||||
|
for (String uri : urisToExclude) {
|
||||||
|
BooleanQuery boolQuery = new BooleanQuery();
|
||||||
|
boolQuery.add( query, BooleanClause.Occur.MUST);
|
||||||
|
boolQuery.add( new TermQuery(
|
||||||
|
new Term(Entity2LuceneDoc.term.URI, uri)),
|
||||||
|
BooleanClause.Occur.MUST_NOT);
|
||||||
|
query = boolQuery;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//check if this is classgroup filtered
|
//check if this is classgroup filtered
|
||||||
// Object param = request.getParameter("classgroup");
|
// Object param = request.getParameter("classgroup");
|
||||||
// if( param != null && !"".equals(param)){
|
// if( param != null && !"".equals(param)){
|
||||||
|
|
|
@ -38,10 +38,13 @@ public abstract class FileList extends BaseTemplateModel {
|
||||||
public String getTags() {
|
public String getTags() {
|
||||||
String tags = "";
|
String tags = "";
|
||||||
|
|
||||||
Iterator<String> i = list.iterator();
|
for (String file : list) {
|
||||||
while (i.hasNext()) {
|
tags += getTag(file);
|
||||||
tags += getTag(i.next());
|
|
||||||
}
|
}
|
||||||
|
// Iterator<String> i = list.iterator();
|
||||||
|
// while (i.hasNext()) {
|
||||||
|
// tags += getTag(i.next());
|
||||||
|
// }
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,3 +51,5 @@
|
||||||
<@dump var="fruit" />
|
<@dump var="fruit" />
|
||||||
<@dumpDataModel />
|
<@dumpDataModel />
|
||||||
|
|
||||||
|
${stylesheets.addFromTheme("/sstest.css")}
|
||||||
|
${scripts.addFromTheme("/jstest.js")}
|
Loading…
Add table
Add a link
Reference in a new issue