Package org.wltea.analyzer.lucene

Examples of org.wltea.analyzer.lucene.IKAnalyzer


    String fieldName = "text";
     //检索内容
    String text = "IK Analyzer是一个结合词典分词和文法分词的中文分词开源工具包。它使用了全新的正向迭代最细粒度切分算法。";
   
    //实例化IKAnalyzer分词器
    Analyzer analyzer = new IKAnalyzer();
  
   
    Directory directory = null;
    IndexWriter iwriter = null;
    IndexSearcher isearcher = null;
View Full Code Here


    String fieldName = "text";
     //检索内容
    String text = "IK Analyzer是一个结合词典分词和文法分词的中文分词开源工具包。它使用了全新的正向迭代最细粒度切分算法。";
   
    //实例化IKAnalyzer分词器
    Analyzer analyzer = new IKAnalyzer();
  
   
    Directory directory = null;
    IndexWriter iwriter = null;
    IndexSearcher isearcher = null;
View Full Code Here

   * @param q 查询关键字
   * @param fields 查询字段
   * @return 全文查询对象
   */
  public BooleanQuery getFullTextQuery(String q, String... fields){
    Analyzer analyzer = new IKAnalyzer();
    BooleanQuery query = new BooleanQuery();
    try {
      if (StringUtils.isNotBlank(q)){
        for (String field : fields){
          QueryParser parser = new QueryParser(Version.LUCENE_36, field, analyzer);  
View Full Code Here

   * @param list 设置高亮的内容列表
   * @param subLength 截取长度
   * @param fields 字段名
   */
  public List<T> keywordsHighlight(BooleanQuery query, List<T> list, int subLength, String... fields){
    Analyzer analyzer = new IKAnalyzer();
    Formatter formatter = new SimpleHTMLFormatter("<span class=\"highlight\">", "</span>");  
    Highlighter highlighter = new Highlighter(formatter, new QueryScorer(query));
    highlighter.setTextFragmenter(new SimpleFragmenter(subLength));
    for(T entity : list){
      try {
View Full Code Here

    String fieldName = "text";
     //检索内容
    String text = "IK Analyzer是一个结合词典分词和文法分词的中文分词开源工具包。它使用了全新的正向迭代最细粒度切分算法。";
   
    //实例化IKAnalyzer分词器
    Analyzer analyzer = new IKAnalyzer(true);
   
    Directory directory = null;
    IndexWriter iwriter = null;
    IndexReader ireader = null;
    IndexSearcher isearcher = null;
View Full Code Here

*/
public class IKAnalzyerDemo {
 
  public static void main(String[] args){
    //构建IK分词器,使用smart分词模式
    Analyzer analyzer = new IKAnalyzer(true);
   
    //获取Lucene的TokenStream对象
      TokenStream ts = null;
    try {
      ts = analyzer.tokenStream("myfield", new StringReader("WORLD ,.. html DATA</html>HELLO"));
//      ts = analyzer.tokenStream("myfield", new StringReader("这是一个中文分词的例子,你可以直接运行它!IKAnalyer can analysis english text too"));
      //获取词元位置属性
        OffsetAttribute  offset = ts.addAttribute(OffsetAttribute.class);
        //获取词元文本属性
        CharTermAttribute term = ts.addAttribute(CharTermAttribute.class);
View Full Code Here

    @Inject
    public IkAnalyzerProvider(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) {
        super(index, indexSettings, name, settings);
        Dictionary.initial(new Configuration(env));
        analyzer=new IKAnalyzer(indexSettings, settings, env);
    }
View Full Code Here

TOP

Related Classes of org.wltea.analyzer.lucene.IKAnalyzer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.