Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 25419 invoked from network); 4 Aug 2005 10:43:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 4 Aug 2005 10:43:48 -0000 Received: (qmail 56800 invoked by uid 500); 4 Aug 2005 10:43:41 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 56779 invoked by uid 500); 4 Aug 2005 10:43:40 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 56761 invoked by uid 99); 4 Aug 2005 10:43:40 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Aug 2005 03:43:40 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [193.108.181.138] (HELO quimby.programmfabrik.de) (193.108.181.138) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Aug 2005 03:43:29 -0700 Received: from [84.188.210.123] (helo=xen) by quimby.programmfabrik.de with asmtp (Exim 3.35 #1 (Debian)) id 1E0c4u-0001wn-00 for ; Thu, 04 Aug 2005 11:31:52 +0200 Received: from [192.168.0.222] (helo=[127.0.0.1]) by xen with esmtp (Exim 4.34 #1 (Debian)) id 1E0dCC-00021h-Sf for ; Thu, 04 Aug 2005 12:43:28 +0200 Message-ID: <42F1F16A.2040204@programmfabrik.de> Date: Thu, 04 Aug 2005 12:43:54 +0200 From: Martin Rode User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: java-user@lucene.apache.org Subject: Re: Search in multi fields with cross field AND ? References: <013F0E81D349EC42A14CD3242BC61AFFF9A96B@sch-mail-06.schibsted.no> In-Reply-To: <013F0E81D349EC42A14CD3242BC61AFFF9A96B@sch-mail-06.schibsted.no> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Erlend, try this code: QueryParser q = new QueryParser("text", analyzer); q.setOperator(QueryParser.DEFAULT_OPERATOR_AND); Query query = q.parse(search); Hits hits = isearcher.search(query); Best, Martin erlend.bjorge@aftenposten.no wrote: >Hi there! > >I'm fairly new to Lucene and trying evaluate it. I want to retrieve only documenets (companies) that has >all the words searched for in different fields, crossed in different fields with AND search. > >I have a structure in the "documents" (companies) like this : > >companyName string >keywords1 string (Extra boosting if match here) >keywords2 string > >--- > >So far so good when I create the index with boosting on keywords1 etc. > >If I search for: > >"ford garage" > >I want companies that rapair ford cars, and only those. > >So if you have documents/companies like: > >"company1", "ford volvo", "garage motor ...." >"company2", "volvo nissan", "garage ......." >"company3", null, "ford garage motor ....." > >--- > >I will have match with company1 and company3. Company2 don't do ford cars. Company3 haven't match in keywords1, but >they still doing garage stuff with Ford cars, but should be after company1 in the result list, since match in keywords1 >should give you extra boosting = higher score = why I don't have only one field for both keywords. > >So I have tried different approaches doing searching, something like this: > >1 --------------------------------------------------------------------------- > > String[] fieldNames = new String[]{"companyName", "keywords1", "keywords2"}; > String searchText = "ford garage" / "ford AND garage" > > BooleanQuery query = new BooleanQuery(); > > for(int i = 0; i < fieldNames.length; ++i) { > QueryParser qp = new QueryParser(fieldNames[i], new StandardAnalyzer()); > > qp.setOperator(QueryParser.DEFAULT_OPERATOR_AND); > query.add(qp.parse(searchText), false, false); > } > > Hits h = is.search(query); > >2 --------------------------------------------------------------------------- > > Query query = MultiFieldQueryParser.parse(searchText, fieldNames, new StandardAnalyzer()); > > Hits h = is.search(query); > >------------------------------------------------------------------------------ > >In both cases, I only get company3 in the result because "ford garage" is within the same field for this company I guess, >and I don't get Company1 too. I guess because the two words are split in two different fields = search in muliti fields, >cross field AND..... if you understand ? > >So is this possible with Lucene, what have I missed ? I have the Lucene book, can't find anything there, tried to find >anyting in the archive, didn't find anythign there either, but maybe I didn't look good enough ? What should I look for ? > >So any clues of how I can do this search ?? > > >Thanks in advanced! > > >Cheers, >Erlend > > > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org