Class PgFullTextSearchFunction.Rank

  • All Implemented Interfaces:
    org.hibernate.dialect.function.SQLFunction
    Enclosing class:
    PgFullTextSearchFunction

    public static class PgFullTextSearchFunction.Rank
    extends PgFullTextSearchFunction
    It allows to add an order by clause regarding how fitting a text is according to the values in the tsvector column. This function returns an integer that can be returned in the select clause and order by it. It is strictly not necessary to put it in the select clause, but it helps to know how it orders.

    Examples of usage having p as alias of a product table and searchable_field as the tsvector field:

    - 'fullTextSearchRank(p, p.searchable_field, 'english', 'cat')' this will return an integer that will be higher the more fitting to it the chain with which the tsvector field was and the more times the cat chain appeared on it

    - 'fullTextSearchRank(p, p.searchable_field, 'english', 'cat:* | black:*')' same as before but with substrings and with cat or black

    • Constructor Detail

      • Rank

        public Rank()
    • Method Detail

      • getReturnType

        public org.hibernate.type.Type getReturnType​(org.hibernate.type.Type arg0,
                                                     org.hibernate.engine.spi.Mapping arg1)
      • getRankNormalizationPref

        protected String getRankNormalizationPref()
        Gets rank normalization from a preference, it needs to be an integer. According to Postgresql documentation.

        Since a longer document has a greater chance of containing a query term it is reasonable to take into account document size, e.g., a hundred-word document with five instances of a search word is probably more relevant than a thousand-word document with five instances. Both ranking functions take an integer normalization option that specifies whether and how a document's length should impact its rank. The integer option controls several behaviors, so it is a bit mask: you can specify one or more behaviors using | (for example, 2|4).

        • 0 (the default) ignores the document length
        • 1 divides the rank by 1 + the logarithm of the document length
        • 2 divides the rank by the document length
        • 4 divides the rank by the mean harmonic distance between extents (this is implemented only by ts_rank_cd)
        • 8 divides the rank by the number of unique words in document
        • 16 divides the rank by 1 + the logarithm of the number of unique words in document
        • 32 divides the rank by itself + 1

        Returns:
        numLike String
        See Also:
        PostgreSQL Controlling Text Search