solr4.10不區分大小寫查詢
阿新 • • 發佈:2019-02-05
solr查詢string型別時,有時需要使之不區分大小寫( case insensitive),這時,就需要重新定義資料型別:
如統一轉化為小寫進行查詢:
1 2 3 4 5 6 7 8 |
< fieldType name = "string_ci" class = "solr.TextField" sortMissingLast = "true" omitNorms = "true" >
< analyzer >
< tokenizer class = "solr.KeywordTokenizerFactory" />
< filter class = "solr.LowerCaseFilterFactory" />
</ analyzer >
</ fieldType >
< field name = "code" type = "string_ci" indexed = "true" stored = "true" />
|
因string型別為值是可不變的,因此此次使用TextField
(string field type for fields that contain structured values that shouldn’t be altered in any way)
注意:上面string_ci型別的field如果做facet時,得到的值將都是小寫的,可能不符合實際需求。
因此,如果需要facet,需使用copyField再定義一個string型別的欄位。
如:
1 2 3 |
<field
name= "code_cp" type= "string" indexed= "true" stored= "false" />
<copyField
source= "code" dest= "code_cp" />
|
對code_cp進行facet則行。