crawler 查询

package com.zking.cucu;

import java.io.IOException;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;

import com.zking.dao.BlogDao;
import com.zking.util.PropertiesUtil;

/**
 * 构建lucene
 * @author Administrator
 *
 */
public class IndexStrat {
       private static BlogDao blogDao=new BlogDao();
       public static void main(String[] args) {
    	 //写在分词器中
		 IndexWriterConfig conf=new IndexWriterConfig(new SmartChineseAnalyzer());
	     //保存路径
		 Directory d;
		 //写流
	     IndexWriter indexWriter=null;
		try {
			d = FSDirectory.open(Paths.get(PropertiesUtil.getValue("indexPath")));
			indexWriter=new IndexWriter(d, conf);
			//开始写这些
			List<Map<String, Object>> list = blogDao.list(null, null);
			for (Map<String, Object> map : list) {
				//每个人作为一个单独的数据写在文档里
				Document doc=new Document();
				doc.add(new StringField("id", (String) map.get("id"), Field.Store.YES));
				//用于对一句话进行分词处理
				doc.add(new TextField("title", (String) map.get("title"), Field.Store.YES));
				doc.add(new StringField("url", (String) map.get("url"), Field.Store.YES));
				indexWriter.addDocument(doc);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if(indexWriter!=null) {
				try {
					indexWriter.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
      }
}

然后拿到我们写入的文件

通过字符去查询

//判断你传过来的分词是否有
if(StringUtils.isBlank(title)) {
				List<Map<String, Object>> blogList = this.blogDao.list(title, null);
				request.setAttribute("blogList", blogList);
			}else {
				//分词器
				SmartChineseAnalyzer analyzer=new SmartChineseAnalyzer();
				//相当于io的读取
				IndexReader indexReader=DirectoryReader.open(FSDirectory.open(Paths.get(PropertiesUtil.getValue("indexPath"))));
				//搜索引擎
				IndexSearcher searcher=new IndexSearcher(indexReader);
				//查询前面100 条数据
				Query query= new QueryParser("title", analyzer).parse(title);
				TopDocs tsearch = searcher.search(query, 100);
				
				//将碰撞出来的关键字给点亮
				QueryScorer queryScorer=new QueryScorer(query);
				//样式
				Formatter formatter=new SimpleHTMLFormatter("<span style='color:red;'><b>", "</b></span>");
				Highlighter highlight=new Highlighter(formatter, queryScorer);
				
				List<Map<String, Object>> blogList =new ArrayList<Map<String,Object>>();
				Map<String, Object> map=null;
				ScoreDoc[] scoreDocs = tsearch.scoreDocs;
			    for (ScoreDoc scoreDoc : scoreDocs) {
			    	map=new HashMap<String, Object>(); 
			    	Document doc = searcher.doc(scoreDoc.doc);
			    	map.put("id", doc.get("id"));
			    	//点亮
			    	String titleHighlighter = doc.get("title");
			    	if(StringUtils.isNotBlank(titleHighlighter)) {
			    		titleHighlighter=highlight.getBestFragment(analyzer, "title", titleHighlighter);
			    	}
			    	map.put("title",titleHighlighter );
			    	map.put("url", doc.get("url"));
			    	blogList.add(map);
			    }
			    request.setAttribute("blogList", blogList);
			}

两个方法类

帮助类

package com.zking.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * properties工具类
 * @author user
 *
 */
public class PropertiesUtil {

	/**
	 * 根据key获取value值
	 * @param key
	 * @return
	 */
	public static String getValue(String key){
		Properties prop=new Properties();
		InputStream in=new PropertiesUtil().getClass().getResourceAsStream("/lucene.properties");
		try {
			prop.load(in);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return prop.getProperty(key);
	}
}

文件..lucene.properties

你写的地方

url=jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&useSSL=false
user=root
pwd=123
driver=com.mysql.jdbc.Driver
ehcacheXmlPath=C://blogCrawler/ehcache.xml
blogImages=C://blogCrawler/blogImages/
indexPath=C://blogCrawler/lucene

 

内容概要:本文介绍了利用Matlab代码实现处理IMU、GPS传感器数据的多种姿态解算算法,重点包括卡尔曼滤波和扩展卡尔曼滤波等技术,旨在提升导航系统的精度与稳定性。通过对传感器数据进行融合与滤波处理,有效解决了惯性导航系统中存在的累积误差问题,提高了动态环境下的姿态估计准确性。文章还提供了完整的算法实现流程和仿真验证,展示了不同滤波方法在实际应用场景中的性能对比。; 适合人群:具备一定Matlab编程基础,从事导航、控制、机器人或自动驾驶等相关领域研究的科研人员及工程技术人员,尤其适合研究生及以上学历或有相关项目经验的研发人员。; 使用场景及目标:①应用于无人机、无人车、机器人等自主导航系统中的姿态估计;②用于教学与科研中对滤波算法的理解与改进;③帮助开发者掌握IMU【处理IMU、GPS传感器】现了多种姿态解算算法,如卡尔曼滤波、扩展卡尔曼滤波等,以提高导航系统的精度和稳定性(Matlab代码实现)/GPS融合算法的设计思路与实现技巧,提升系统鲁棒性与定位精度。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,逐步调试并理解各算法模块的作用,重点关注传感器数据预处理、状态方程构建、噪声协方差调节及滤波结果分析等关键环节,以达到深入掌握姿态解算核心技术的目的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值