2013-03-01 153 views
3

我想稍微沿行排序的值的列表:如何使用自然排序顺序对solr中的文本/字符串进行排序?

  • 5XA
  • 8kdjfew454
  • 999cc
  • b
  • c9
  • c10cc
  • C11

换句话说,什么是有时被称为“自然排序”,其中文字字母顺序排列/字典顺序,其中有文字,但是数字是那里有数字,即使两者都混合在同一个字符串中。

我无法找到在Solr(4.0 atm)中做到这一点。有没有标准的方法来做到这一点,或至少有一个可行的“配方”?

回答

0

可以达到最接近的事在this article

描述从文章:

要强制数字到数字排序,我们需要离开垫的任何数字 用零:2变成0002,10变成0010,100变成0100,并且变成 等等。那么即使词法排序将安排这样的值:

标题1编号标题号2标题号10名称100号

字段类型

此字母数字排序字段类型转换发现任何数字为6 数字,用零填充。 (如果您预计数字在你的字段值大于6 位,则需要增加 零数时填充。)

字段类型还删除英语和法语重要文章, 小写字母,并清除任何不是字母数字的字符。它是以英文为中心的 ,并且假设变音符已被折成 ASCII字符。

<fieldType name="alphaNumericSort" class="solr.TextField" sortMissingLast="false" omitNorms="true"> 
 
    <analyzer> 
 
    <!-- KeywordTokenizer does no actual tokenizing, so the entire 
 
     input string is preserved as a single token 
 
     --> 
 
    <tokenizer class="solr.KeywordTokenizerFactory"/> 
 
    <!-- The LowerCase TokenFilter does what you expect, which can be 
 
     when you want your sorting to be case insensitive 
 
     --> 
 
    <filter class="solr.LowerCaseFilterFactory" /> 
 
    <!-- The TrimFilter removes any leading or trailing whitespace --> 
 
    <filter class="solr.TrimFilterFactory" /> 
 
    <!-- Remove leading articles --> 
 
    <filter class="solr.PatternReplaceFilterFactory" 
 
      pattern="^(a |the |les |la |le |l'|de la |du |des)" replacement="" replace="all" 
 
    /> 
 
    <!-- Left-pad numbers with zeroes --> 
 
    <filter class="solr.PatternReplaceFilterFactory" 
 
      pattern="(\d+)" replacement="00000$1" replace="all" 
 
    /> 
 
    <!-- Left-trim zeroes to produce 6 digit numbers --> 
 
    <filter class="solr.PatternReplaceFilterFactory" 
 
      pattern="0*([0-9]{6,})" replacement="$1" replace="all" 
 
    /> 
 
    <!-- Remove all but alphanumeric characters --> 
 
    <filter class="solr.PatternReplaceFilterFactory" 
 
      pattern="([^a-z0-9])" replacement="" replace="all" 
 
    /> 
 
    </analyzer> 
 
</fieldType>

样本输出

标题号1 => titleno000001 标题号2 => titleno000002
标题号10 => titleno000010
标题号= 100> titleno000100

相关问题