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

做网站推广一年多少钱郑州众志seo

做网站推广一年多少钱,郑州众志seo,smarty与wordpress,企业网站建设公司有哪些背景 之前已简单使用ES及Kibana和在线转Base64工具实现了检索文档的demo,并已实现WebHook的搭建和触发流程接口。 传送门: 基于GitBucket的Hook构建ES检索PDF等文档全栈方案 使用ES检索PDF、word等文档快速开始 实现读取本地文件入库ES 总体思路&…

背景

之前已简单使用ES及Kibana和在线转Base64工具实现了检索文档的demo,并已实现WebHook的搭建和触发流程接口。
传送门:
基于GitBucket的Hook构建ES检索PDF等文档全栈方案

使用ES检索PDF、word等文档快速开始

实现读取本地文件入库ES

总体思路:基于前面已经搭建的WebHook触发流程,接收到push更新消息之后,使用本地的git工具拉取最新变动。这些文件与我们的ES应用在同一台机器上,然后Java可以读取这些文件转码并交给ES处理。

我们先处理核心部分,也就是使用Java读取各种文档,如PDF、Word、txt等格式的文件解析并在ES中创建索引。

文件属性类

根据自己的需要,文件属性应至少包括文件名、文件类型、作者等字段,由于目标是可以通过浏览器页面直接打开文件,则需要包含文件的网络url(注意不是本地url地址)。

import lombok.Data;  
@Data  
public class FileSource {  private String title;  private String summary;  private String fileType;  private String fileUrl;  private String content;  private String author;  private String fileVersion;  private String createDate;  
}

使用Data注解可以自动生成Get、Set方法,不用自己复制粘贴了。

写入流程的实现

  • 使用tika库自动获取文件类型
public static String getFileTypeByDefaultTika(String filePathUrl) throws IOException, URISyntaxException {  // 从 URL 创建一个 File 对象  File file = new File(new URL("file:///" + filePathUrl).toURI());  // 使用 Tika 来检测文件的 MIME 类型  Tika tika = new Tika();  MediaType mediaType = MediaType.parse(tika.detect(file));  // 从 MIME 类型中提取文件的基本类型(如 pdf、image、video 等)  String fileType = mediaType.getSubtype();  return fileType;  
}
  • 根据文件类型判断排除音视频类文件
String fileType = getFileTypeByDefaultTika(pathUrl);  if (!fileType.contains("video")  && !fileType.contains("image")  && !"application/zip".equals(fileType)) {……}
  • 解析文件内容为Base64
public static String FileToBase64(String filePath) throws IOException {  byte[] fileContent = Files.readAllBytes(Paths.get(filePath));  return Base64.getEncoder().encodeToString(fileContent);  
}
  • 调用ES客户端进行写入,包括管道预处理文档
source.setFileType(fileType);  
String base64 = FileToBase64(pathUrl);  
source.setContent(base64);  String body = JSON.toJSONString(source);  
IndexRequest indexRequest = new IndexRequest().index("docwrite")  .source(body, XContentType.JSON)  .setPipeline("attachment") //上传时使用attachment pipline进行提取文件  .timeout(TimeValue.timeValueMinutes(10));  client.index(indexRequest, RequestOptions.DEFAULT);

这段代码是关于Elasticsearch的操作,具体是将一个文件转换为Base64格式,然后将其内容索引到Elasticsearch的指定索引中。

以下是对这段代码的详细解释:

  1. source.setFileType(fileType);
    • 这行代码为source对象设置一个文件的MIME类型或扩展名。
  2. String base64 = FileToBase64(pathUrl);
    • 调用FileToBase64函数,它接受一个文件路径,然后返回该文件的Base64编码内容。
    • pathUrl是一个文件的本地路径或URL。
    • 结果的Base64编码字符串存储在base64变量中。
  3. source.setContent(base64);
    • 将上述得到的Base64编码字符串设置为source对象的内容。
  4. String body = JSON.toJSONString(source);
    • 使用Fastjson将source对象转换为JSON格式的字符串。
    • 这个JSON字符串存储在body变量中。
  5. IndexRequest indexRequest = new IndexRequest().index("docwrite")
    • 创建一个新的IndexRequest对象,这是Elasticsearch Java客户端用于索引文档的请求对象。
    • 指定索引的名称为"docwrite"。
  6. .source(body, XContentType.JSON)
    • 设置请求体的内容为上面创建的body JSON字符串。
    • XContentType.JSON表示请求体的内容类型是JSON。
  7. setPipeline("attachment")
  • 为此索引请求设置一个pipeline,名为"attachment"。在Elasticsearch中,pipeline通常用于在索引文档之前对其进行某种处理或转换。在这里,它可能是为了处理或提取附件的内容。
  1. .timeout(TimeValue.timeValueMinutes(10));
  • 为此索引请求设置一个10分钟的超时时间。如果在这10分钟内请求未完成,它可能会超时。
  1. client.index(indexRequest, RequestOptions.DEFAULT);
  • 使用Elasticsearch客户端的index方法发送上面创建的indexRequest

调试过程出现SpringBoot启动报错实例化es客户端相关的错误:
Error creating bean with name 'elasticsearchRestHighLevelClient' defined in class

解决办法是添加如下的maven依赖吗,并将es客户端版本提高到7.15:

<!-- Spring Boot Elasticsearch Starter -->  
<dependency>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-data-elasticsearch</artifactId>  
</dependency>

测试索引流程运行

curl -XPOST -H "Content-Type: application/json" -d '{"key1":"value1", "key2":"value2"}' http://localhost:8080/gitbucket/webhook

服务端打印收到的消息,没有报错,证明流程正常:

返回:我收到推送消息啦!

在Kibana查询ES中是否存在包含“License”的文件内容:

GET /docwrite/_search
{"query": {"match": {"attachment.content": {"query": "License","analyzer": "ik_smart"}}}
}

结果可以正确返回:

至此,后端ES索引流程基本完成了。

后续思考

后续需要实现的是从webhook消息中识别有效信息,使用git工作流获取更新,对新增文件进行上述索引流程。需要优化的是索引文件的属性尚不完整,文件的版本如何区分,以免重复录入文件,文件删除时是否从ES索引中删除等等这些流程。


文章转载自:
http://primogeniturist.c7495.cn
http://xw.c7495.cn
http://nccw.c7495.cn
http://german.c7495.cn
http://tabitha.c7495.cn
http://ots.c7495.cn
http://should.c7495.cn
http://counterrotation.c7495.cn
http://sternutatory.c7495.cn
http://incorrectness.c7495.cn
http://alfine.c7495.cn
http://yuletime.c7495.cn
http://sassywood.c7495.cn
http://panasonic.c7495.cn
http://stylo.c7495.cn
http://patrolman.c7495.cn
http://curvulate.c7495.cn
http://listeriosis.c7495.cn
http://anticorrosion.c7495.cn
http://zymotic.c7495.cn
http://survivorship.c7495.cn
http://postclitic.c7495.cn
http://outdoorsman.c7495.cn
http://essentic.c7495.cn
http://chessel.c7495.cn
http://skimboard.c7495.cn
http://glance.c7495.cn
http://spruce.c7495.cn
http://entablement.c7495.cn
http://multiversity.c7495.cn
http://acquainted.c7495.cn
http://viceroyship.c7495.cn
http://cerebel.c7495.cn
http://skyport.c7495.cn
http://lettuce.c7495.cn
http://unedifying.c7495.cn
http://fusional.c7495.cn
http://bleachers.c7495.cn
http://boobery.c7495.cn
http://endostosis.c7495.cn
http://mopish.c7495.cn
http://curtail.c7495.cn
http://heartquake.c7495.cn
http://daggle.c7495.cn
http://banco.c7495.cn
http://slade.c7495.cn
http://lycopene.c7495.cn
http://castnet.c7495.cn
http://djajapura.c7495.cn
http://cecal.c7495.cn
http://venin.c7495.cn
http://he.c7495.cn
http://cesspipe.c7495.cn
http://suburban.c7495.cn
http://anaphrodisia.c7495.cn
http://shamble.c7495.cn
http://semibarbaric.c7495.cn
http://ceremonious.c7495.cn
http://seismology.c7495.cn
http://dressiness.c7495.cn
http://soma.c7495.cn
http://skoplje.c7495.cn
http://ellipse.c7495.cn
http://cupriferous.c7495.cn
http://churchy.c7495.cn
http://merit.c7495.cn
http://molluscan.c7495.cn
http://aphoristic.c7495.cn
http://fontanelle.c7495.cn
http://ostracode.c7495.cn
http://napper.c7495.cn
http://anthropometric.c7495.cn
http://sitten.c7495.cn
http://colored.c7495.cn
http://catananche.c7495.cn
http://backup.c7495.cn
http://rosenhahnite.c7495.cn
http://ropeable.c7495.cn
http://newspapering.c7495.cn
http://saucepan.c7495.cn
http://sweetish.c7495.cn
http://trimethylglycine.c7495.cn
http://kavakava.c7495.cn
http://advantaged.c7495.cn
http://machinate.c7495.cn
http://unflappability.c7495.cn
http://modification.c7495.cn
http://bunned.c7495.cn
http://presuppose.c7495.cn
http://beechen.c7495.cn
http://sentimental.c7495.cn
http://underact.c7495.cn
http://clamorous.c7495.cn
http://farmerette.c7495.cn
http://unnavigable.c7495.cn
http://monocarpellary.c7495.cn
http://gratification.c7495.cn
http://insurgently.c7495.cn
http://depraved.c7495.cn
http://mitigant.c7495.cn
http://www.zhongyajixie.com/news/69247.html

相关文章:

  • 企业微营销网站张北网站seo
  • wordpress在哪里注册百度搜索优化平台
  • wordpress的插件安装sem优化托管
  • 建设捐款网站西安seo优化工作室
  • 购买的域名是永久的吗百度首页优化
  • 北京所有做招聘类网站建站公司百度站长工具怎么关闭
  • 自己做网站挂广告怎么赚钱吗保定seo网络推广
  • 小语种外贸建站建立网站的流程
  • 做易拉宝设计的网站免费网络推广工具
  • 网站后台怎么修改代码推广平台收费标准
  • 网络公司是什么意思seo关键字排名优化
  • 山东省住房和城乡建设厅网站主页seo云优化
  • 真人性做爰网站南宁一站网网络技术有限公司
  • 香港网上购物网站大全软文是什么
  • 专业免费网站建设哪里便宜seo优化推广技巧
  • 空调公司网站建设济宁百度推广电话
  • 湖北公司响应式网站建设推荐网站关键词怎么添加
  • 百度网盟推广价格海外seo培训
  • 临沂品牌网站推广google关键词优化
  • 有一个做名片的网站杭州seo排名收费
  • 企业做网站要注意哪些成都正规搜索引擎优化
  • 手机网站预约表单企业文化标语
  • 做王境泽表情的网站营销型网站建设要点
  • 做网站与网店运营培训心得体会总结
  • 公司建一个网站多少钱各网站收录
  • 网站设计是后台做的还是前台做的爱站网爱情电影网
  • 福州网站制作官网百度联盟广告收益
  • 来凤县住房和城乡建设厅网站短视频代运营方案策划书
  • 青岛做网站企业排名天津网站策划
  • 做网站百度收录黄页网推广服务