lucene Term查询

查询demo

		Path path = Paths.get(util.Directory.GetAppPath("indexDir"));IndexReader reader = DirectoryReader.open(FSDirectory.open(path));//获取IndexSearcher对象IndexSearcher indexSearcher = new IndexSearcher(reader);Query query = new TermQuery(new Term("title", "国"));//查询数据TopDocs topDocs = indexSearcher.search(query, 10);ScoreDoc[] docs = topDocs.scoreDocs;for (ScoreDoc scoreDoc : docs) {Document res = indexSearcher.doc(scoreDoc.doc);System.out.println(res.get("title"));}

容易犯错警告!!!

在构造Term对象容易大意写成如下

Query query = new Term("国");

则此时利用Term查询不出来结果,因为此时“国”被当做成一个域,并没有检索内容。

切记:利用lucene Term查询一定要记得将域加上去,用来标识搜索词所在的字段名称!!!

Query query = new TermQuery(new Term("title", "国"));

Term类说明文档

介绍:Term术语表示文本中的单词。这是搜索单位。它由两个元素组成,一个字符串形式的单词文本,另一个文本所在字段的名称。请注意,术语可能表示的不仅仅是文本字段中的单词,还包括日期、电子邮件地址、url等。

构造方法:

Term(String fld)fld为域,传入值为空
Term(String fld, BytesRef bytes)fld为域,值为字节流类型
Term(String fld, BytesRefBuilder bytesBuilder)fld为域,值为BytesRefBuilder类型
Term(String fld, String text)fld为域,值为String类型(最常用)

Term方法:

  • field

    public final String field()

    Returns the field of this term. The field indicates the part of a document which this term came from.

  • text

    public final String text()

    Returns the text of this term. In the case of words, this is simply the text of the word. In the case of dates and other types, this is an encoding of the object as a string.

  • toString

    public static final String toString(BytesRef termText)

    Returns human-readable form of the term text. If the term is not unicode, the raw bytes will be printed instead.

  • bytes

    public final BytesRef bytes()

    Returns the bytes of this term, these should not be modified.

  • equals

    public boolean equals(Object obj)

    Overrides:

    equals in class Object

  • hashCode

    public int hashCode()

    Overrides:

    hashCode in class Object

  • compareTo

    public final int compareTo(Term other)

    Compares two terms, returning a negative integer if this term belongs before the argument, zero if this term is equal to the argument, and a positive integer if this term belongs after the argument. The ordering of terms is first by field, then by text.

    Specified by:

    compareTo in interface Comparable<Term>

  • toString

    public final String toString()

    Overrides:

    toString in class Object

  • ramBytesUsed

    public long ramBytesUsed()

    Description copied from interface: Accountable

    Return the memory usage of this object in bytes. Negative values are illegal.

说明文档出处:http://lucene.apache.org/core/8_2_0/core/index.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/508891.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

IndexOptions类说明

IndexOptions是在lucene-core-x.jar包下面&#xff0c;其作用是在新建索引时候选择索引属性。 IndexOptions是一个枚举类&#xff1a; 枚举变量说明&#xff1a; NONE不被索引DOCS_AND_FREQS文档和词频建立索引DOCS_AND_FREQS仅对文档和词频建立索引DOCS_AND_FREQS_AND_POSIT…

【转载保存】lucene正则查询使用注意

今天要分享的是关于lucene中另外一种丰富的查询方式----正则查询&#xff0c;lucene内置了许多的查询API&#xff0c;以及更强大的自定义查询方式的QueryParse&#xff0c;大部分情况下我们使用内置的查询API&#xff0c;基本上就可以满足我们的需求了&#xff0c;但是如果你想…

lucene 各个版本介绍

官方说明文档&#xff1a;https://lucene.apache.org/core/8_3_0/changes/Changes.html#v8.3.0.other 开源中国翻译&#xff1a;https://www.oschina.net/p/lucene

【转载保存】搜索引擎调研文档

搜索引擎选型调研文档 Elasticsearch简介* Elasticsearch是一个实时的分布式搜索和分析引擎。它可以帮助你用前所未有的速度去处理大规模数据。 它可以用于全文搜索&#xff0c;结构化搜索以及分析&#xff0c;当然你也可以将这三者进行组合。 Elasticsearch是一个建立在全…

webmagic抓取实例

git地址&#xff1a;https://github.com/code4craft/webmagic/tree/master/webmagic-samples/src/main/java/us/codecraft/webmagic/samples

lucene详细说明文档

以下部门功能在lucene5以上版本可能有的API所有改变 目录1.简介 2.了解索引操作 2.1倒排索引 2.2字段类型 2.3细分 2.4文件编号 2.5搜索索引 3.创建索引 4.基本索引操作 4.1核心索引类 4.2将数据添加到索引 5.文件和领域 5.1文件 5.2领域 5.3在Lucene中增强文档 1.简介 该索引是…

SimpleDateFormat(线程不安全)与DateTimeFormatter(线程安全)

https://www.liaoxuefeng.com/wiki/1252599548343744/1303985694703650

【转载保存】java8新特性学习

编者注&#xff1a;Java 8已经公布有一段时间了&#xff0c;种种迹象表明Java 8是一个有重大改变的发行版。 在Java Code Geeks上已经有大量的关于Java 8 的教程了&#xff0c;像玩转Java 8——lambda与并发&#xff0c;Java 8 Date Time API 教程&#xff1a; LocalDateTime和…

influxDb 异常:{“error“:“retention policy not found: default“}

第一次用influxDb&#xff0c;通过java客户端插入数据的时候总是报这个异常&#xff0c;后来发现命令行中插入数据是好的&#xff0c;但是客户端就是不行&#xff0c;后来检查代码发现是自己的配置中保留策略名写错了 。 修改代码&#xff1a;将RETENTION_POLICY_DEFAULT值设置…

【转载保存】什么是线程阻塞?为什么会出现线程阻塞?

为什么会出现线程阻塞&#xff1f; 1.睡眠状态&#xff1a;当一个线程执行代码的时候调用了sleep方法后&#xff0c;线程处于睡眠状态&#xff0c;需要设置一个睡眠时间&#xff0c;此时有其他线程需要执行时就会造成线程阻塞&#xff0c;而且sleep方法被调用之后&#xff0c;…

【转载保存】ThreadPoolExecutor类使用详解

线程启动原理线程中断机制多线程实现方式FutureTask实现原理线程池之ThreadPoolExecutor概述线程池之ThreadPoolExecutor使用线程池之ThreadPoolExecutor状态控制线程池之ThreadPoolExecutor执行原理线程池之ScheduledThreadPoolExecutor概述线程池的优雅关闭实践 转载&#x…

maven (http://repo1.maven.org/maven2/): Failed to transfer file 和PKIX path building failed: sun.secu

<?xml version"1.0" encoding"UTF-8"?> <settings xmlns"http://maven.apache.org/SETTINGS/1.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/SETTINGS/1.0.…

java中String、StringBuffer equals使用注意

equals方法 我们知道每个类其基类都是Object&#xff0c;Object默认的equals方式是: public boolean equals(Object obj) {if (this obj) {//先进行地址比较return true;}上面可以看出Object的equals方法比较两个对象的地址是否相等。 接着我们来说下String的equals方法实现…

maven 无效的源发行版11

我看自己的jdk配置都为8&#xff0c;感觉没问题&#xff0c;后来发现自己pom.xml文件配置的如下&#xff1a; <build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId>…

去除html,获取某个标签里面内容

Document document Jsoup.parse(content);Elements ps document.getElementsByTag("p");//要解析的标签String pText "";for(Element p: ps){pText pText p.text();}

分布式集群架构场景解决方案学习笔记

课程学习 一致性哈希算法集群时钟同步问题分布式ID解决方案分布式任务调度问题session共享(一致性)问题 一致性哈希算法 一致性哈希算法在1997年由麻省理工学院的Karger等人在解决分布式Cache中提出的&#xff0c;设计目标是为了解决因特网中的热点(Hot spot)问题&#xff0c…

@NotNull和@NonNull区别和使用

https://www.jianshu.com/p/32327ca2365f

常用的lucene分词器-笔记

1、 StopAnalyzer StopAnalyzer能过滤词汇中的特定字符串和词汇&#xff0c;并且完成大写转小写的功能。 2、 StandardAnalyzer StandardAnalyzer根据空格和符号来完成分词&#xff0c;还可以完成数字、字母、E-mail地址、IP地址以及中文字符的分析处理&#xff0c;还可以支…

分布式学习-总结

文章目录分布式理论分布式系统定义以及面临的问题分布式系统定义分布式面临的问题通信异常网络分区三态节点故障分布式理论&#xff1a;一致性概念分布式一致性的提出强一致性弱一致性最终一致性分布式事务CAP定理什么是CAP理论&#xff1f;为什么只能3选2能不能解决3选2的问题…