<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] > [github](https://github.com/blevesearch/bleve) ## 概述 * 索引任何 Go 數據結構(包括 JSON) * 強大的配置支持智能默認設置 * 支持的字段類型: * `text`,,,,,,,,`number`?`datetime`?`boolean`?`geopoint`?`geoshape`?`IP`?`vector` * 支持的查詢類型: * 術語、短語、匹配、匹配短語、前綴、模糊 * 連詞、析取、布爾 (`must`/`should`/`must_not`) * 術語范圍、數字范圍、日期范圍 * [地理空間](https://github.com/blevesearch/bleve/blob/master/geo/README.md) * 簡單[查詢字符串語法](http://www.blevesearch.com/docs/Query-String-Query/) * [向量搜索](https://github.com/blevesearch/bleve/blob/master/docs/vectors.md) * [tf-idf](https://en.wikipedia.org/wiki/Tf-idf)評分 * 查詢時間提升 * 使用文檔片段突出顯示搜索結果匹配項 * 聚合/方面支持: * 條款方面 * 數字范圍方面 * 日期范圍方面 ## 語法 ## 示例 ### 索引存儲方式 已文件形式存放索引 ``` mapping := bleve.NewIndexMapping() index, err := bleve.New("example.bleve", mapping) if err != nil { panic(err) } ``` 純內存索引 ``` indexMapping := bleve.NewIndexMapping() index, err := bleve.NewMemOnly(indexMapping) ``` ### 創建索引 ``` func CreateOrLoadIndex() (bleve.Index, error) { open, err := bleve.Open("example.bleve") if err != nil { if err != bleve.ErrorIndexPathDoesNotExist { return nil, err } open, err = bleve.New("example.bleve", bleve.NewIndexMapping()) if err != nil { return nil, err } } return open, nil } ``` ### 添加索引 #### 單個 ``` //WriteIndex 寫入單條索引,如果索引已經存在則刪除重建 func WriteIndex(index bleve.Index) error { for i := 0; i < 10; i++ { idStr := strconv.Itoa(i) _ = index.Delete(idStr) if err := index.Index(idStr, Meta{ Id: i, Body: "test bodyindex" + idStr, From: "test bodyindex" + idStr, }); err != nil { return err } } return nil } ``` #### 批量寫入索引(推薦) ``` //WriteBatchIndex 批量寫入索引數據 func WriteBatchIndex(index bleve.Index) error { batchDel := index.NewBatch() batchAdd := index.NewBatch() for i := 0; i < 10; i++ { idStr := strconv.Itoa(i) batchDel.Delete(idStr) if err := batchAdd.Index(idStr, Meta{ Id: i, Body: "test bodyindex" + idStr, From: "test bodyindex" + idStr, }); err != nil { return err } } _ = index.Batch(batchDel) return index.Batch(batchAdd) } ``` ### 搜索指指定索引 ``` func ReadFieldIndex(index bleve.Index) (*bleve.SearchResult, error) { query := bleve.NewMatchQuery("body") query.SetField("from") request := bleve.NewSearchRequest(query) search, err := index.Search(request) if err != nil { return nil, err } return search, nil } ``` ### 翻頁 ``` query := bleve.NewMatchQuery("test") page := 1 pageSize := 2 from := (page - 1) * pageSize searchRequest := bleve.NewSearchRequestOptions(query, pageSize, from, false) ``` ### 語法高亮 ``` func main() { // 創建或打開一個新的索引 indexMapping := bleve.NewIndexMapping() index, err := bleve.NewMemOnly(indexMapping) if err != nil { log.Fatal(err) } // 創建一些示例文檔 docs := []struct { ID string Title string Body string }{ {ID: "1", Title: "Hello World", Body: `1.右鍵群組設置接收消息不 World`}, {ID: "2", Title: "Go Programming", Body: "Go is an open-source programming language search World"}, {ID: "3", Title: "Bleve search", Body: " is a full-text and indexing library written in Go."}, } // 索引這些文檔 for _, doc := range docs { err = index.Index(doc.ID, doc) if err != nil { log.Fatal(err) } } request := bleve.NewSearchRequest(bleve.NewMatchQuery("World")) request.Highlight = bleve.NewHighlight() searchResults, err := index.Search(request) if err != nil { log.Fatal(err) } // 打印搜索結果 fmt.Println("Search Results:") for _, hit := range searchResults.Hits { fmt.Printf("%#v\n", hit.Fragments) fmt.Printf("Document ID: %s, Score: %f\n", hit.ID, hit.Score) //search.FieldFragmentMap{"Body":[]string{"1.右鍵群組設置接收消息不 <mark>World</mark> "}, "Title":[]string{"Hello <mark>World</mark>"}} //Document ID: 1, Score: 0.496907 } // 當關鍵詞在 body 和title 被同時匹配時,會同時輸出 //output: //search.FieldFragmentMap{"Body":[]string{"1.右鍵群組設置接收消息不 <mark>World</mark>"}, "Title":[]string{"Hello <mark>World</mark>"}} //Document ID: 1, Score: 0.353553 //search.FieldFragmentMap{"Body":[]string{"Go is an open-source programming language search <mark>World</mark>"}} //Document ID: 2, Score: 0.316228 } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看