Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1) facet minimal count; 2) empty facet results serialization #132

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public interface Query {
* Default for the max number of returned facets
*/
public static final int DEFAULT_FACET_LIMIT = 50;


/**
* Default for the min count of a value within a facet to be returned
*/
public static final int DEFAULT_FACET_MINCOUNT = 1;

/**
* Use these instead of the ones provided in the apache Solr package
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package eu.europeana.api.commons.search.util;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.solr.client.solrj.SolrQuery;

import eu.europeana.api.commons.definitions.search.Query;
import eu.europeana.api.commons.definitions.search.impl.QueryImpl;
import eu.europeana.api.commons.definitions.utils.RandomUtils;
Expand Down Expand Up @@ -123,14 +121,15 @@ public SolrQuery toSolrQuery(Query searchQuery, String searchHandler) {
solrQuery.setQuery(searchQuery.getQuery());

solrQuery.setRows(searchQuery.getPageSize());
solrQuery.setStart(searchQuery.getPageNr() * searchQuery.getPageSize());
solrQuery.setStart(computeSolrQueryStart(searchQuery));

if (searchQuery.getFilters() != null)
solrQuery.addFilterQuery(searchQuery.getFilters());

if (searchQuery.getFacetFields() != null) {
solrQuery.setFacet(true);
solrQuery.addFacetField(searchQuery.getFacetFields());
solrQuery.setFacetMinCount(Query.DEFAULT_FACET_MINCOUNT);
solrQuery.setFacetLimit(Query.DEFAULT_FACET_LIMIT);
}

Expand All @@ -144,6 +143,10 @@ public SolrQuery toSolrQuery(Query searchQuery, String searchHandler) {
return solrQuery;
}

protected int computeSolrQueryStart(Query searchQuery) {
return searchQuery.getPageNr() * searchQuery.getPageSize();
}

/**
* This method should be implemented in subclasses (if the fieldName is not
* allowed for sorting an Runtime Exception and the api responses must indicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,9 @@ JsonLdPropertyValue buildFacetPropertyValue(FacetFieldView view) {

facetViewEntry.putProperty(new JsonLdProperty(CommonApiConstants.SEARCH_RESP_FACETS_FIELD, view.getName()));

JsonLdProperty values = new JsonLdProperty(CommonApiConstants.SEARCH_RESP_FACETS_VALUES);
// only if values for facet count are available
if (view.getValueCountMap() != null && !view.getValueCountMap().isEmpty()) {

JsonLdProperty values = new JsonLdProperty(CommonApiConstants.SEARCH_RESP_FACETS_VALUES);
JsonLdPropertyValue labelCountValue;
Map<String, String> valueMap;

Expand All @@ -126,9 +125,8 @@ JsonLdPropertyValue buildFacetPropertyValue(FacetFieldView view) {

values.addValue(labelCountValue);
}

facetViewEntry.putProperty(values);
}
facetViewEntry.putProperty(values);

return facetViewEntry;
}
Expand Down
Loading