#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    6
    Rep Power
    0

    Question FTS how to configure and get files


    The more I read about FTS in Postgresql the more my head hurts.

    Can someone point me to the files I need, and what commands to run to setup a search that does some mild spell checking and can handle things like Rain/Rains/Raining etc.

    I'm running Fedora Linux.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,788
    Rep Power
    349
    Originally Posted by MikeyCarter
    Can someone point me to the files I need
    No "files" needed. It's built into the core.

    and what commands to run to setup a search that does some mild spell checking and can handle things like Rain/Rains/Raining etc.
    What exactly are you missing from the manual?

    http://www.postgresql.org/docs/current/static/textsearch-tables.html
    http://www.postgresql.org/docs/current/static/textsearch-controls.html

    Here is a little example taken from the manual and adjusted to your question: First some test data to play with
    Code:
    create table text_data (id integer primary key, the_text text);
    
    insert into text_data (id, the_text)
    values
    (1, 'it''s raining again'),
    (2, 'it never rains in california'),
    (3, 'some random text');
    
    commit;
    To query the table use something like this:
    Code:
    postgres=> select *
    postgres-> from text_data
    postgres-> where to_tsvector(the_text) @@ to_tsquery('rain');
     id |           the_text
    ----+------------------------------
      2 | it never rains in california
    (1 row)
    Now this is probably not what you expected, so we need to configure a stemmer to also get other text with rain init:
    Code:
    create text search configuration my_config (copy=english);
    
    create text search dictionary english_stem (
        TEMPLATE = snowball,
        Language = english
    );
    
    alter text search configuration my_config alter mapping for asciiword WITH english_stem
    Now when we use this configuration to search for rain, the result look better:
    Code:
    postgres=> select *
    postgres-> from text_data
    postgres-> where to_tsvector('my_config', the_text) @@ to_tsquery('rain');
     id |           the_text
    ----+------------------------------
      1 | it's raining again
      2 | it never rains in california
    (2 rows)
    Hope this helps
    Last edited by shammat; April 20th, 2012 at 12:57 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    6
    Rep Power
    0
    That works thanks.

IMN logo majestic logo threadwatch logo seochat tools logo