Apache Lucene open-source search software
SOLR-3056: add example japanese field type, lazy-load kuromoji resources
Robert Muir8c2e20bb2d8f
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 8f9bc007c76..777986048cc 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -485,6 +485,7 @@ New FeaturesUwe Schindler)* LUCENE-3305, SOLR-3056: Added Kuromoji morphological analyzer for Japanese.+ See the 'text_ja' fieldtype in the example to get started.(Christian Moen, Masaru Hasegawa via Robert Muir)* SOLR-1860: StopFilterFactory, CommonGramsFilterFactory, anddiff --git a/solr/core/src/java/org/apache/solr/analysis/KuromojiTokenizerFactory.java b/solr/core/src/java/org/apache/solr/analysis/KuromojiTokenizerFactory.javaindex f3f5f90358f..ef1face026a 100644--- a/solr/core/src/java/org/apache/solr/analysis/KuromojiTokenizerFactory.java+++ b/solr/core/src/java/org/apache/solr/analysis/KuromojiTokenizerFactory.java@@ -59,11 +59,12 @@ public class KuromojiTokenizerFactory extends BaseTokenizerFactory implements Reprivate static final String USER_DICT_ENCODING = "user-dictionary-encoding";- private Segmenter segmenter;+ private UserDictionary userDictionary;+ private Mode mode;@Overridepublic void inform(ResourceLoader loader) {- Mode mode = getMode(args);+ mode = getMode(args);String userDictionaryPath = args.get(USER_DICT_PATH);try {if (userDictionaryPath != null) {@@ -76,9 +77,9 @@ public class KuromojiTokenizerFactory extends BaseTokenizerFactory implements Re.onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);Reader reader = new InputStreamReader(stream, decoder);- this.segmenter = new Segmenter(new UserDictionary(reader), mode);+ userDictionary = new UserDictionary(reader);} else {- this.segmenter = new Segmenter(mode);+ userDictionary = null;}} catch (Exception e) {throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);@@ -87,7 +88,7 @@ public class KuromojiTokenizerFactory extends BaseTokenizerFactory implements Re@Overridepublic Tokenizer create(Reader input) {- return new KuromojiTokenizer(segmenter, input);+ return new KuromojiTokenizer(new Segmenter(userDictionary, mode), input);}private Mode getMode(Map<String, String> args) {diff --git a/solr/example/solr/conf/schema.xml b/solr/example/solr/conf/schema.xmlindex 0508bc89efb..cc50f555bdb 100755--- a/solr/example/solr/conf/schema.xml+++ b/solr/example/solr/conf/schema.xml@@ -491,7 +491,7 @@</analyzer></fieldType>- <!-- CJK bigram (see text_ja for an alternative Japanese configuration) -->+ <!-- CJK bigram (see text_ja for a Japanese configuration using morphological analysis) --><fieldType name="text_cjk" class="solr.TextField" positionIncrementGap="100"><analyzer><tokenizer class="solr.StandardTokenizerFactory"/>@@ -676,6 +676,44 @@</analyzer></fieldType>+ <!-- Japanese using morphological analysis (see text_cjk for a configuration using bigramming)++ NOTE: If you want to optimize search for precision, use default operator AND in your query+ parser config with <solrQueryParser defaultOperator="AND"/> further down in this file. Use+ OR if you would like to optimize for recall (default).+ -->+ <fieldType name="text_ja" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="false">+ <analyzer>+ <!-- Kuromoji Japanese morphological analyzer/tokenizer.++ Uses a search-mode (heuristic) to get a noun-decompounding effect that is useful for search.++ Example:+ 関西国際空港 (Kansai International Airpart) becomes 関西 (Kansai) 国際 (International) 空港 (airport)+ so we get a match when searching for 空港 (airport) as we would expect from a good search engine.+ (With regular segmentation 関西国際空港 becomes one word and we don't get a hit.)++ Valid values for mode are:+ normal: regular segmentation+ search: segmentation useful for search with extra splitting (default)+ extended: same as search mode, but unigrams unknown words (experimental)++ NOTE: Search-mode improves segmentation for search at the expense of part-of-speech and reading accuracy+ -->+ <tokenizer class="solr.KuromojiTokenizerFactory" mode="search"/>+ <!-- Reduces inflected verbs and adjectives to their base/dictionary forms (辞書形) -->+ <filter class="solr.KuromojiBaseFormFilterFactory"/>+ <!-- Removes tokens with certain part-of-speech tags -->+ <filter class="solr.KuromojiPartOfSpeechStopFilterFactory" tags="lang/stoptags_ja.txt" enablePositionIncrements="true"/> -->+ <!-- Normalizes full-width romaji to half-width and half-width kana to full-width (Unicode NFKC subset) -->+ <filter class="solr.CJKWidthFilterFactory"/>+ <!-- Removes common tokens typically not useful for search, but have a negative effect on ranking -->+ <filter class="solr.StopFilterFactory" ignoreCase="true" words="lang/stopwords_ja.txt" enablePositionIncrements="true" />+ <!-- Lower-case romaji characters -->+ <filter class="solr.LowerCaseFilterFactory"/>+ </analyzer>+ </fieldType>+<!-- Latvian --><fieldType name="text_lv" class="solr.TextField" positionIncrementGap="100"><analyzer>