日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

lucene Term查询

發布時間:2024/8/23 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的lucene Term查询的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。