package granary

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Granary_sql.Fts_querySource

FTS query string parser.

Parses a MATCH query string into a structured query tree.

Syntax:

  • Space-separated terms → implicit AND
  • term OR term → OR
  • -term or NOT term → NOT (negation — must be combined with a positive term)
  • "term1 term2" → phrase (terms must appear consecutively in same column)
  • term* → prefix search

All terms are lowercased before matching.

Sourcetype fts_term =
  1. | FT_exact of string
    (*

    single exact term

    *)
  2. | FT_prefix of string
    (*

    prefix: "foo*" stored as "foo"

    *)
  3. | FT_phrase of string list
    (*

    phrase: consecutive terms

    *)
Sourcetype t =
  1. | FQ_and of t list
    (*

    all must match (default for spaces)

    *)
  2. | FQ_or of t list
    (*

    any must match

    *)
  3. | FQ_not of t
    (*

    must NOT match; used inside FQ_and

    *)
  4. | FQ_term of fts_term
Sourceval parse : string -> (t, string) result

Parse a raw MATCH query string. Returns Error msg on malformed input.

Sourceval collect_terms : t -> fts_term list

Collect all positive (non-negated) terms from a query, for posting-list lookups.

Sourceval pp : Format.formatter -> t -> unit

Pretty-print a query tree in a parenthesised AND/OR/NOT form.