NIHVIVO-2459 Autocomplete: specify returned fields and sort results. Temporarily use untokenized query for tokenized queries.
This commit is contained in:
parent
74a34e8a31
commit
239b45f36c
1 changed files with 21 additions and 17 deletions
|
@ -114,8 +114,8 @@ public class SolrAutocompleteController extends VitroAjaxController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// See if we can do without this, since we set sort field on the query
|
// Since SolrQuery.setSortField() is buggy, sort the results here
|
||||||
//Collections.sort(results);
|
Collections.sort(results);
|
||||||
|
|
||||||
// map.put("results", results);
|
// map.put("results", results);
|
||||||
// writeTemplate(TEMPLATE_DEFAULT, map, config, vreq, response);
|
// writeTemplate(TEMPLATE_DEFAULT, map, config, vreq, response);
|
||||||
|
@ -156,8 +156,9 @@ public class SolrAutocompleteController extends VitroAjaxController {
|
||||||
query.addFilterQuery(VitroLuceneTermNames.RDFTYPE + ":\"" + typeParam + "\"");
|
query.addFilterQuery(VitroLuceneTermNames.RDFTYPE + ":\"" + typeParam + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
// query.setFields(VitroLuceneTermNames.NAME_RAW, VitroLuceneTermNames.URI) // fields to retrieve
|
query.setFields(VitroLuceneTermNames.NAME_RAW, VitroLuceneTermNames.URI); // fields to retrieve
|
||||||
// .setSortField(VitroLuceneTermNames.NAME_RAW, SolrQuery.ORDER.asc);
|
// Solr bug: generates sort=nameLowercase asc instead of sort=nameLowercase+asc
|
||||||
|
//.setSortField(VitroLuceneTermNames.NAME_LOWERCASE, SolrQuery.ORDER.asc);
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -183,11 +184,13 @@ public class SolrAutocompleteController extends VitroAjaxController {
|
||||||
|
|
||||||
private void setTokenizedQuery(SolrQuery query, String queryStr, HttpServletRequest request) {
|
private void setTokenizedQuery(SolrQuery query, String queryStr, HttpServletRequest request) {
|
||||||
|
|
||||||
String stemParam = (String) request.getParameter("stem");
|
// RY 5/18/2011 For now, just doing untokenized query, due to the interactions of wildcard
|
||||||
boolean stem = "true".equals(stemParam);
|
// query and stemming described below. Need to find a way to do this in Solr.
|
||||||
String termName = stem ? VitroLuceneTermNames.AC_NAME_STEMMED : VitroLuceneTermNames.AC_NAME_UNSTEMMED ;
|
// Should take the same approach if we can figure out how to do a disjunction.
|
||||||
|
|
||||||
BooleanQuery boolQuery = new BooleanQuery();
|
// String stemParam = (String) request.getParameter("stem");
|
||||||
|
// boolean stem = "true".equals(stemParam);
|
||||||
|
// String termName = stem ? VitroLuceneTermNames.AC_NAME_STEMMED : VitroLuceneTermNames.AC_NAME_UNSTEMMED ;
|
||||||
|
|
||||||
// // Use the query parser to analyze the search term the same way the indexed text was analyzed.
|
// // Use the query parser to analyze the search term the same way the indexed text was analyzed.
|
||||||
// // For example, text is lowercased, and function words are stripped out.
|
// // For example, text is lowercased, and function words are stripped out.
|
||||||
|
@ -196,18 +199,18 @@ public class SolrAutocompleteController extends VitroAjaxController {
|
||||||
// // The wildcard query doesn't play well with stemming. Query term name:tales* doesn't match
|
// // The wildcard query doesn't play well with stemming. Query term name:tales* doesn't match
|
||||||
// // "tales", which is indexed as "tale", while query term name:tales does. Obviously we need
|
// // "tales", which is indexed as "tale", while query term name:tales does. Obviously we need
|
||||||
// // the wildcard for name:tal*, so the only way to get them all to match is use a disjunction
|
// // the wildcard for name:tal*, so the only way to get them all to match is use a disjunction
|
||||||
// // of wildcard and non-wildcard queries. The query will look have only an implicit disjunction
|
// // of wildcard and non-wildcard queries. The query will have only an implicit disjunction
|
||||||
// // operator: e.g., +(name:tales name:tales*)
|
// // operator: e.g., +(name:tales name:tales*)
|
||||||
// try {
|
// try {
|
||||||
// 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);
|
||||||
// boolQuery.add(query, BooleanClause.Occur.SHOULD);
|
// boolQuery.add(query, BooleanClause.Occur.SHOULD);
|
||||||
//
|
//
|
||||||
// // Prevent ParseException here when adding * after a space.
|
// // Prevent ParseException here when adding * after a space.
|
||||||
// // If there's a space at the end, we don't need the wildcard query.
|
// // If there's a space at the end, we don't need the wildcard query.
|
||||||
// if (! queryStr.endsWith(" ")) {
|
// if (! querystr.endsWith(" ")) {
|
||||||
// log.debug("Adding wildcard query for " + queryStr);
|
// log.debug("Adding wildcard query for " + querystr);
|
||||||
// Query wildcardQuery = parser.parse(queryStr + "*");
|
// Query wildcardQuery = parser.parse(querystr + "*");
|
||||||
// boolQuery.add(wildcardQuery, BooleanClause.Occur.SHOULD);
|
// boolQuery.add(wildcardQuery, BooleanClause.Occur.SHOULD);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
@ -216,11 +219,12 @@ public class SolrAutocompleteController extends VitroAjaxController {
|
||||||
// log.warn(e, e);
|
// log.warn(e, e);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
setUntokenizedQuery(query, queryStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUntokenizedQuery(SolrQuery query, String queryStr) {
|
private void setUntokenizedQuery(SolrQuery query, String queryStr) {
|
||||||
|
|
||||||
// Don't know why we should have to do this; the analyzer should take care of it, but doesn't
|
// We have to lowercase manually, because Solr doesn't do text analysis on wildcard queries
|
||||||
queryStr = queryStr.toLowerCase();
|
queryStr = queryStr.toLowerCase();
|
||||||
// Solr wants whitespace to be escaped with a backslash
|
// Solr wants whitespace to be escaped with a backslash
|
||||||
// Better: replace \s+
|
// Better: replace \s+
|
||||||
|
|
Loading…
Add table
Reference in a new issue