Giter Club home page Giter Club logo

setrank's Introduction

float4 ts_rank_tfidf(text STATTABLE
					  [, float4[] weights]
					  tsvector,
					  tsquery
					  [, int flags])

STATTABLE:
    Name of table stored set-wide statistic. Table should be
	defined as
	CREATE TABLE table_name (
			value   text UNIQUE,
			ndoc    int4 (or bigint)  NOT NULL CHECK (ndoc>0)
	);
	And row with null value means total number of documents.
	See an examples in sql/setrank.sql file

example:

Create STATTABLE:

                 Table "public.apod"
  Column  |   Type   | Collation | Nullable | Default
----------+----------+-----------+----------+---------
 title    | text     |           |          |
 body     | text     |           |          |
 sdate    | date     |           |          |
 keywords | text     |           |          |
 id       | integer  |           |          |
 fts      | tsvector |           |          |
Indexes:

select word, ndoc into apod_stat  from ts_stat('select fts from apod') order by ndoc desc;
insert into apod_stat values(NULL, 1754);

-- 'star' is very common word

select title, ts_rank_tfidf('apod_stat', fts, to_tsquery('x-ray:a | star:a')) as rank from apod where fts @@ to_tsquery('x-ray:a| star:a') order by rank desc limit 10;
                    title                    |   rank
---------------------------------------------+----------
 X-ray Moon and X-ray Star                   | 0.218907
 X-Ray Pulsar                                |   0.1818
 The X-Ray Sky                               | 0.178291
 X-Ray Pleiades                              | 0.177293
 X-Ray Pleiades                              | 0.177293
 X-Ray Pleiades                              | 0.177293
 XMM-Newton First Light: X-Rays From The LMC | 0.176329
 The X-ray Timing Explorer                   | 0.175857
 X-Rays From The Galactic Center             | 0.175857
 X-Ray Jet From Centaurus A                  | 0.175523
(10 rows)


select title, ts_rank_cd(fts, to_tsquery('x-ray:a | star:a')) as rank from apod where fts @@ to_tsquery('x-ray:a| star:a') order by rank desc limit 10;
           title            |  rank
----------------------------+---------
 X-ray Moon and X-ray Star  | 3.66667
 X-Ray Stars Of Orion       |       2
 The Pleiades Star Cluster  |       1
 X-Ray Jet From Centaurus A |       1
 Star Wars in NGC 664       |       1
 The Pleiades Star Cluster  |       1
 Stars in the Infrared Sky  |       1
 The X-Ray Moon             |       1
 The Pleiades Star Cluster  |       1
 The Crab Nebula in X-Rays  |       1
(10 rows)

setrank's People

Contributors

obartunov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.