python222网站实战(SpringBoot+SpringSecurity+MybatisPlus+thymeleaf+layui)-标题生成关键字实现

锋哥原创的Springboot+Layui python222网站实战:

python222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )_哔哩哔哩_bilibilipython222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )共计23条视频,包括:python222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )、第2讲 架构搭建实现、第3讲 页面系统属性动态化设计实现等,UP主更多精彩视频,请关注UP账号。icon-default.png?t=N7T8https://www.bilibili.com/video/BV1yX4y1a7qM/在帖子添加的地方,我们用ik进行分词。引入ik分词依赖。


    com.github.keran213539
    IK_Analyzer
    2012FF_hf1_1
package com.python222;



import com.python222.util.AnalyzerUtil;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.wltea.analyzer.lucene.IKAnalyzer;

import java.io.StringReader;

class Python222ApplicationTests {

    public static void main(String[] args) throws Exception{
        Analyzer analyzer=new IKAnalyzer();
        TokenStream tokenStream = analyzer.tokenStream("", "Hive执行计划之什么是hiveSQL向量化模式及优化详解");
        CharTermAttribute charTermAttribute = tokenStream.addAttribute(CharTermAttribute.class);
        tokenStream.reset();
        while (tokenStream.incrementToken()){
            System.out.println(charTermAttribute.toString());
        }
        tokenStream.close();
    }
}

我们做一个分词工具类:

package com.python222.util;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.wltea.analyzer.lucene.IKAnalyzer;

/**
 * 分词器工具类
 * @author python222小锋老师
 * @site www.python222.com
 */
public class AnalyzerUtil {

    /**
     * 生成分词
     * @param text
     * @return
     * @throws Exception
     */
    public static String gen(String text)throws Exception{
        StringBuffer sb=new StringBuffer();
        Analyzer analyzer=new IKAnalyzer();
        TokenStream tokenStream = analyzer.tokenStream("", text);
        CharTermAttribute charTermAttribute = tokenStream.addAttribute(CharTermAttribute.class);
        tokenStream.reset();
        while (tokenStream.incrementToken()){
            sb.append(charTermAttribute.toString()+",");
        }
        tokenStream.close();
        return sb.deleteCharAt(sb.length()-1).toString();
    }
}

生成 逗号隔开的分词结果。

帖子添加和修改模块,加下

article.setKeyWords(AnalyzerUtil.gen(article.getTitle())); // 根据标题生成关键字分词

python222网站实战(SpringBoot+SpringSecurity+MybatisPlus+thymeleaf+layui)-标题生成关键字实现_第1张图片

article模版加下 分词遍历显示代码:

    关键字:

你可能感兴趣的:(java,spring,boot,layui,后端)