Re: tsearch matching "barrier"

Oleg Bartunov <[email protected]>
Newsgroups gmane.comp.db.postgresql.openfts.general
Message-ID <[email protected]>
Vladimir,

we discussed tsvector array support but see too many issues.
You can use an additional column with paragraph tsvector, or
another approach, if you know what is a paragraph, you can insert
artificial stopper(s) to the indexed text and query. Then you could
write your own ranking function or hack rank_cd and take into account
that you query shouldn't cross paragraph boundaries - just set rank to zero
or to some minimal value.

Oleg

On Wed, 16 Jan 2008, Vladimir Volovich wrote:

> 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/
> _______________________________________________
> OpenFTS-general mailing list
> OpenFTS-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/openfts-general
>

 	Regards,
 		Oleg
_____________________________________________________________
Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru),
Sternberg Astronomical Institute, Moscow University, Russia
Internet: [email protected], http://www.sai.msu.su/~megera/
phone: +007(495)939-16-83, +007(495)939-23-83

-------------------------------------------------------------------------
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.