Skip to content

Module HTM::LongTermMemory::FulltextSearch

Defined in lib/htm/long_term_memory/fulltext_search.rb

Full-text search using PostgreSQL tsvector and pg_trgm

Performs keyword-based search using: * PostgreSQL full-text search (tsvector/tsquery) for stemmed word matching * Trigram fuzzy matching (pg_trgm) for typos and partial words * Combined scoring: tsvector matches rank higher, trigram provides fallback

Results are cached for performance.

Security: All queries use parameterized placeholders to prevent SQL injection.

Constants

MAX_FULLTEXT_LIMIT

Maximum results to prevent DoS via unbounded queries

TRIGRAM_SIMILARITY_THRESHOLD

Minimum trigram similarity threshold (0.0-1.0) Lower = more fuzzy matches, higher = stricter matching

TSVECTOR_SCORE_BOOST

Score boost for tsvector matches over trigram matches Ensures exact word matches rank above fuzzy matches

Public Instance Methods

search_fulltext(timeframe:, query:, limit:, metadata: {})

Full-text search - @param timeframe [Range] Time range to search - @param query [String] Search query - @param limit [Integer] Maximum results (capped at MAX_FULLTEXT_LIMIT) - @param metadata [Hash] Filter by metadata fields (default: {}) - @return [Array] Matching nodes