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
A Config is required to add/search in an Index
config : { 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
}
setMaxResultSize : Basics.Int -> Config a -> Config a
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
add : doc -> Index doc -> Index doc
Add a document to an index
search : String -> Index doc -> List doc
Search a document in the index