X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 62AE58B9DFF for ; Sun, 13 Feb 2005 04:08:11 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70502-05 for ; Sun, 13 Feb 2005 04:08:01 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 51B0C8BA024 for ; Sun, 13 Feb 2005 04:08:00 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id j1D47tqc024680 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 12 Feb 2005 21:07:58 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id j1D47tRM025607; Sat, 12 Feb 2005 21:07:55 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id j1D47t6G025606; Sat, 12 Feb 2005 21:07:55 -0700 (MST) (envelope-from mfuhr) Date: Sat, 12 Feb 2005 21:07:55 -0700 From: Michael Fuhr To: b t Cc: pgsql-interfaces@postgresql.org Subject: Re: How to write UDF in C that resemble the LIKE function Message-ID: <20050213040755.GA25541@winnie.fuhr.org> References: <20050213034017.95691.qmail@web61004.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050213034017.95691.qmail@web61004.mail.yahoo.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200502/53 X-Sequence-Number: 5298 On Sat, Feb 12, 2005 at 07:40:17PM -0800, b t wrote: > > I have a question, as part of the project that I have to do for school, > we have to implement a User Define Function in C that is similar like the > LIKE funtion in PostgreSQL. For example where a customer is searching for > an actor whose last name sounds like "Schwarseneger" (notice the typo). > However, the customer is not sure neither about the spelling nor the > pronunciation. The real star name should be "Schwarzenegger". The contrib/fuzzystrmatch module contains implementations of the soundex, levenshtein, and metaphone algorithms. Here's an example: CREATE TABLE actor ( id serial PRIMARY KEY, name text NOT NULL ); INSERT INTO actor (name) VALUES ('Schwarzenegger'); SELECT * FROM actor WHERE soundex(name) = soundex('Schwarseneger'); id | name ----+---------------- 1 | Schwarzenegger You could create a functional index to speed up queries on large tables: CREATE INDEX actor_name_soundex_idx ON actor (soundex(name)); -- Michael Fuhr http://www.fuhr.org/~mfuhr/