Skip to content

Commit

Permalink
Limit default search results by all the possible values for the filte…
Browse files Browse the repository at this point in the history
…r in SearchFilterValuesDataGetter
  • Loading branch information
litvinovg committed Oct 17, 2024
1 parent 33538f8 commit b566bca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class SearchFiltering {
private static final String FILTER_RANGE = "filter_range_";
private static final String FILTER_INPUT_PREFIX = "filter_input_";
private static final String FILTERS = "filters";
public static final String ANY_VALUE = "[* TO *]";

private static final String FILTER_QUERY = ""
+ "PREFIX search: <https://vivoweb.org/ontology/vitro-search#>\n"
Expand Down Expand Up @@ -173,7 +174,11 @@ protected static void addFiltersToQuery(SearchQuery query, Map<String, SearchFil
}
for (FilterValue fv : searchFilter.getValues().values()) {
if (fv.isDefault() || fv.getSelected()) {
query.addFilterQuery(searchFilter.getField() + ":\"" + fv.getId() + "\"");
if (ANY_VALUE.equals(fv.getId())) {
query.addFilterQuery(searchFilter.getField() + ":" + ANY_VALUE );
} else {
query.addFilterQuery(searchFilter.getField() + ":\"" + fv.getId() + "\"");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/* $This file is distributed under the terms of the license in LICENSE$ */
package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;

import static edu.cornell.mannlib.vitro.webapp.search.controller.SearchFiltering.ANY_VALUE;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;

import com.google.common.base.Optional;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
Expand Down Expand Up @@ -41,7 +40,6 @@ public class SearchFilterValuesDataGetter extends DataGetterBase implements Data
private String dataGetterURI;
private String searchFilter;
private VitroRequest vreq;
private ServletContext context;

/**
* Constructor with display model and data getter URI that will be called by reflection.
Expand All @@ -54,7 +52,8 @@ public SearchFilterValuesDataGetter(VitroRequest vreq, Model displayModel, Strin
public Map<String, Object> getData(Map<String, Object> pageData) {
Map<String, Object> responseMap = new HashMap<>();
responseMap.putAll(vreq.getParameterMap());
Map<String, List<String>> requestFilters = Collections.emptyMap();
Map<String, List<String>> requestFilters = new HashMap<>();
requestFilters.put(searchFilter, new ArrayList<String>(Arrays.asList(ANY_VALUE)));
Map<String, Object> defaultSearchResults = PagedSearchController.process(vreq, requestFilters).getMap();
responseMap.put("filterGenericInfo", defaultSearchResults);
requestFilters = SearchFiltering.getRequestFilters(vreq);
Expand Down Expand Up @@ -129,7 +128,6 @@ protected void configure(VitroRequest vreq, Model displayModel, String dataGette
}

this.vreq = vreq;
this.context = vreq.getSession().getServletContext();
this.dataGetterURI = dataGetterURI;

QuerySolutionMap initBindings = new QuerySolutionMap();
Expand Down

0 comments on commit b566bca

Please sign in to comment.