Lucene 3.5在搜索时不支持中国的Russain Korean Languages

时间:2018-01-02 04:45:45

标签: java lucene

我正在使用Lucene 3.5 Standard Analyzer进行索引和搜索。它适用于除中文,日文和韩文之外的所有语言。我尝试过CJK Analyzer和中国分析仪。但仍然没有工作。索引正在正确创建。我们已经使用Luke工具验证了这一点。但是无法使用Luke工具和使用分析器的代码搜索上述语言单词。任何解决方案。

伊拉克航空公司               

+name:伊拉克航空公司~0.9     This  is the lucene query generated by the analyzer for this chinese word. But not returning result. But other languages and its corresponding query is returning results

1 个答案:

答案 0 :(得分:2)

对于中文,有许多有用的第三方分析器,例如:

  1. mmseg4j
  2. IK-analyzer
  3. ansj_seg
  4. imdict-中国分析器
  5. 我推荐IK分析仪,例如: 将此添加到您的依赖项:

        <dependency>
            <groupId>com.janeluo</groupId>
            <artifactId>ikanalyzer</artifactId>
            <version>2012_u6</version>
        </dependency>
    

    示例代码:

    public class LuenceFirst {
        public static void main(String[] args) throws IOException {
            Analyzer analyzer = new IKAnalyzer(); 
            TokenStream tokenStream = analyzer.tokenStream("", "伊拉克航空公司");
    
            CharTermAttribute charTermAttribute = tokenStream.addAttribute(CharTermAttribute.class);
            OffsetAttribute offsetAttribute = tokenStream.addAttribute(OffsetAttribute.class);
            tokenStream.reset();
            while (tokenStream.incrementToken()) {
                System.out.println("start→" + offsetAttribute.startOffset());
                System.out.println(charTermAttribute);
                System.out.println("end→" + offsetAttribute.endOffset()); 
            }
            tokenStream.close();
        }
    }
    

    输出是:     开始→0

    伊拉克
    
    end→3
    
    start→3
    
    航空公司
    
    end→7
    
    start→3
    
    航空
    
    end→5
    
    start→5
    
    公司
    
    end→7
    

    日语:

    1. koromoji
    2. lucene-gosen
相关问题