Thread: Tsearch2 lexeme position
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: arueegg@techfak.uni-bielefeld.de
Alexander Rüegg 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: teodor@sigaev.ru
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 Rüegg 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: arueegg@uni-bielefeld.de
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 RЭegg 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 RЭegg 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: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(095)939-16-83, +007(095)939-23-83
Alexander Rüegg 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 Rüegg 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: teodor@sigaev.ru
Hi, this is an answer of thread http://archives.postgresql.org/pgsql-general/2003-08/msg00694.php You say it exist a funktion to fin positions an frequency of lexems for own calculate of an ranking since this time. But where is the description of this? May Im to blind but I spend a lot of time to search in internet for this. http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch-V2-intro.html http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch2-guide.html http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch2-ref.html has to less examples to see it. May it is'nt in?.. I need it to serch terms with more than one lexem and later for an ranking for nearst lexems. greeds Peter Schmelzer
On Thu, 12 May 2005, Peter Schmelzer wrote: > Hi, > > this is an answer of thread > http://archives.postgresql.org/pgsql-general/2003-08/msg00694.php > > You say it exist a funktion to fin positions an frequency of lexems for own > calculate of an ranking since this time. > But where is the description of this? > May Im to blind but I spend a lot of time to search in internet for this. > > http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch-V2-intro.html > http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch2-guide.html > http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch2-ref.html > has to less examples to see it. > May it is'nt in?.. > > I need it to serch terms with more than one lexem and later for an ranking > for nearst lexems. ranking functions is already aware of this. See tsearch2.sql in contrib/tsearch2/sql for examples. We don't have API to specify your own ranking function. Do you really need it ? > > greeds > Peter Schmelzer > > ---------------------------(end of broadcast)--------------------------- > TIP 8: explain analyze is your friend > Regards, Oleg _____________________________________________________________ Oleg Bartunov, sci.researcher, hostmaster of AstroNet, Sternberg Astronomical Institute, Moscow University (Russia) Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(095)939-16-83, +007(095)939-23-83
Hello Oleg Bartunov, Oleg Bartunov schrieb: > On Thu, 12 May 2005, Peter Schmelzer wrote: > >> Hi, >> >> this is an answer of thread http://archives.postgresql.org/pgsql-general/2003-08/msg00694.php >> >> You say it exist a funktion to fin positions an frequency of lexems for own calculate of an ranking since this time. >> But where is the description of this? >> May Im to blind but I spend a lot of time to search in internet for this. >> >> http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch-V2-intro.html >> http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch2-guide.html >> http://www.sai.msu.su/~megera/postgres/gist/tsearch/V2/docs/tsearch2-ref.html >> has to less examples to see it. >> May it is'nt in?.. >> >> I need it to serch terms with more than one lexem and later for an ranking for nearst lexems. > > > > ranking functions is already aware of this. See tsearch2.sql in contrib/tsearch2/sql for examples. We don't have API to specify your own > ranking function. Do you really need it ? Yes, i do. Me is given a real komplicatet concept for an ranking. I dont need only a ranking for one, two or tree terms. What I need is a system for give different terms diferent weights and to search terms with more than one word. How near they are and there frequency is important to. I dont have seen rules to use the 'rank()' function for this. I dont have seen any rules to use the 'rank()' as the one example on youre webside. I need the benefit of performance of an full text search and postgres is the only non commercial DB-Syste can handle greater data sizes. If u dont have an API for this, what can i do? [humor]*panic!* :\[/humor] greeds Peter Schmelzer >> >> greeds >> Peter Schmelzer >> >> ---------------------------(end of broadcast)--------------------------- >> TIP 8: explain analyze is your friend >> > > Regards, > Oleg > _____________________________________________________________ > Oleg Bartunov, sci.researcher, hostmaster of AstroNet, > Sternberg Astronomical Institute, Moscow University (Russia) > Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ > phone: +007(095)939-16-83, +007(095)939-23-83 > >