Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

Getting wrong results from fulltext search in PostgreSQL

$
0
0

This is the query which I am running. The keyword “exhausted” is present only in one of the rows but I am getting all 3 rows.

How to avoid the rows where the keyword is not present?

DDL:

CREATE TABLE semantified_content_key_word
(
  id bigint NOT NULL,
  semantified_content_id bigint,
  key_word_text text,
  content_date timestamp without time zone NOT NULL,
  context_id bigint NOT NULL,
  CONSTRAINT pk_sckw_id PRIMARY KEY (id )
)
WITH (
  OIDS=FALSE
);
ALTER TABLE semantified_content_key_word
  OWNER TO postgres;


-- Index: idx_sckw_kwt

-- DROP INDEX idx_sckw_kwt;

CREATE INDEX idx_sckw_kwt
  ON semantified_content_key_word
  USING gin
  (to_tsvector('english'::regconfig, key_word_text) );

-- Index: idx_sckw_sc_id

-- DROP INDEX idx_sckw_sc_id;

CREATE INDEX idx_sckw_sc_id
  ON semantified_content_key_word
  USING btree
  (semantified_content_id );

Following is the data:

INSERT INTO semantified_content_key_word (id, semantified_content_id, key_word_text, content_date, context_id) VALUES (7347, 7347, ', agreementnumber customer servicecreditdate the guarantor taken exhausted prior being pursuant avoidance doubt shall remain liable case non incomplete', '2014-11-21 00:00:00', 111);

INSERT INTO semantified_content_key_word (id, semantified_content_id, key_word_text, content_date, context_id) VALUES (7356, 7356, ', ; agreementnumber agreementperiod aircraftmodel commencementdate customer enginemodel enginequantity enginetype foddeductibleamount llpminimumbuild servicecreditdate steppedpopularrate takeoffderate termdate turnaroundtime ion ls initiated manager otherwise) inform whether proposed qualified view lnltlated confirm satisfies criteria out article instruct programme accordingly determined meet pursuant paragraph a) treated subject only g) below b)', '2014-11-21 00:00:00', 111);

INSERT INTO semantified_content_key_word (id, semantified_content_id, key_word_text, content_date, context_id) VALUES (7441, 7441, ', activationdate agreementnumber enginemodel enginetype llpminimumbuild servicecreditdate steppedpopularrate turnaroundtime leap-1a as united continental customer 1/ neutral qec configuration engines shop maintenance: each engine ', '2014-11-17 00:00:00', 111);

Select:

select sckw.*
FROM semantified_content_key_word sckw
where TO_TSVECTOR(sckw.key_word_text) @@ TO_TSQUERY('exhausted');

In case of MySQL I am getting the correct result, i.e. only 1 row. The query is:

SELECT * ,MATCH(key_word_text) AGAINST('"exhausted"') 
FROM semantified_content_key_word 
WHERE MATCH(key_word_text) AGAINST('"exhausted"') 

What is the equivalent query in PostgreSQL?


Viewing all articles
Browse latest Browse all 1138

Trending Articles