2012-11-14 34 views
6

我正在使用Solr 3.6.1。什麼是正確的字段類型用於包含整數值的Solr排序字段?我只需要這個字段進行排序,並且不會對它進行範圍查詢。我應該使用integer還是sint什麼是正確的Solr fieldType用於排序整數值?

我看到,在schema.xml中,有聲明sint類型:

<!-- Numeric field types that manipulate the value into 
     a string value that isn't human-readable in its internal form, 
     but with a lexicographic ordering the same as the numeric ordering, 
     so that range queries work correctly. --> 
    <fieldType name="sint" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/> 

integer說以下內容:

<!-- numeric field types that store and index the text 
     value verbatim (and hence don't support range queries, since the 
     lexicographic ordering isn't equal to the numeric ordering) --> 
    <fieldType name="integer" class="solr.IntField" omitNorms="true"/> 

我問這種情況的主要原因是因爲每次的Solr排序我做的sint字段(我有很多他們聲明爲動態字段)填充(不可配置)lucene fieldCache。我看到的統計數據頁上sint各種存儲爲

org.apache.lucene.search.FieldCache$StringIndex

integer各種存儲爲

(HTTP:PORT/Solr的/ CORE /管理/ stats.jsp:// HOST)fieldCache下

org.apache.lucene.search.FieldCache.DEFAULT_INT_PARSER

我相信哪些消耗空間更少?


UPDATE:Solr的3.6.1 schema.xml中已宣佈int作爲TrieIntField即作爲

<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>

該一個以上是從舊版本的solr。

+3

您應該始終使用TrieIntField而不是IntField和SortableIntField:此類具有**多** **多內存效率的FieldCache impl – jpountz

回答

7

如果您不需要範圍查詢,使用 「整數」 作爲Sorts work correctly on both

Documentation: -

可排序域類型像燒結靶,sdouble是有點用詞不當。在上述意義上,它們不需要排序,但在執行RangeQuery查詢時需要 。實際上,Sortables參考 這個概念,使得按字典順序將數字排序爲 字符串。也就是說,如果沒有這樣做,數字1..10將 按字典順序排列爲1,10,2,3 ...使用sint,但是補救措施 這個。但是,如果您不需要執行RangeQuery查詢,並且只有 需要在該字段上進行排序,則只需使用int或double或 等效適當的類。你將節省自己的時間和記憶。

1

可排序字段類型在Solr 5中被棄用,不應使用。您可以使用solr int或tint字段類型

相關問題