jxxcarlson / elm-text-search / Text.Search

Basic usage

Let

match =
    Search.withQueryString
        identity
        Search.NotCaseSensitive
        "foo -bar | baz"

Run match on the list

    [ "foo yada", "foo bar", "hehe, baza baza!" ]

It will return

    [ "foo yada", "hehe, baza baza!" ]

The query string foo -bar | baz is of the form P | Q. It will match anything that matches P or Q. The term P is form word1 -word2 It will match anything that contains word1 but not word2. Similarly, word1 word2 matches anything that contains word1 and word2.

Non-string data

Suppose that you want to query data of type List a. You can do this if you have function like digest : a -> String. For example, if

type alias Datum =
  {   title: String
    , tags : List String
    , ... other stuff ...
   }

Then digest datum = String.join " " title::tags does the job — you can search using

Search.withQueryString
    digest
    Search.NotCaseSensitive
    "foo -bar | baz"

Below we describe the types and functions exported from this module.


type Config
    = CaseSensitive
    | NotCaseSensitive

matchWithQueryStringToResult : (datum -> String) -> Config -> String -> datum -> Result String Basics.Bool

If the query string is well-formed, Ok True/False is returned, the result depending on whether the query string matches datum. If it is ill-formed, Err errorString is returned. At the moment, the error string reads 'ill-formed query'.

withQueryStringToResult : (datum -> String) -> Config -> String -> List datum -> Result String (List datum)

Filter the data list using the query. If the query string is well-formed, Ok filteredList is returned. If it is ill-formed, Err errorString is returned. At the moment, the error string reads 'ill-formed query'.

matchWithQueryString : (datum -> String) -> Config -> String -> datum -> Basics.Bool

If the query string is well-formed, Ok True/False is returned depending on whether the query string matches the datum. If the query string is ill-formed, False is returned.

withQueryString : (datum -> String) -> Config -> String -> List datum -> List datum

Filter the data list using the query. If the query is ill-formed, return the empty list.