2017-03-08 47 views
-1

我需要刪除全部內容中的\ n。我決定用PatternReplaceCharFilterFactory,我需要添加使用API​​調用來SCHEMA.XML如何使用API​​添加到架構「 n」(PatternReplaceCharFilterFactory)?

<filter class="solr.PatternReplaceCharFilterFactory" pattern="\n" replace="all" replacement=""/> 

。但是,solr編碼這種模式。 我打電話

curl -X "POST" "http://localhost:$PORT/solr/$CORE_NAME/schema" \ 
    -H "Content-Type: application/json" \ 
    -d $'{ 
    "add-field-type": { 
    ........ 
    "indexAnalyzer": { 
     "filters": [ 
     { 
      "class": "solr.PatternReplaceCharFilterFactory", 
      "pattern":"\n", 
      "replacement":"", 
      "replace":"all" 
     },] 
     ........... 
    } 

但schema.xml中

Solr的創建
 <filter class="solr.PatternReplaceCharFilterFactory" pattern=" 
" replace="all" replacement=""/> 

我嘗試添加\ n,\ n(\ n)的但結果一樣,它不能正常工作。

+0

雖然捲曲線在行爲方面是清楚的,它立即無法使用,例如在以Solr爲樣本的集合中。 – freedev

回答

1

逃脫的反斜槓對我有用:"pattern": "\\n"

我檢查,在託管模式文件:

<fieldType name="myNewTextField" class="solr.TextField"> 
    <analyzer type="index"> 
    <tokenizer class="solr.PathHierarchyTokenizerFactory" delimiter="/"/> 
    <filter class="solr.PatternReplaceCharFilterFactory" pattern="\n" replace="all" replacement=""/> 
    </analyzer> 
    <analyzer type="query"> 
    <tokenizer class="solr.KeywordTokenizerFactory"/> 
    </analyzer> 
</fieldType> 

所以全捲曲命令如下所示:

curl -X POST -H 'Content-type: application/json' "http://localhost:8983/solr/gettingstarted/schema" -d '{ 
    "add-field-type": { 
    "name": "myNewTextField", 
    "class": "solr.TextField", 
    "indexAnalyzer": { 
     "tokenizer": { 
     "class": "solr.PathHierarchyTokenizerFactory", 
     "delimiter": "/" 
     }, 
     "filters": [ 
     { 
      "class": "solr.PatternReplaceCharFilterFactory", 
      "pattern": "\\n", 
      "replacement": "", 
      "replace": "all" 
     } 
     ] 
    }, 
    "queryAnalyzer": { 
     "tokenizer": { 
     "class": "solr.KeywordTokenizerFactory" 
     } 
    } 
    } 
}' 
+0

你是怎麼發送電話賣掉的?使用unix捲曲? – DenisOgr

+0

是的,讓我更新自己的更新答案。 –

+0

謝謝,我在'-d $'{「add-field-type」之前的捲曲查詢中使用了** $ ** **' – DenisOgr