Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 215C79FB514 for ; Thu, 8 Mar 2007 02:45:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 94280-06 for ; Thu, 8 Mar 2007 02:45:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from relay.benon.com (abe.benon.com [210.18.217.10]) by postgresql.org (Postfix) with ESMTP id C4FFE9FB485 for ; Thu, 8 Mar 2007 02:45:50 -0400 (AST) Received: from [1.1.1.98] (brdr-gw-01.benon.com [210.18.217.1]) by relay.benon.com (Postfix) with ESMTP id D7AB134C111; Thu, 8 Mar 2007 16:45:47 +1000 (EST) Message-ID: <45EFB12F.9000001@benon.com> Date: Thu, 08 Mar 2007 16:46:07 +1000 From: Shaun Johnston User-Agent: Thunderbird 1.5.0.9 (X11/20070103) MIME-Version: 1.0 To: Madison Kelly CC: pgsql-general@postgresql.org Subject: Re: Query help References: <45EFAB1A.2060105@alteeve.com> In-Reply-To: <45EFAB1A.2060105@alteeve.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.025 tagged_above=0 required=5 tests=AWL, BAYES_50, SPF_PASS X-Spam-Level: X-Archive-Number: 200703/393 X-Sequence-Number: 110583 Try SELECT DISTINCT rather than SELECT That should return a result with unique records. Madison Kelly wrote: > Hi all, > > I've got a query that looks through a table I use for my little > search engine. It's something of a reverse-index but not quite, where > a proper reverse index would have 'word | doc1, doc3, doc4, doc7' > showing all the docs the keyword is in, mine has an entry for eac > > I've got a query like: > > SELECT > sch_id, sch_for_table, sch_ref_id, sch_instances > FROM > search_index > WHERE > (sch_keyword LIKE '%digi%' OR sch_keyword LIKE '%madi%') > AND > sch_for_table!='client' > AND > ... (more restrictions) > ORDER BY > sch_instances DESC; > > This returns references to a data column (sch_ref_id) in a given > table (sch_for_table) for each matched keyword. > > The problem I am having is that two keywords might reference the > same table/column which would, in turn, give me two+ search results > pointing to the same entry. > > What I would like to do is, when two or more results match the same > 'sch_ref_id' and 'sch_for_table' to merge the results. Specifically, > the 'sch_instances' column is the number of times the given keyword is > found in the table/column. I'd like to add up the number in the > duplicate results (to give it a higher accuracy and move it up the > search results). > > Is this possible or would I need to add this logic in my program? > I'd rather do it in PostgreSQL though, if I could. > > Here is the 'search_index' table I am using: > > db=> \d search_index > Table "public.search_index" > Column | Type | Modifiers > ---------------+---------+----------------------------------------------- > sch_id | integer | not null default nextval('sch_seq'::regclass) > sch_keyword | text | not null > sch_instances | integer | not null default 1 > sch_for_table | text | not null > sch_ref_id | integer | not null > Indexes: > "search_index_pkey" PRIMARY KEY, btree (sch_id) > > Thanks in advance to any help you might be able to give me! > > Madison > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings