Wraith.Search (Wraith v0.1.0)

View Source

Site search over published posts and pages, in memory: an inverted index in ETS keyed by word, rebuilt from the store on boot and kept fresh from Wraith.Content events. Titles weigh 5, tags 3, the excerpt 2, the body 1; a prefix match on the last word makes search-as-you-type work.

The index only ever holds what an anonymous reader may see: for members and paid posts that is the part above the paywall (Wraith.Content.readable_markdown/2), so neither matching nor snippets can leak gated text.

Words live in an ordered_set, so a prefix is a bounded walk with :ets.next/2, not a scan of the whole table. The boot rebuild is retried with backoff if the store is unreachable — the node comes up with an empty index rather than crash-looping.

search/2 returns [%{post, score, snippet}], best first.

Summary

Functions

Returns a specification to start this module under a supervisor.

Rebuild the whole index from the store.

Posts matching query, up to limit.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

index(post)

rebuild()

Rebuild the whole index from the store.

remove(post)

search(query, limit \\ 10)

@spec search(String.t(), pos_integer()) :: [
  %{post: map(), score: number(), snippet: String.t()}
]

Posts matching query, up to limit.

start_link(opts \\ [])