By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,781 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,781 IT Pros & Developers. It's quick & easy.

Tsearch2 lexeme position

P: n/a
Hi,

Is it possible to get all the positions of a lexeme in a result-set of a
query? For example, we have the table

TEXT TEXT_IDX
'TSearch2 is very cool' ...

'It would be much cooler with lexeme positions'

Our query is
SELECT text, position FROM thetable WHERE text_idx @@ 'cool'::tsquery;
^^^^^^^^
The result should be something like:
'TSearch2 is very cool', 4
'It would be much cooler with lexeme positions', 5

If not, is there a function that returns the positions of a lexeme in a
single entry?

thanks
Alex

--
Dipl.-Inform. Alexander Rueegg
Bioinformatics Department Faculty of Technology
Bielefeld University
Phone: +49 (0)521-106-3541
Fax: +49 (0)521-106-6488
Room: C02-206
Email: ar*****@techfak.uni-bielefeld.de


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 11 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a


Alexander Regg wrote:
Hi,

Is it possible to get all the positions of a lexeme in a result-set of a
query? For example, we have the table

TEXT TEXT_IDX
'TSearch2 is very cool' ...

'It would be much cooler with lexeme positions'

Our query is
SELECT text, position FROM thetable WHERE text_idx @@ 'cool'::tsquery;
^^^^^^^^
The result should be something like:
'TSearch2 is very cool', 4
'It would be much cooler with lexeme positions', 5

If not, is there a function that returns the positions of a lexeme in a
single entry?


You can write such function, but why do you need it? May be there is more simple
way to resolve your problem?

BTW, lexeme can have more that one position...

--
Teodor Sigaev E-mail: te****@sigaev.ru
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 11 '05 #2

P: n/a
Thank you for your response.
We want to know the distance or sequence of words in a set of
text-entries. So first we try to retrieve the text-entries in which the
words appear using tsearch indexing. After that we want to calculate the
positions of the words in each entry, e.g. parsing the index column of
the retrieved text-entries.
Maybe there exists a function or an easier/cheaper way to get this
information (and which considers that the words maybe occur more than once).

thanks,
Alex

Teodor Sigaev wrote:


Alexander Regg wrote:
Hi,

Is it possible to get all the positions of a lexeme in a result-set of a
query? For example, we have the table

TEXT TEXT_IDX
'TSearch2 is very cool' ...

'It would be much cooler with lexeme positions'

Our query is
SELECT text, position FROM thetable WHERE text_idx @@ 'cool'::tsquery;
^^^^^^^^
The result should be something like:
'TSearch2 is very cool', 4
'It would be much cooler with lexeme positions', 5

If not, is there a function that returns the positions of a lexeme in a
single entry?


You can write such function, but why do you need it? May be there is
more simple way to resolve your problem?

BTW, lexeme can have more that one position...

--

Alexander Rueegg
Email: ar*****@uni-bielefeld.de

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 11 '05 #3

P: n/a
Alexander,

we'd be glad to add such function to tsearch2 in case it'd be useful
for many peoples, not just you.

Oleg
On Thu, 14 Aug 2003, Teodor Sigaev wrote:


Alexander Regg wrote:
Thank you for your response.
We want to know the distance or sequence of words in a set of
text-entries. So first we try to retrieve the text-entries in which the
words appear using tsearch indexing. After that we want to calculate the
positions of the words in each entry, e.g. parsing the index column of
the retrieved text-entries.
Maybe there exists a function or an easier/cheaper way to get this
information (and which considers that the words maybe occur more than
once).


No, it is not exists. The easiest way is to extract this info from tsvector value.


thanks,
Alex

Teodor Sigaev wrote:


Alexander Regg wrote:

Hi,

Is it possible to get all the positions of a lexeme in a result-set of a
query? For example, we have the table

TEXT TEXT_IDX
'TSearch2 is very cool' ...

'It would be much cooler with lexeme positions'

Our query is
SELECT text, position FROM thetable WHERE text_idx @@ 'cool'::tsquery;
^^^^^^^^
The result should be something like:
'TSearch2 is very cool', 4
'It would be much cooler with lexeme positions', 5

If not, is there a function that returns the positions of a lexeme in a
single entry?
You can write such function, but why do you need it? May be there is
more simple way to resolve your problem?

BTW, lexeme can have more that one position...



Regards,
Oleg
__________________________________________________ ___________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: ol**@sai.msu.su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #4

P: n/a


Alexander Regg wrote:
Thank you for your response.
We want to know the distance or sequence of words in a set of
text-entries. So first we try to retrieve the text-entries in which the
words appear using tsearch indexing. After that we want to calculate the
positions of the words in each entry, e.g. parsing the index column of
the retrieved text-entries.
Maybe there exists a function or an easier/cheaper way to get this
information (and which considers that the words maybe occur more than
once).
No, it is not exists. The easiest way is to extract this info from tsvector value.


thanks,
Alex

Teodor Sigaev wrote:


Alexander Regg wrote:
Hi,

Is it possible to get all the positions of a lexeme in a result-set of a
query? For example, we have the table

TEXT TEXT_IDX
'TSearch2 is very cool' ...

'It would be much cooler with lexeme positions'

Our query is
SELECT text, position FROM thetable WHERE text_idx @@ 'cool'::tsquery;
^^^^^^^^
The result should be something like:
'TSearch2 is very cool', 4
'It would be much cooler with lexeme positions', 5

If not, is there a function that returns the positions of a lexeme in a
single entry?


You can write such function, but why do you need it? May be there is
more simple way to resolve your problem?

BTW, lexeme can have more that one position...


--
Teodor Sigaev E-mail: te****@sigaev.ru
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.