Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WR7dy-00024B-FC for pgsql-bugs@arkaria.postgresql.org; Fri, 21 Mar 2014 22:10:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WR7dx-0006Nv-VK for pgsql-bugs@arkaria.postgresql.org; Fri, 21 Mar 2014 22:10:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WR7dx-0006Np-73 for pgsql-bugs@postgresql.org; Fri, 21 Mar 2014 22:10:25 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WR7dp-0005nv-JQ for pgsql-bugs@postgresql.org; Fri, 21 Mar 2014 22:10:24 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1WR7dn-0007Oh-Tj; Fri, 21 Mar 2014 18:10:15 -0400 Date: Fri, 21 Mar 2014 18:10:15 -0400 From: Bruce Momjian To: Tom Lane Cc: Alexander Hill , pgsql-bugs@postgresql.org Subject: Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd Message-ID: <20140321221015.GA26056@momjian.us> References: <20140131212251.GQ19957@momjian.us> <20140211154537.GA2289@momjian.us> <20140212143151.GA12551@momjian.us> <20140321134323.GA1701@momjian.us> <16233.1395413118@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="sm4nu43k4a2Rpi4c" Content-Disposition: inline In-Reply-To: <16233.1395413118@sss.pgh.pa.us> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) 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 --sm4nu43k4a2Rpi4c Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Mar 21, 2014 at 10:45:18AM -0400, Tom Lane wrote: > Bruce Momjian writes: > > OK, combined patch attached. Is this correct? I keep hoping someone > > else will chime in with an opinion on this, but at this point I think > > what you have done is clear enough for me to commit for 9.4. > > That whole function is seriously undercommented; I suppose it's not this > patch's charter to fix that, but we could at least write > > ! /* ignore words without positions */ > ! entry++; > ! continue; > > The proposed new documentation text seems pretty badly written. How about > > This function requires lexeme positional information to perform its > calculation. Therefore it ignores any stripped lexemes in the > tsvector. If there are no unstripped lexemes in the input, the > result will be zero. > > The parenthetical "See" text is ok. OK, thanks. Updated patch attached. If Alexander Hill would like to add more C comments to any of the ts*.c files, or docs explaining what "cover desity" is, I would be glad to include those in the patch as well. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --sm4nu43k4a2Rpi4c Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="rank.diff" diff --git a/doc/src/sgml/textsearch.sgml b/doc/src/sgml/textsearch.sgml new file mode 100644 index 604e545..9e78286 *** a/doc/src/sgml/textsearch.sgml --- b/doc/src/sgml/textsearch.sgml *************** SELECT plainto_tsquery('english', 'The F *** 889,897 **** ! This function requires positional information in its input. ! Therefore it will not work on stripped tsvector ! values — it will always return zero. --- 889,901 ---- ! This function requires lexeme positional information to perform ! its calculation. Therefore, it ignores any stripped ! lexemes in the tsvector. If there are no unstripped ! lexemes in the input, the result will be zero. (See for more information ! about the strip function and positional information ! in tsvectors.) diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c new file mode 100644 index c9e71c9..dcb681d *** a/src/backend/utils/adt/tsrank.c --- b/src/backend/utils/adt/tsrank.c *************** get_docrep(TSVector txt, QueryRepresenta *** 658,665 **** } else { ! dimt = POSNULL.npos; ! post = POSNULL.pos; } while (cur + dimt >= len) --- 658,666 ---- } else { ! /* ignore words without positions */ ! entry++; ! continue; } while (cur + dimt >= len) diff --git a/src/test/regress/expected/tsearch.out b/src/test/regress/expected/tsearch.out new file mode 100644 index 9341dbe..d22d345 *** a/src/test/regress/expected/tsearch.out --- b/src/test/regress/expected/tsearch.out *************** S. T. Coleridge (1772-1834) *** 596,601 **** --- 596,615 ---- 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 new file mode 100644 index 9fd1207..fa460cd *** a/src/test/regress/sql/tsearch.sql --- b/src/test/regress/sql/tsearch.sql *************** Water, water, every where, *** 165,170 **** --- 165,176 ---- 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, --sm4nu43k4a2Rpi4c 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 --sm4nu43k4a2Rpi4c--