Return-Path: Delivered-To: apmail-jakarta-lucene-user-archive@www.apache.org Received: (qmail 89152 invoked from network); 30 Oct 2003 21:34:22 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 30 Oct 2003 21:34:22 -0000 Received: (qmail 88851 invoked by uid 500); 30 Oct 2003 21:33:59 -0000 Delivered-To: apmail-jakarta-lucene-user-archive@jakarta.apache.org Received: (qmail 88713 invoked by uid 500); 30 Oct 2003 21:33:58 -0000 Mailing-List: contact lucene-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Lucene Users List" Reply-To: "Lucene Users List" Delivered-To: mailing list lucene-user@jakarta.apache.org Received: (qmail 88677 invoked from network); 30 Oct 2003 21:33:58 -0000 Received: from unknown (HELO sn2.cwihosting.com) (66.216.127.33) by daedalus.apache.org with SMTP; 30 Oct 2003 21:33:58 -0000 Received: from h0004763fc2ea.ne.client2.attbi.com ([24.91.229.13] helo=mgiles-office.visionstudio.com) by sn2.cwihosting.com with asmtp (Exim 4.24) id 1AFKQd-0000zr-T0 for lucene-user@jakarta.apache.org; Thu, 30 Oct 2003 15:34:03 -0600 Message-Id: <6.0.0.22.0.20031030162654.023dc6d0@mail.visionstudio.com> X-Sender: mgiles%visionstudio.com@mail.visionstudio.com X-Mailer: QUALCOMM Windows Eudora Version 6.0.0.22 Date: Thu, 30 Oct 2003 16:34:02 -0500 To: "Lucene Users List" From: Michael Giles Subject: Re: MultiFieldQueryParser default operator In-Reply-To: <3AD85700-0AEA-11D8-8FA2-000393A564E6@ehatchersolutions.com > References: <20031030143121.63637.qmail@web12703.mail.yahoo.com> <3AD85700-0AEA-11D8-8FA2-000393A564E6@ehatchersolutions.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - sn2.cwihosting.com X-AntiAbuse: Original Domain - jakarta.apache.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - visionstudio.com X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N This would be great to get fixed (I think I emailed a similar question a month or so ago). If MultiFieldQueryParser is being mucked with, the constructor should be updated to take an array of fields instead of the single field it takes currently. The code snippet below is actually passing the query ("britney spears") into the constructor instead of a default field. If you made that single change to the constructor, no other changes would be necessary, as you could simply call the parse(String) method from QueryParser to do your work. -Mike At 10:03 AM 10/30/2003, you wrote: >It was posted on lucene-dev, not lucene-user. I've pasted it below. > >I will be fixing this at some point in the near future based on this fix >and other related ones needed. > > Erik > >----- > >From: Bernhard Messer >Date: Wed Oct 29, 2003 11:27:02 AM US/Eastern >To: Lucene Developers List >Subject: MultiFieldQueryParser, can't change default search operator >Reply-To: "Lucene Developers List" > >hi all, > >just played around with the MultiFieldQueryParser and didn't find a >working way to change the "operator" value. > >The problem is that MultiFieldQueryParser is implementing two public >static methods "parse" only. Calling one of those, in the extended >superclass, the static method implementation for "parse" is called. Due to >the fact that the QueryParser class creates a new Instance for each call >thru the static method, the "operator" flag is simply ignored. > >There would be a simple fix within MultiFieldQueryParser class without >touching the rest of the system. One have to add a new non static method >"parse" which could look like this: > >/***********************************************************/ >public Query parse(String query, String[] fields) throws ParseException { > BooleanQuery bQuery = new BooleanQuery(); > > for (int i = 0; i < fields.length; i++) > { > QueryParser parser = new QueryParser(fields[i], analyzer); > parser.setOperator(getOperator()); > Query q = parser.parse(query); > bQuery.add(q, false, false); > } > return bQuery; > } >/***********************************************************/ > > >To test the new implementation, following code fragment can be used: > >/***********************************************************/ > Directory directory = > FSDirectory.getDirectory("/tmp/idx-test", false); > Analyzer analyzer = new SimpleAnalyzer(); > Searcher searcher = new IndexSearcher(directory); > Hits hits = null; > String[] fields = { "contents", "title" }; > MultiFieldQueryParser parser = new > MultiFieldQueryParser("britney spears", analyzer); > >parser.setOperator(QueryParser.DEFAULT_OPERATOR_AND); > Query query = parser.parse("britney spears", > fields); > System.out.println("Query: " + query.toString()); > hits = searcher.search(query); > > System.out.println ("Results: " + hits.length()); > searcher.close(); >/***********************************************************/ > > >best regards > >Bernhard --------------------------------------------------------------------- To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: lucene-user-help@jakarta.apache.org