Skip to content

PgTsQuery

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Owns a PostgreSQL tsquery, lexemes combined with Boolean and phrase operators, as the bytes PostgreSQL stores, as pgrx’s TsQueryBuf does. The default value is the empty tsquery.

public readonly struct PgTsQuery : IComparable<PgTsQuery>, IEquatable<PgTsQuery>

Equality and hashing follow PostgreSQL’s comparison, which ignores an operand’s labels and prefix flag, so ‘a:A’ equals ‘a’, as in SQL and pgrx. Except for identical stored bytes they call PostgreSQL, as parsing, formatting, combining and ordering do, so they need a backend callback.

Implements: IComparable<PgTsQuery>, IEquatable<PgTsQuery>

Matches documents that match both queries, as && does.

public PgTsQuery And(PgTsQuery other)

Parameters:

other — PgTsQuery

The other query.

Returns: PgTsQuery

The combined query.

Orders two tsqueries as PostgreSQL’s comparison operators do.

public int CompareTo(PgTsQuery other)

Parameters:

other — PgTsQuery

The other tsquery.

Returns: int

A negative, zero or positive comparison.

Compares two tsqueries as PostgreSQL’s = does.

public bool Equals(PgTsQuery other)

Parameters:

other — PgTsQuery

The other tsquery.

Returns: bool

Whether PostgreSQL considers them equal.

public override bool Equals(object obj)

Parameters:

obj — object

Returns: bool

Matches documents where a match of the other query follows a match of this one, as <-> or tsquery_phrase(this, other, distance) does.

public PgTsQuery FollowedBy(PgTsQuery other, int distance = 1)

Parameters:

other — PgTsQuery

The query that follows.

distance — int

How many positions later it follows, from 0 to 16384.

Returns: PgTsQuery

The phrase query.

Matches the words of plain text as a phrase with a configuration, as phraseto_tsquery(config, text) does.

public static PgTsQuery FromPhraseText(PgTsConfig config, string text)

Parameters:

config — PgTsConfig

The configuration.

text — string

The words.

Returns: PgTsQuery

The tsquery.

Matches the words of plain text as a phrase with the current configuration, as phraseto_tsquery does.

public static PgTsQuery FromPhraseText(string text)

Parameters:

text — string

The words.

Returns: PgTsQuery

The tsquery.

Matches every word of plain text with a configuration, as plainto_tsquery(config, text) does.

public static PgTsQuery FromPlainText(PgTsConfig config, string text)

Parameters:

config — PgTsConfig

The configuration.

text — string

The words.

Returns: PgTsQuery

The tsquery.

Matches every word of plain text with the current configuration, as plainto_tsquery does.

public static PgTsQuery FromPlainText(string text)

Parameters:

text — string

The words.

Returns: PgTsQuery

The tsquery.

Parses a query with a configuration, as to_tsquery(config, text) does.

public static PgTsQuery FromText(PgTsConfig config, string text)

Parameters:

config — PgTsConfig

The configuration.

text — string

The query.

Returns: PgTsQuery

The tsquery.

Exceptions:

  • PgException: The text isn’t a query, SQLSTATE 42601.

Parses a query with the current configuration, normalizing its words, as to_tsquery does.

public static PgTsQuery FromText(string text)

Parameters:

text — string

A query such as fat & rats.

Returns: PgTsQuery

The tsquery.

Exceptions:

  • PgException: The text isn’t a query, SQLSTATE 42601.

Parses web search syntax with a configuration, as websearch_to_tsquery(config, text) does.

public static PgTsQuery FromWebSearchText(PgTsConfig config, string text)

Parameters:

config — PgTsConfig

The configuration.

text — string

The search.

Returns: PgTsQuery

The tsquery.

Parses web search syntax with the current configuration, as websearch_to_tsquery does: quoted phrases, or and a leading -.

public static PgTsQuery FromWebSearchText(string text)

Parameters:

text — string

The search.

Returns: PgTsQuery

The tsquery.

Hashes the operands’ text and the operators in stored order, which PostgreSQL’s comparison distinguishes, as pgrx’s hash does.

public override int GetHashCode()

Returns: int

The hash.

Reads the items in stored prefix order, as pgrx’s TsQuery::items does: each operator precedes its right operand, then its left.

public IReadOnlyList<PgTsQueryItem> GetItems()

Returns: IReadOnlyList<PgTsQueryItem>

The items.

Matches documents that don’t match this query, as !! does.

public PgTsQuery Not()

Returns: PgTsQuery

The negated query.

Matches documents that match either query, as || does.

public PgTsQuery Or(PgTsQuery other)

Parameters:

other — PgTsQuery

The other query.

Returns: PgTsQuery

The combined query.

Parses a tsquery’s text, as a cast to tsquery does, without normalizing words.

public static PgTsQuery Parse(string text)

Parameters:

text — string

A query such as ‘fat’ & (‘rat’ | ‘cat’).

Returns: PgTsQuery

The tsquery.

Exceptions:

Formats the tsquery as PostgreSQL does, such as ‘fat’ & ‘rat’.

public override string ToString()

Returns: string

The text.

Matches documents that match both queries.

public static PgTsQuery operator &(PgTsQuery left, PgTsQuery right)

Parameters:

left — PgTsQuery

The first query.

right — PgTsQuery

The second query.

Returns: PgTsQuery

The combined query.

Matches documents that match either query.

public static PgTsQuery operator |(PgTsQuery left, PgTsQuery right)

Parameters:

left — PgTsQuery

The first query.

right — PgTsQuery

The second query.

Returns: PgTsQuery

The combined query.

public static bool operator ==(PgTsQuery left, PgTsQuery right)

Parameters:

left — PgTsQuery

right — PgTsQuery

Returns: bool

Orders two tsqueries as PostgreSQL does.

public static bool operator >(PgTsQuery left, PgTsQuery right)

Parameters:

left — PgTsQuery

The left tsquery.

right — PgTsQuery

The right tsquery.

Returns: bool

Whether the left sorts last.

Orders two tsqueries as PostgreSQL does.

public static bool operator >=(PgTsQuery left, PgTsQuery right)

Parameters:

left — PgTsQuery

The left tsquery.

right — PgTsQuery

The right tsquery.

Returns: bool

Whether the left doesn’t sort first.

public static bool operator !=(PgTsQuery left, PgTsQuery right)

Parameters:

left — PgTsQuery

right — PgTsQuery

Returns: bool

Orders two tsqueries as PostgreSQL does.

public static bool operator <(PgTsQuery left, PgTsQuery right)

Parameters:

left — PgTsQuery

The left tsquery.

right — PgTsQuery

The right tsquery.

Returns: bool

Whether the left sorts first.

Orders two tsqueries as PostgreSQL does.

public static bool operator <=(PgTsQuery left, PgTsQuery right)

Parameters:

left — PgTsQuery

The left tsquery.

right — PgTsQuery

The right tsquery.

Returns: bool

Whether the left doesn’t sort last.

Matches documents that don’t match the query.

public static PgTsQuery operator !(PgTsQuery query)

Parameters:

query — PgTsQuery

The query.

Returns: PgTsQuery

The negated query.