Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > tsearch strateg...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 15926 of 17437
Post > Topic >>

tsearch strategy for incremental search

by pierdeux@[EMAIL PROTECTED] ("Pierre Thibaudeau") Jun 29, 2008 at 09:33 PM

I am trying to implement an incremental search engine.  The service
should start searching when the user has typed at least 3 characters.
I am thinking of using the following strategy:

a) Create a function string_to_three_char_tsvector(str text) that
would generate the tsvector composed of the three-letter lexemes that
begin all the admissible words within the parameter str.
b) Using this function, create an indexed tsvector column: 
three_char_index.
c) Given the query string query_string (assume query_string containing
at least 3 characters):
SELECT *
FROM mytable,
plainto_tsquery((string_to_three_char_tsvector(query_string))::text)
AS query
WHERE three_char_index @[EMAIL PROTECTED]
 query
AND text_field LIKE '%' || str || '%';

Once I've narrowed the field of possibilities down to the correct
3-letter lexemes, there are fewer than 100 lines to search through
with LIKE.  I could even repeat the exercise with 4-letter lexemes if
these numbers were to grow or if I needed the extra boost in
performance.

So, two questions to postgres/tsearch experts:

1) Does that seem like a decent overall strategy?

2) About the function string_to_three_char_tsvector(text), I cannot
think of an elegant way of writing this.  Is it possible to do better
than the following:

str => cast to tsvector => cast to text => for each lexeme-string,
take first-three-char substring => concat back together => cast to
tsvector

Is there a nice way of performing the middle operation?  Like
splitting the string to an array...

-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 5 Posts in Topic:
tsearch strategy for incremental search
pierdeux@[EMAIL PROTECTED  2008-06-29 21:33:42 
Re: tsearch strategy for incremental search
pierdeux@[EMAIL PROTECTED  2008-06-30 01:38:21 
Re: tsearch strategy for incremental search
oleg@[EMAIL PROTECTED] (  2008-06-30 10:00:25 
Re: tsearch strategy for incremental search
pierdeux@[EMAIL PROTECTED  2008-06-30 13:33:21 
Re: tsearch strategy for incremental search
oleg@[EMAIL PROTECTED] (  2008-06-30 22:03:10 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 2:19:28 CST 2008.