Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id E94D6B5DBC4 for ; Tue, 14 Jun 2011 19:33:49 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 21174-02 for ; Tue, 14 Jun 2011 22:33:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-px0-f174.google.com (mail-px0-f174.google.com [209.85.212.174]) by mail.postgresql.org (Postfix) with ESMTP id 208FAB5D803 for ; Tue, 14 Jun 2011 19:33:42 -0300 (ADT) Received: by pxi15 with SMTP id 15so4191409pxi.33 for ; Tue, 14 Jun 2011 15:33:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=uxV3Ka94MsRaGJZY+Ef9MF7ik15e9TfAyofp/p1wc5Q=; b=Kqsh0pFktQdzdAESmyzmKcdHxes/905d5etIirw9QzOmNtOCkD9ALShVlXeydsSTjg SGCqBGiZu+ZFBZV0HempRe+cQiHrW7GjV2/PosJzjimAiA7V7QrRf3mNJ60LLzWYCST4 PbM6/rrt8fsJsWTT01LzMrK3AVCaDwUakR26Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=Tf+yPKVXyDV8z4JxwqlLcbclLVuBcw7+TyFsUVmnfT37vjYKonCz8cC9iqMhFrjDk+ u3g46OFZlBfzLyYDAYB+1RqoE/KquKrLwueYJSv90BWN9ykRC5OWEp5VTLhTJUk7oL6P D8yg8QuwNt48x4QhNcAWXctMbmW7Ey0La/CMY= MIME-Version: 1.0 Received: by 10.68.0.99 with SMTP id 3mr3452543pbd.375.1308090822013; Tue, 14 Jun 2011 15:33:42 -0700 (PDT) Received: by 10.68.50.40 with HTTP; Tue, 14 Jun 2011 15:33:41 -0700 (PDT) In-Reply-To: <4DF7CEA5.4090400@emolecules.com> References: <4DF7275C020000250003E59F@gw.wicourts.gov> <4DF7399B020000250003E5AB@gw.wicourts.gov> <4DF7CEA5.4090400@emolecules.com> Date: Tue, 14 Jun 2011 18:33:41 -0400 Message-ID: Subject: Re: tsvector limitations From: Tim To: Craig James Cc: pgsql-admin@postgresql.org Content-Type: multipart/alternative; boundary=bcaec5215553c7b1d604a5b3a038 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.897 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201106/75 X-Sequence-Number: 37701 --bcaec5215553c7b1d604a5b3a038 Content-Type: text/plain; charset=ISO-8859-1 Hi Craig, Thanks for writing. If one were to try to increase the limitation of tsvectors (I'm not sure I need to yet; this thread is mainly to determine that.) Instead of using a solution involving a "vocabulary" file, one would probably be better off discarding tsvectors making a vocabulary table then linking it to documents with a (dict_id, hit_count, word_id) table It would be faster, smaller, and more accurate because it would not contain the now useless position information, while it would contain the otherwise lost word count information. I wonder if anyone has any incite on the inner workings of ORACLE/MSSQL/etc FTS. Maybe there is a common design pattern I/we can use to handle text files of non trivial vocabulary that preserves position information. I'm not sure a (dict_id, position, word_id) table would be queryable in a useful way because as far as I can think at the moment there is no good way to compare the position in different rows with SQL. I will collect a few more sample files to see how much I relay need this .... multi-language files are probably the worst offenders. On Tue, Jun 14, 2011 at 5:12 PM, Craig James wrote: > On 6/14/11 1:42 PM, Tim wrote: > > So I ran this test: > unzip -p text.docx word/document.xml | perl -p -e > 's/<.+?>/\n/g;s/[^a-z0-9\n]/\n/ig;'|grep ".." > text.txt > ls -hal ./text.* > #-rwxrwxrwx 1 postgres postgres 15M 2011-06-14 15:12 ./text.docx > #-rwxrwxrwx 1 postgres postgres 29M 2011-06-14 15:17 ./text.txt > mv /tmp/text.* /var/lib/postgresql/9.0/main/ > cd ~/;psql -d postgres > #psql (9.0.4) > CREATE DATABASE test; > \q > cd ~/;psql -d test > CREATE TABLE test(title VARCHAR(256), data OID, words TSVECTOR); > INSERT INTO test VALUES ( 'text.docx', LO_IMPORT('text.docx'), > TO_TSVECTOR(pg_read_file('text.txt' ,0, 100000000)) ); > > and I got this: > #ERROR: string is too long for tsvector (30990860 bytes, max 1048575 > bytes) > > doing the math > echo "scale=3;29/(30990860/1048575)"|bc #==0.981 > > Indicates a (worst case) limit of searching only the first 1MB of a text > file before you need to start building your own search maybe on top of > tsvector. > The year is 2011 I don't think searching a 2MB text file is to much to > expect. > > The novel "Hawaii" at 960 pages is roughly 1MB. tsvector was intended for > documents (web pages, news articles, corporate memos, ...), not for books. > What you're asking for is interesting, but you can't complain that an > open-source project that was designed for a different purpose doesn't meet > your needs. > > So how am I to use the PGSQL FTS as a "full text search" when the above > example can only handle a "small or partial text search"? > If I'm not missing anything maybe the documentation should be adjusted > accordingly. > > Maybe a better question is, "So how am I to use PGSQL FTS as a "massively > huge text search" when it was designed for nothing bigger than "huge text > search"? > > Any thoughts or alternatives are most welcome. > > I'm curious how tsvector could be useful on a 29 MB document. That's > roughly one whole encyclopedia set. A document that size should have a huge > vocabulary, and tsvector's index would be saturated. > > However, if the vocabulary in this 29 MB document isn't that big, then you > might consider creating a smaller "document." You could write a Perl script > that scans the document and creates a dictionary which it writes out as a > secondary "vocabulary" file that's a list of the unique words in your > document. Create an auxillary column in your database to hold this > vocabulary for each document, and use tsvector to index that. The perl > program would be trivial, and tsvector would be happy. > > Craig > > --bcaec5215553c7b1d604a5b3a038 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi Craig,

Thanks for writing.

If one were to try to increase = the limitation of tsvectors (I'm not sure I need to yet; this thread is= mainly to determine that.)
Instead of using a solution involving a &quo= t;vocabulary" file,
one would probably be better off discarding tsvectors making a vocabulary t= able then linking it to documents with a (dict_id, hit_count, word_id) tabl= e
It would be faster, smaller, and more accurate because it would not co= ntain the now useless position information, while it would contain the othe= rwise lost word count information.

I wonder if anyone has any incite on the inner workings of ORACLE/MSSQL= /etc FTS.
Maybe there is a common design pattern I/we can use to handle = text files of non trivial vocabulary that preserves position information. I'm not sure a (dict_id, position, word_id) table would be queryable in= a useful way
because as far as I can think at the moment there is no go= od way to compare the position in different rows with SQL.

I will co= llect a few more sample files to see how much I relay need this .... multi-= language files are probably the worst offenders.
=A0


On Tue, Jun 14, 2011 at 5:12 PM, = Craig James <craig_james@emolecules.com> wrote:
=20 =20 =20 =20
On 6/14/11 1:42 PM, Tim wrote:
So I ran this test:
unzip -p text.docx word/document.xml | perl -p -e 's/<.+?>/\n/g;s/[^a-z0-9\n]/\n/ig;'|grep "..&quo= t; > text.txt
ls -hal ./text.*
#-rwxrwxrwx 1 postgres postgres 15M 2011-06-14 15:12 ./text.docx #-rwxrwxrwx 1 postgres postgres 29M 2011-06-14 15:17 ./text.txt
mv /tmp/text.* /var/lib/postgresql/9.0/main/
cd ~/;psql -d postgres
#psql (9.0.4)
CREATE DATABASE test;
\q
cd ~/;psql -d test
CREATE TABLE test(title VARCHAR(256), data OID, words TSVECTOR); INSERT INTO test VALUES (=A0 'text.docx',=A0 LO_IMPORT('text.docx'),=A0 TO_TSVECTOR(pg_read_file('te= xt.txt' ,0, 100000000))=A0 );

and I got this:
#ERROR:=A0 string is too long for tsvector (30990860 bytes, max 1048575 bytes)

doing the math
echo "scale=3D3;29/(30990860/1048575)"|bc #=3D=3D0.981

Indicates a (worst case) limit of searching only the first 1MB of a text file before you need to start building your own search maybe on top of tsvector.
The year is 2011 I don't think searching a 2MB text file is to much to expect.
The novel "Hawaii" at 960 pages is roughly 1MB.=A0 tsvector w= as intended for documents (web pages, news articles, corporate memos, ...), not for books.=A0 What you're asking for is interesting, but = you can't complain that an open-source project that was designed for a different purpose doesn't meet your needs.

So how am I to use the PGSQL FTS as a "f= ull text search" when the above example can only handle a "small or = partial text search"?
If I'm not missing anything maybe the documentation should be adjusted accordingly.
Maybe a better question is, "So how am I to use PGSQL FTS as a "massively huge text search" when it was designed for nothing= bigger than "huge text search"?

Any thoughts or alternatives are most welcome= .
I'm curious how tsvector could be useful on a 29 MB document.=A0 That's roughly one whole encyclopedia set.=A0 A document that size should have a huge vocabulary, and tsvector's index would be saturated.

However, if the vocabulary in this 29 MB document isn't that big, then you might consider creating a smaller "document."=A0 You= could write a Perl script that scans the document and creates a dictionary which it writes out as a secondary "vocabulary" file that'= ;s a list of the unique words in your document.=A0 Create an auxillary column in your database to hold this vocabulary for each document, and use tsvector to index that.=A0 The perl program would be trivial, and tsvector would be happy.

Craig


--bcaec5215553c7b1d604a5b3a038--