Bleve

Bleve is a full-text search and indexing library. Rye can create a Bleve index on disk, add documents to it, and run search queries over them.

This package needs a build with -tags "b_contrib,b_bleve".

Create an index

An index needs a mapping, which describes how documents are indexed. The default mapping is usually fine to start with.

; Create a default index mapping
mapping: new-bleve-index-mapping

; Create a new index on disk
idx: new-bleve mapping file://./myindex

You can also reopen an existing index later with open-bleve:

idx: open-bleve file://./myindex

Add documents

Documents are added with an id and a dict of fields.

idx .Index "doc1" { "name" "Neuromancer" "author" "William Gibson" }
idx .Index "doc2" { "name" "Snow Crash" "author" "Neal Stephenson" }
idx .Index "doc3" { "name" "Dune" "author" "Frank Herbert" }

To search, build a query, turn it into a search request, and run it against the index.

; Match query for a term
q: new-match-query "Neuromancer"
req: q .New-search-request
res: idx .Search req

; Print a text summary of the results
print res .Summary

; Or get the matching documents as a list of dicts
hits: res .To-list idx

Custom field mappings

For finer control you can build a custom mapping and describe how each field should be indexed.

mapping: new-bleve-index-mapping

; A text field
name-field: new-bleve-text-field-mapping

; Attach it to a document mapping and add it to the index mapping
doc: new-bleve-document-mapping
doc .Add-field-mapping-at "name" name-field
mapping .Add-document-mapping "default" doc

idx: new-bleve mapping file://./myindex