Re: tsearch matching "barrier"

Vladimir Volovich <[email protected]>
Newsgroups gmane.comp.db.postgresql.openfts.general
Message-ID <[email protected]>
Hi Florian,

"FA" == Florian Aumeier writes:

 FA> Hi yes, have a look at the "Index structured documents" section in
 FA> http://www.sai.msu.su/~megera/wiki/Tsearch_V2_Notes

thanks for reply, but i did not understand how to apply this to my
problem. the "structured documents" seem to support up to 4 different
sections, but i need unlimited number, and being able to find documents
where at least one of the sections matches the query independently of
other sections.

to clarify my needs, i put the following example below.

create temp table tmp_fts (pk_doc integer, ix tsvector[]);
insert into tmp_fts (pk_doc, ix) values (1, ARRAY[to_tsvector('aaa aab'),to_tsvector('aac aad aaf'),to_tsvector('test')]);
insert into tmp_fts (pk_doc, ix) values (2, ARRAY[to_tsvector('aab aac aaf'),to_tsvector('test aad aag aaf')]);

this creates 2 records, 1 per "document", and the ix field contains an
array of tsvector values, which are thought to be logically independent
parts of the document.

document #1 contains 3 parts shown on separate lines below:

  aaa aab
  aac aad aaf
  test

document #2 contains 2 parts shown on separate lines below:

  aab aac aaf
  test aad aag aaf

the search should find the document only if one of document's parts
wholly matches the query.

the following works:

select pk_doc from tmp_fts where to_tsquery('aab & aaf') @@ any (ix); -- returns 2
select pk_doc from tmp_fts where to_tsquery('aac & aad') @@ any (ix); -- returns 1
select pk_doc from tmp_fts where to_tsquery('aad & aaf') @@ any (ix); -- returns 1 & 2

e.g. a search for 'aab & aaf' returns only document #2, but not
document #1, although document #1 contains the words 'aab' and 'aaf',
but only in separate parts, - no part contains them together.

but unfortunately, indexing does not work:

-- create index ind_tmp_fts on tmp_fts using gin (ix); -- this does not work

i was wondering whether tsearch perhaps could be enhanced to understand
some "barrier token" which will divide the document into parts.

then, i could solve this without creating arrays, by indexing document #1 as:

  aaa aab <BARRIER> aac aad aaf <BARRIER> test

and indexing document #2 as:

  aab aac aaf <BARRIER> test aad aag aaf

and having the @@ operator only search inside parts separated by a
barrier, but not between them. e.g. @@ should not find 'aab & aaf'
in document #1, because they are separated by a barrier token.

Best,
v.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.