Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDFWy-0005QN-4v for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Feb 2014 15:45:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WDFWx-0006kz-LE for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Feb 2014 15:45:51 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDFWw-0006ks-JN for pgsql-bugs@postgresql.org; Tue, 11 Feb 2014 15:45:50 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDFWl-0007SC-33 for pgsql-bugs@postgresql.org; Tue, 11 Feb 2014 15:45:49 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1WDFWj-0001D5-5T; Tue, 11 Feb 2014 10:45:37 -0500 Date: Tue, 11 Feb 2014 10:45:37 -0500 From: Bruce Momjian To: Alexander Hill Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Message-ID: <20140211154537.GA2289@momjian.us> References: <20140131212251.GQ19957@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="1yeeQ81UyVL57Vl7" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --1yeeQ81UyVL57Vl7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Feb 7, 2014 at 02:07:59AM +0800, Alexander Hill wrote: > Hi Bruce, all, > > I think this can be solved (if it's agreed that it's a bug) in a pretty > straightforward way: when creating the document representation used in > calculating cover density rank, we can just skip lexemes with no position > entirely. > > Fix and tests here: https://github.com/AlexHill/postgres/compare/bug_8354 > > As a patch file here: https://github.com/AlexHill/postgres/commit/ > cd522b254d166d569b86803115f0f499864e949b.patch OK, great. I am attaching this patch. Would this change the contents of any indexes? That would be a problem for pg_upgrade. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --1yeeQ81UyVL57Vl7 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="tsrank.patch" diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c index c9e71c9..bb220d4 100644 --- a/src/backend/utils/adt/tsrank.c +++ b/src/backend/utils/adt/tsrank.c @@ -658,8 +658,8 @@ } else { - dimt = POSNULL.npos; - post = POSNULL.pos; + entry++; + continue; } while (cur + dimt >= len) diff --git a/src/test/regress/expected/tsearch.out b/src/test/regress/expected/tsearch.out index 9341dbe..3bbfb655 100644 --- a/src/test/regress/expected/tsearch.out +++ b/src/test/regress/expected/tsearch.out @@ -596,6 +596,20 @@ S. T. Coleridge (1772-1834) 0.1 (1 row) +SELECT ts_rank_cd(strip(to_tsvector('both stripped')), + to_tsquery('both&stripped')); + ts_rank_cd +------------ + 0 +(1 row) + +SELECT ts_rank_cd(to_tsvector('unstripped') || strip(to_tsvector('stripped')), + to_tsquery('unstripped&stripped')); + ts_rank_cd +------------ + 0 +(1 row) + --headline tests SELECT ts_headline('english', ' Day after day, day after day, diff --git a/src/test/regress/sql/tsearch.sql b/src/test/regress/sql/tsearch.sql index 9fd1207..1f21826 100644 --- a/src/test/regress/sql/tsearch.sql +++ b/src/test/regress/sql/tsearch.sql @@ -165,6 +165,12 @@ Water, water, every where, S. T. Coleridge (1772-1834) '), to_tsquery('english', 'ocean')); +SELECT ts_rank_cd(strip(to_tsvector('both stripped')), + to_tsquery('both&stripped')); + +SELECT ts_rank_cd(to_tsvector('unstripped') || strip(to_tsvector('stripped')), + to_tsquery('unstripped&stripped')); + --headline tests SELECT ts_headline('english', ' Day after day, day after day, -- 1.8.5.1 --1yeeQ81UyVL57Vl7 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --1yeeQ81UyVL57Vl7--