-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#935 Added option for tagging/excluding filters
Initial changes - still need to add code to handle multiple fields in fq.
- Loading branch information
Showing
5 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,11 @@ public Map[] formatSearchQuery(SpatialSearchRequestDTO searchParams, boolean for | |
//reset formattedFq in case of searchParams reuse | ||
searchParams.setFormattedFq(null); | ||
|
||
// Apply filter tagging and excluding filters if flag is set | ||
if (searchParams.getIncludeUnfilteredFacetValues()) { | ||
applyFilterTagging(searchParams); | ||
} | ||
|
||
//format fqs for facets that need ranges substituted | ||
if (searchParams.getFq() != null) { | ||
for (int i = 0; i < searchParams.getFq().length; i++) { | ||
|
@@ -184,16 +189,62 @@ public Map[] formatSearchQuery(SpatialSearchRequestDTO searchParams, boolean for | |
|
||
//add spatial query term for wkt or lat/lon/radius parameters. DisplayString is already added by formatGeneral | ||
String spatialQuery = buildSpatialQueryString(searchParams); | ||
|
||
if (StringUtils.isNotEmpty(spatialQuery)) { | ||
addFormattedFq(new String[] { spatialQuery }, searchParams); | ||
} | ||
|
||
updateQualityProfileContext(searchParams); | ||
} | ||
|
||
updateQueryContext(searchParams); | ||
return fqMaps; | ||
} | ||
|
||
/** | ||
* Apply facet tagging and filter exclusions to the search request. | ||
* | ||
* Note: due to bug/feature in SOLRJ, the filtered facets are added to | ||
* the facet pivot list instead of the facet list, otherwise SOLRJ will | ||
* ignore the facets with counts greater than totalRecords count, when generating | ||
* the facetResults. | ||
* | ||
* @author "Nick dos Remedios <[email protected]>" | ||
* @date 2025-01-09 | ||
* | ||
* @param searchParams | ||
*/ | ||
private void applyFilterTagging(SpatialSearchRequestDTO searchParams) { | ||
List<String> facetList = new ArrayList<String>(); | ||
List<String> facetPivotList = new ArrayList<String>(); | ||
List<String> fqList = new ArrayList<String>(); | ||
|
||
for (String f : searchParams.getFacets()) { | ||
if (searchParams.getFq() != null && Arrays.stream(searchParams.getFq()).anyMatch(fq -> fq.contains(f) && !fq.contains("*"))) { | ||
String prefix = "{!ex=" + f + "}"; | ||
facetPivotList.add(prefix + f); | ||
} else { | ||
facetList.add(f); | ||
} | ||
} | ||
|
||
if (searchParams.getFq() != null) { | ||
for (String fq : searchParams.getFq()) { | ||
String fqField = org.apache.commons.lang3.StringUtils.substringBefore(fq, ":"); | ||
if (Arrays.asList(searchParams.getFacets()).contains(fqField) && !fq.contains("*")) { | ||
String prefix = "{!tag=" + fqField + "}"; | ||
fqList.add(prefix + fq); | ||
} else { | ||
fqList.add(fq); | ||
} | ||
} | ||
} | ||
|
||
searchParams.setFacetPivots(facetPivotList.toArray(new String[0])); | ||
searchParams.setFacets(facetList.toArray(new String[0])); | ||
searchParams.setFq(fqList.toArray(new String[0])); | ||
} | ||
|
||
/** | ||
* To retrieve the key from a fq | ||
* | ||
|
@@ -248,6 +299,7 @@ public void addFqs(String [] fqs, SpatialSearchRequestDTO searchParams) { | |
} | ||
} | ||
} | ||
|
||
private void addFormattedFq(String [] fqs, SearchRequestDTO searchParams) { | ||
if (fqs != null && searchParams != null) { | ||
String[] currentFqs = searchParams.getFormattedFq(); | ||
|