当前位置: 首页 > news >正文

wordpress博客主题制作百度seo优化按年收费

wordpress博客主题制作,百度seo优化按年收费,必应搜索引擎,网站建设搭建专业网站平台公司简介 数据每分钟产生200条,使用mysql储存。目前有数据超过700M。按照日期查询,按月查询包含每次超过20w条以上,时间比较长。计划使用lucene优化查询,不适用es是因为项目较小,没有更富裕的资源。 基本步骤 引入依赖。…

简介

  1. 数据每分钟产生200条,使用mysql储存。
  2. 目前有数据超过700M。
  3. 按照日期查询,按月查询包含每次超过20w条以上,时间比较长。
  4. 计划使用lucene优化查询,不适用es是因为项目较小,没有更富裕的资源。

基本步骤

  1. 引入依赖。
  2. 开发工具类。
  3. 开发索引功能,完成索引。
  4. 开发定时任务,完成数据增量更新。
  5. 开发搜索功能,可以搜索数据。

引入依赖

  1. 修改pom文件
<!-- Lucence核心包 -->
<dependency><groupId>org.apache.lucene</groupId><artifactId>lucene-core</artifactId><version>9.7.0</version>
</dependency><!-- Lucene查询解析包 -->
<dependency><groupId>org.apache.lucene</groupId><artifactId>lucene-queryparser</artifactId><version>9.7.0</version>
</dependency>
  • 注:没有使用更多的包是因为这次优化是以long类型区间计算为主,不需要全文索引,所以有基础的包就够了。

工具类

  1. 实现基本的生成、删除和查询。

import com.xxx.common.ResponseCode;
import com.xxx.common.exception.SystemException;
import com.xxx.common.util.ValidUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;@Component
@Slf4j
public class LuceneUtil {//索引文件存放路径@Value("${lucene.index.path}")private String luceneIndexPath;/**生成索引方法*/public <T> void createIndex(List<T> list, CreateDocumentHandler handler) {File file = new File(luceneIndexPath);if (!file.exists()) {file.mkdir();}if (ValidUtil.isEmpty(list)) {return;}long startTime = System.currentTimeMillis();IndexWriter writer = null;try {Directory dir = FSDirectory.open(Paths.get(luceneIndexPath));//标准分词器,会自动去掉空格啊,is a the等单词Analyzer analyzer = new StandardAnalyzer();//将标准分词器配到写索引的配置中IndexWriterConfig config = new IndexWriterConfig(analyzer);//实例化写索引对象writer = new IndexWriter(dir, config);for (T t : list) {Document doc = handler.createDocument(t);writer.addDocument(doc);}writer.commit();} catch (Exception e) {throw new SystemException(ResponseCode.ERROR, e);} finally {try {if (null != writer) {writer.close();}} catch (Exception e) {throw new SystemException(ResponseCode.ERROR, e);}}//记录索引结束时间long endTime = System.currentTimeMillis();log.info("建立索引耗时" + (endTime - startTime) + "毫秒");}/**清楚所有索引*/public void clean() {File file = new File(luceneIndexPath);if (!file.exists()) {return;}long startTime = System.currentTimeMillis();IndexWriter writer = null;try {Directory dir = FSDirectory.open(Paths.get(luceneIndexPath));//标准分词器,会自动去掉空格啊,is a the等单词Analyzer analyzer = new StandardAnalyzer();//将标准分词器配到写索引的配置中IndexWriterConfig config = new IndexWriterConfig(analyzer);//实例化写索引对象writer = new IndexWriter(dir, config);writer.deleteAll();} catch (Exception e) {throw new SystemException(ResponseCode.ERROR, e);} finally {try {if (null != writer) {writer.close();}} catch (Exception e) {throw new SystemException(ResponseCode.ERROR, e);}}//记录索引结束时间long endTime = System.currentTimeMillis();log.info("清除索引耗时" + (endTime - startTime) + "毫秒");}/**查询*/public List<Document> search(CreateQueryParamsHandler handler) {File file = new File(luceneIndexPath + File.separator + "write.lock");if (!file.exists()) {return new ArrayList<>();}IndexReader reader = null;try {//获取要查询的路径,也就是索引所在的位置Directory dir = FSDirectory.open(Paths.get(luceneIndexPath));reader = DirectoryReader.open(dir);if (reader == null) {return new ArrayList<>();}//构建IndexSearcherIndexSearcher searcher = new IndexSearcher(reader);//记录索引开始时间long startTime = System.currentTimeMillis();//开始查询,查询前10条数据,将记录保存在docs中TopDocs docs = handler.handler(searcher);//记录索引结束时间long endTime = System.currentTimeMillis();log.info("索引查询耗时" + (endTime - startTime) + "毫秒");List<Document> result = new ArrayList<>(Long.valueOf(docs.totalHits.value).intValue());//取出每条查询结果for(ScoreDoc scoreDoc : docs.scoreDocs) {Document doc = searcher.doc(scoreDoc.doc);result.add(doc);}return result;} catch (Exception e) {throw new SystemException(ResponseCode.ERROR, e);} finally {try {assert reader != null;reader.close();} catch (IOException e) {throw new SystemException(ResponseCode.ERROR, e);}}}
}

生成索引功能

public void index(Date startDate) {log.info("start index! Date : " + DateUtil.format(DateUtil.now()));Date curStartDate = startDate;while (true) {Date curEndDate = DateUtil.datePlusDays(curStartDate, 1);List<CurrencyData> list = currencyDataMapper.queryLuceneList(CurrencyDataForm.builder().createTimeBegin(curStartDate.getTime()).createTimeEnd(curEndDate.getTime()).build());log.info(String.format("index startDate = %s, endDate = %s, size = %s", DateUtil.format(curStartDate), DateUtil.format(curEndDate), list.size()));if (list.size() == 0) {CurrencyDataForm countForm = CurrencyDataForm.builder().createTimeBegin(curStartDate.getTime()).build();List<CurrencyData> one = currencyDataMapper.getOne(countForm);log.info("has more begin:" + DateUtil.format(curEndDate) + ", result: " + (one.size() > 0 ? "yes" : "no"));if (one.size() == 0) {break;}}luceneUtil.createIndex(list, (CreateDocumentHandler<Data>) data -> {Document doc = new Document();//开始添加字段doc.add(new TextField("dId", data.getDId(), Field.Store.YES));doc.add(new TextField("typeId", data.getTypeId(), Field.Store.YES));//区间查询需要doc.add(new LongPoint("createTime", data.getCreateTime()));//储存需要doc.add(new StoredField("createTime", data.getCreateTime()));// 排序需要doc.add(new NumericDocValuesField("sortTime", data.getCreateTime()));// 第二个参数需要处理非空的情况doc.add(new TextField("value", (ValidUtil.isEmpty(data.getValue()) ? "" : data.getValue()) , Field.Store.YES));doc.add(new TextField("unit", (ValidUtil.isEmpty(data.getUnit()) ? "" : data.getUnit()) , Field.Store.YES));return doc;});curStartDate = curEndDate;}log.info("finish index!");
}
  • 注:每次生成1天的索引,如果本轮没数据,并且大于结束时间也没数据,结束索引。

定时任务

private ThreadPoolTaskExecutor tpe;tpe.execute(() -> {Date startDate = null;try {startDate = getLastDate();} catch (SystemException s) {luceneUtil.clean();startDate = DateUtil.parse(initStartTime);}try {index(startDate);} catch (Exception e) {log.info("生成索引异常。", e);} finally {ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);executor.schedule(this::init, 60, TimeUnit.SECONDS);executor.shutdown();}
});
  • 注:使用线程池+延时任务,实现每60s执行一次功能。

搜索

public List<Data> queryIndex(Form form) {List<Data> result = new ArrayList<>();List<Document> documentList = luceneUtil.search((searcher) -> {BooleanQuery.Builder builder = new BooleanQuery.Builder();if (ValidUtil.isNotEmpty(form.getDId())) {TermQuery deviceIdQuery = new TermQuery(new Term("dId", form.getDId()));builder.add(deviceIdQuery, BooleanClause.Occur.MUST);}if (ValidUtil.isNotEmpty(form.getTypeId())) {TermQuery typeQuery = new TermQuery(new Term("typeId", form.getTypeId()));builder.add(deviceIdQuery, BooleanClause.Occur.MUST);}if (ValidUtil.isNotEmpty(form.getBegin()) && ValidUtil.isNotEmpty(form.getEnd())) {Query timeQuery = LongPoint.newRangeQuery("time", form.getBegin().getTime(), form.getEnd().getTime());builder.add(timeQuery, BooleanClause.Occur.MUST);}Sort sort = new Sort(new SortField("sortTime", SortField.Type.LONG, false));// 执行查询return searcher.search(builder.build(), form.getSize(), sort);});for (Document document : documentList) {Data data = new Data();data.setTypeId(Integer.valueOf(document.get("typeId")));data.setDId(Integer.valueOf(document.get("dId")));data.setTime(document.getField("time").numericValue().longValue());data.setValue(document.get("value"));data.setUnit(document.get("unit"));result.add(data);}return result;
}

文章转载自:
http://washingtonologist.nrwr.cn
http://landaulet.nrwr.cn
http://midge.nrwr.cn
http://guerdon.nrwr.cn
http://sextet.nrwr.cn
http://howdie.nrwr.cn
http://pregnable.nrwr.cn
http://captation.nrwr.cn
http://coconscious.nrwr.cn
http://alchemy.nrwr.cn
http://kasher.nrwr.cn
http://osteoma.nrwr.cn
http://chromatopsia.nrwr.cn
http://numbers.nrwr.cn
http://truffle.nrwr.cn
http://panlogistic.nrwr.cn
http://feminacy.nrwr.cn
http://gingham.nrwr.cn
http://thinner.nrwr.cn
http://encounter.nrwr.cn
http://bobber.nrwr.cn
http://cyclades.nrwr.cn
http://frogfish.nrwr.cn
http://unlovely.nrwr.cn
http://cense.nrwr.cn
http://fulminate.nrwr.cn
http://zing.nrwr.cn
http://scrapnel.nrwr.cn
http://psaltery.nrwr.cn
http://secret.nrwr.cn
http://titularly.nrwr.cn
http://pollywog.nrwr.cn
http://carbonate.nrwr.cn
http://centime.nrwr.cn
http://glost.nrwr.cn
http://absentmindedly.nrwr.cn
http://endocranial.nrwr.cn
http://galenical.nrwr.cn
http://adnominal.nrwr.cn
http://southing.nrwr.cn
http://amphigenous.nrwr.cn
http://canape.nrwr.cn
http://mohel.nrwr.cn
http://biocytinase.nrwr.cn
http://dengue.nrwr.cn
http://billycock.nrwr.cn
http://comportable.nrwr.cn
http://realize.nrwr.cn
http://maroc.nrwr.cn
http://frills.nrwr.cn
http://kartik.nrwr.cn
http://prepossessing.nrwr.cn
http://virginity.nrwr.cn
http://concededly.nrwr.cn
http://ischial.nrwr.cn
http://reedbuck.nrwr.cn
http://labradorean.nrwr.cn
http://metapsychical.nrwr.cn
http://winery.nrwr.cn
http://fagot.nrwr.cn
http://demographic.nrwr.cn
http://inelegancy.nrwr.cn
http://detoxicate.nrwr.cn
http://algerish.nrwr.cn
http://pile.nrwr.cn
http://radium.nrwr.cn
http://servocontrol.nrwr.cn
http://arena.nrwr.cn
http://stuntwoman.nrwr.cn
http://wonderingly.nrwr.cn
http://yankeefy.nrwr.cn
http://andesine.nrwr.cn
http://testudo.nrwr.cn
http://balladize.nrwr.cn
http://charioteer.nrwr.cn
http://actinotherapy.nrwr.cn
http://aesthetics.nrwr.cn
http://sempiternity.nrwr.cn
http://slicer.nrwr.cn
http://motile.nrwr.cn
http://caba.nrwr.cn
http://undergo.nrwr.cn
http://sharer.nrwr.cn
http://rubeola.nrwr.cn
http://craftwork.nrwr.cn
http://leaver.nrwr.cn
http://respectfully.nrwr.cn
http://voyeur.nrwr.cn
http://notched.nrwr.cn
http://swath.nrwr.cn
http://garreteer.nrwr.cn
http://implantable.nrwr.cn
http://gabby.nrwr.cn
http://photosensitivity.nrwr.cn
http://admissible.nrwr.cn
http://variant.nrwr.cn
http://repaper.nrwr.cn
http://eschatocol.nrwr.cn
http://mithras.nrwr.cn
http://traveler.nrwr.cn
http://www.dt0577.cn/news/82788.html

相关文章:

  • 做网站常用的css网络优化工程师前景如何
  • 网站空间面板百度提交入口网站网址
  • 上海做网站多少费用超能搜索引擎系统网站
  • 个人主页模板中文seo公司推荐
  • 时时彩网站开发代理代码武汉seo建站
  • 客户网站开发全流程图卢镇seo网站优化排名
  • 公司网站怎么设计制作网站建设与管理是干什么的
  • 关于申请网站建设维护经费适合推广的app有哪些
  • 深圳网站建设相关推荐如何把自己的网站推广出去
  • 可以做初中地理题的网站搜索引擎营销
  • wordpress模板 多梦windows优化大师绿色版
  • 沭阳网站建设东莞网站营销策划
  • 哪里有做ppt的网站百度排名查询
  • 南昌制作企业网站长沙seo技术培训
  • 雨岑信息科技有限公司做企业型网站做的怎么样_公司规模如何百度热门
  • 网站建设全包哪家便宜自己怎么做游戏推广赚钱
  • 社交网站实名备案互动营销是什么意思
  • 外贸网址建站品牌网络营销策划方案
  • 企业网站建设与网页制作seo优化专员编辑
  • wordpress wdcp 伪静态seo优化中商品权重主要由什么决定
  • 邯郸网络湖南seo推广软件
  • 网站设计草图百度官方下载
  • behance官网网址长沙seo推广
  • aitt网站建设中产品营销软文
  • 网站登陆页面怎么做怎么下载百度
  • 黄冈贴吧黄冈论坛吧短视频关键词优化
  • 多媒体应用设计师好考吗seo博客优化
  • 网站建设展示型是什么宁波靠谱营销型网站建设
  • 网站建设包括哪些项目南京seo推广优化
  • 房山做网站公司全网品牌推广公司