Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 5EBC7650162 for ; Thu, 4 Dec 2008 13:21:40 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 77871-08 for ; Thu, 4 Dec 2008 13:21:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from zimbra.linuxsilo.net (zimbra.linuxsilo.net [92.48.122.79]) by mail.postgresql.org (Postfix) with ESMTP id 6BADC64FCD7 for ; Thu, 4 Dec 2008 13:21:37 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by zimbra.linuxsilo.net (Postfix) with ESMTP id 50A392852D for ; Thu, 4 Dec 2008 17:21:35 +0000 (GMT) X-Virus-Scanned: amavisd-new at Received: from zimbra.linuxsilo.net ([127.0.0.1]) by localhost (zimbra.linuxsilo.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q-n65TtBlgqy for ; Thu, 4 Dec 2008 17:21:34 +0000 (GMT) Received: from zimbra.linuxsilo.net (zimbra.linuxsilo.net [92.48.122.79]) by zimbra.linuxsilo.net (Postfix) with ESMTP id AEF5C2852C for ; Thu, 4 Dec 2008 17:21:34 +0000 (GMT) Date: Thu, 4 Dec 2008 17:21:34 +0000 (GMT) From: Jaume Sabater To: pgsql-admin@postgresql.org Message-ID: <16902748.7851228411294539.JavaMail.root@zimbra.linuxsilo.net> In-Reply-To: <31612419.7831228410455018.JavaMail.root@zimbra.linuxsilo.net> Subject: Using text search for locations, or a computed btree index MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [212.170.239.110] X-Mailer: Zimbra 5.0.10_GA_2609.DEBIAN4.0 (ZimbraWebClient - FF3.0 (Win)/5.0.10_GA_2609.DEBIAN4.0) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200812/26 X-Sequence-Number: 30859 Hello everyone! The guys creating the web site at the company I work for want an incremental search for locations. So, I need to find all locations that start with Uni, then Unit, then Unite, and so on. Problem is that the tables, although partitioned, have got several milion of tuples. Here is what I have in mind: 1. There are no stop words ("Palma of Majorca" is "Palma of Majorca", not "Palma Majorca", although this is not the best example). 2. There are no synonyms that have to be matched to other words. 3. No phrases have to be mapped to single words. 4. No variations of words need to be mapped to a canonical form (although this may be false when we add alternate names of locations) 5. I need to take out all accented characters and change all words to its lowercased form for faster searching and easier locating. So, I've been reading all the text search documentation available online and I think that I should be: 1. Creating an extra column with the "normalized" version of the location name. 2. Creating a GIN index on that extra column. 3. Creating a synonyms (variations) dictionary with the alternate names (touristic names that have no political equivalent but people know and use to search) What I don't know how to do is to just tell tsvector (and tsquery when searching) to do what I need and not what I don't need. I can't find a way in the online documentation to tell the engine which pieces I want from the whole puzzle. Alternatively, provided we don't use alternate names, I could use a computed btree index that does those needed operations: lowercase, substitute accented characters by their equivalents with a regular expression, and store that into an extra colum, perhaps? Any hints would be welcome. Thanks in advance. -- Jaume Sabater http://linuxsilo.net/ "Ubi sapientas ibi libertas"