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 possib开发者_JS百科le?
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?
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;
}
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.
精彩评论