orus-io/elm-simple-text-index/1.0.1

SimpleTextIndex

Init

type Index doc

An Index holds data to quickly find doc document given doc substring of its indexed fields

new : Config doc -> Index doc

Creates doc new empty Index

Configure

type Config doc

A Config is required to add/search in an Index

{ ref : doc -> String
, fields : List (doc -> String)
, normalize : String -> String
}
-> Config doc

Create doc config

  • ref extracts the unique id of a document. It will be used to deduplicate results

  • fields is a list of content extractors. They return the text to index.

  • normalize is called to simplify strings before being indexed, and on the searched text.

A typical config is:

{ ref = .id
, fields = [ .name, .description ]
, normalize = Sring.toLower >> String.Normalize.removeDiacritics
}

Set the maximum number of results to return on a search

The default value is 1000

This value is indicative only and result may be bigger

setConfig : Config doc -> Index doc -> Index doc

Update the index configuration

Insert data

add : doc -> Index doc -> Index doc

Add a document to an index

Search