How can I truncate the solr string field to 10 characters?

I created the following string field for indexing.

<fieldType name="short_text_for_sort" class="solr.StrField" omitNorms="true" sortMissingLast="true" omitTermFreqAndPositions="true" positionIncrementGap="100">
  <analyzer type="index">
    <!-- TODO: truncate to 10 characters-->
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="solr.ASCIIFoldingFilterFactory"/>
  </analyzer>
</fieldType>

How can I limit this field to 10 characters? Do I need to write my own filter?

+3
source share
2 answers

One parameter: PatternTokenizerFactory and regex input to whatever shape you need.

Second option: use the copyfield command, setting the maxChars parameter to 10.

Third option: handle this before your data makes it equal.

The second option is probably the simplest and allows you to keep the original value of the field unchanged.

+5
source

Use a word length filter

<filter class="solr.LengthFilterFactory" min="1" max="10" />

http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.LengthFilterFactory

* edit . , (, )

0

All Articles