* @return the query.
*/
public static DiscoverQuery getDiscoverAutocomplete(Context context,
HttpServletRequest request, DSpaceObject scope)
{
DiscoverQuery queryArgs = new DiscoverQuery();
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration();
setupBasicQuery(context, discoveryConfiguration, request, queryArgs);
String autoIndex = request.getParameter("auto_idx");
String autoQuery = request.getParameter("auto_query");
String sort = request.getParameter("auto_sort");
String autoType = request.getParameter("auto_type");
if ("contains".equals(autoType) || "notcontains".equals(autoType))
{
autoType = DiscoveryConfigurationParameters.TYPE_STANDARD;
}
else if ("authority".equals(autoType) || "notauthority".equals(autoType))
{
autoType = DiscoveryConfigurationParameters.TYPE_AUTHORITY;
}
else
{
autoType = DiscoveryConfigurationParameters.TYPE_AC;
}
DiscoveryConfigurationParameters.SORT sortBy = DiscoveryConfigurationParameters.SORT.VALUE;
if (StringUtils.isNotBlank(sort))
{
if ("count".equalsIgnoreCase(sort))
{
sortBy = DiscoveryConfigurationParameters.SORT.COUNT;
}
else
{
sortBy = DiscoveryConfigurationParameters.SORT.VALUE;
}
}
// no user choices... default for autocomplete should be alphabetic
// sorting in all cases except empty query where count is preferable
else if ("".equals(autoQuery))
{
sortBy = DiscoveryConfigurationParameters.SORT.COUNT;
}
if (autoIndex == null)
{
autoIndex = "all";
}
if (autoQuery == null)
{
autoQuery = "";
}
int limit = UIUtil.getIntParameter(request, "autocomplete.limit");
if (limit == -1)
{
limit = 10;
}
DiscoverFacetField autocompleteField = new DiscoverFacetField(autoIndex,
autoType,
limit, sortBy, autoQuery.toLowerCase());
queryArgs.addFacetField(autocompleteField);
queryArgs.setMaxResults(0);
queryArgs.setFacetMinCount(1);
return queryArgs;
}