In the previous section, we implemented the ElixirDrip text search functionality by using Task.async_stream/5
to search several text files at the same time. The text search function lived on the ElixirDrip.Storage.Search
module and its last iteration could be used like this:
iex> alias ElixirDrip.Storage.Search iex> media_ids = ["25", "8", "6", "7"] iex> search_expression = "media" iex> Search.safe_task_stream_search_for(media_ids, search_expression) %{ "6" => [{1, "Content of media 6."}], "7" => [{1, "Content of media 7."}], "8" => [{1, "Content of media 8."}] }
It returned a map with entries for every searched file whose search ended on the allotted time. For each media id
, it yields a list of two-element tuples, where the first tuple element corresponds to the line where the expression was found and the second element contains the actual line's contents.
Remember that ElixirDrip spawns a CacheWorker
to keep files in memory for a while to speed...