2011-07-14 34 views
1

我已經成功啓用基於文本的字段類型的高亮顯示,但不適用於非文本字段類型...Solr/SolrJ:你如何突出顯示非文本字段?

如何配置solr以突出顯示非文本字段類型?我無法在網絡上找到非文本字段的示例。它甚至有可能嗎?

具體而言,我想突出顯示文檔中符合查詢的日期值。

我使用solrJ來執行查詢,它可能是限制因素嗎?

回答

2

突出顯示在非「文本」字段上是不可能的。看看這個:

/** 
    * 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); 

特別是在這裏:

  if (field.stored() && 
        ((field.getType() instanceof org.apache.solr.schema.TextField) || 
        (field.getType() instanceof org.apache.solr.schema.StrField))) { 

直到這裏

  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; 
    } 
+0

謝謝!雖然它是我擔心:( – Moogie

+1

)然後,如何確定哪些非文本字段導致文檔符合查詢? – Moogie

+0

您的意思是可能哪些非文本字段與查詢的一部分相匹配.Afaik沒有實現用於返回直接匹配 – fyr

0

你不能做到這一點的解釋。

但適應Solr來處理這一點非常簡單。爲日期創建另一個字段,但採用字符串格式。現在只需使用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"/> 

然後,只需將字段date1_str添加到您的查詢。