VIVO-986 Concatenate string values in search records for better snippets.
Concatenated values are separated by a single space. Non-string values are not affected.
This commit is contained in:
parent
37a08c5dcf
commit
3b57db938f
1 changed files with 40 additions and 14 deletions
|
@ -66,24 +66,50 @@ public class SolrConversionUtils {
|
||||||
SearchInputField searchInputField) {
|
SearchInputField searchInputField) {
|
||||||
SolrInputField solrField = new SolrInputField(
|
SolrInputField solrField = new SolrInputField(
|
||||||
searchInputField.getName());
|
searchInputField.getName());
|
||||||
Collection<Object> values = searchInputField.getValues();
|
|
||||||
//Check if single value or multiple, if single only add that one
|
Collection<Object> values = joinStringValues(searchInputField
|
||||||
//This is done in this way to ensure that if the field itself is single valued
|
.getValues());
|
||||||
//we are not passing an array of a single object but just the object itself to prevent errors
|
|
||||||
if(values.size() > 1) {
|
if (values.isEmpty()) {
|
||||||
solrField.addValue(searchInputField.getValues(),
|
// No values, nothing to do.
|
||||||
searchInputField.getBoost());
|
} else if (values.size() == 1) {
|
||||||
} else if(values.size() == 1){
|
// One value? Insure that it is accepted as such.
|
||||||
Object value = values.iterator().next();
|
solrField.addValue(values.iterator().next(),
|
||||||
solrField.addValue(value, searchInputField.getBoost());
|
searchInputField.getBoost());
|
||||||
} else {
|
} else {
|
||||||
//in this case, values are empty? Just add null? Do nothing?
|
// A collection of values? Add them.
|
||||||
//solrField.addValue(null, searchInputField.getBoost());
|
solrField.addValue(values, searchInputField.getBoost());
|
||||||
//log.debug("Values empty so doing nothing for " + searchInputField.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return solrField;
|
return solrField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join the String values while preserving the non-String values. It
|
||||||
|
* shouldn't affect the score, and it produces better snippets.
|
||||||
|
*/
|
||||||
|
private static Collection<Object> joinStringValues(Collection<Object> values) {
|
||||||
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
List<Object> betterValues = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Object value : values) {
|
||||||
|
if (value instanceof String) {
|
||||||
|
if (buffer.length() > 0) {
|
||||||
|
buffer.append(" ");
|
||||||
|
}
|
||||||
|
buffer.append((String) value);
|
||||||
|
} else {
|
||||||
|
betterValues.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer.length() > 0) {
|
||||||
|
betterValues.add(buffer.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return betterValues;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Convert queries to Solr-specific.
|
// Convert queries to Solr-specific.
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -128,7 +154,7 @@ public class SolrConversionUtils {
|
||||||
if (facetLimit >= 0) {
|
if (facetLimit >= 0) {
|
||||||
solrQuery.setFacetLimit(facetLimit);
|
solrQuery.setFacetLimit(facetLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int minCount = query.getFacetMinCount();
|
int minCount = query.getFacetMinCount();
|
||||||
if (minCount >= 0) {
|
if (minCount >= 0) {
|
||||||
solrQuery.setFacetMinCount(minCount);
|
solrQuery.setFacetMinCount(minCount);
|
||||||
|
|
Loading…
Add table
Reference in a new issue