Reputation: 13
I have been successful in enabling highlighting on Text based field types, but not for non-text field types...
How does one configure solr to highlight non-text field types? I cannot find a example on the web for non-text fields. Is it even possible?
Specifically I want to highlight the Date value in the document that meets the query.
I am using solrJ to peform the query, could it be the limiting factor?
Upvotes: 1
Views: 1292
Reputation: 3622
You can't do this as was explained.
But it's super simple to adapt Solr to handle this. Create another field for your date but in string format. Now just use a copyField:
<field name="date1" type="date" indexed="true" stored="true" />
<field name="date1_str" type="string" indexed="true" stored="true" />
<copyField source="date1" dest="date1_str"/>
Then just add the field date1_str to your query.
Upvotes: 0
Reputation: 20859
Highlighting is not possible on non "text" fields. Look at this:
/**
* Returns a collection of the names of all stored fields which can be
* highlighted the index reader knows about.
*/
public Collection<String> getStoredHighlightFieldNames() {
if (storedHighlightFieldNames == null) {
storedHighlightFieldNames = new LinkedList<String>();
for (String fieldName : fieldNames) {
try {
SchemaField field = schema.getField(fieldName);
Especially here:
if (field.stored() &&
((field.getType() instanceof org.apache.solr.schema.TextField) ||
(field.getType() instanceof org.apache.solr.schema.StrField))) {
until here
storedHighlightFieldNames.add(fieldName);
}
} catch (RuntimeException e) { // getField() throws a SolrException, but it arrives as a RuntimeException
log.warn("Field \"" + fieldName + "\" found in index, but not defined in schema.");
}
}
}
return storedHighlightFieldNames;
}
Upvotes: 3