Hi Erik, Thanks for responding. I have attached a sample java file for the sample implementation.
-regards, mahendra On Mon, 6 Dec 2004 08:19:54 -0500, Erik Hatcher <[EMAIL PROTECTED]> wrote: > Mahendra, > > Could you provide a concrete, and simple, example of what you're trying > to achieve? It would help me understand what you're after. > > Any Query implementation works fine as a clause within a BooleanQuery, > there is nothing special to do for a PhrasePrefixQuery in this regard. > > Erik > > > > > On Dec 6, 2004, at 6:34 AM, Mahendra wrote: > > > Hi, > > > > Presently i am working on a requirement in my application, to do the > > search using lucene as follows, > > > > Users enters phrase prefix query text. The query should be constructed > > as follows, > > - a PhrasePrefixQuery based on the user entered text, for eg FieldA > > - a termquery based on another field, for eg FieldB > > - a boolean query is constructed based on the above two queries. > > > > The search based on the boolean query, does not yield any results. > > However, query based on PhrasePrefixQuery and TermQuery is returning > > results. Can anyone suggest how > > to use PhrasePrefixQuery as part of Booleanquery. > > > > -Thanks, > > Mahendra > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
package org.apache.lucene.search; /** * Copyright 2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.index.Term; import org.apache.lucene.index.TermEnum; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.analysis.SimpleAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import junit.framework.TestCase; import java.io.IOException; import java.util.LinkedList; /** * This class tests PhrasePrefixQuery class. * * @author Otis Gospodnetic * @version $Id: TestPhrasePrefixQuery.java,v 1.3 2004/03/29 22:48:06 cutting Exp $ */ public class TestPhrasePrefixQuery extends TestCase { public TestPhrasePrefixQuery(String name) { super(name); } /** * */ public void testPhrasePrefix() throws IOException { RAMDirectory indexStore = new RAMDirectory("D:\\bea81\\user_projects\\domains\\masdomain\\mas\\index"); IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true); /* Document doc1 = new Document(); Document doc2 = new Document(); Document doc3 = new Document(); Document doc4 = new Document(); Document doc5 = new Document(); doc1.add(Field.Text("text", "blueberry pie")); doc2.add(Field.Text("body", "blueberry strudel")); doc3.add(Field.Text("body", "blueberry pizza")); doc4.add(Field.Text("body", "blueberry chewing gum")); doc5.add(Field.Text("body", "piccadilly circus")); writer.addDocument(doc1); writer.addDocument(doc2); writer.addDocument(doc3); writer.addDocument(doc4); writer.addDocument(doc5); writer.optimize(); writer.close(); */ IndexSearcher searcher = new IndexSearcher("D:\\bea81\\user_projects\\domains\\masdomain\\mas\\index"); PhrasePrefixQuery query1 = new PhrasePrefixQuery(); PhrasePrefixQuery query2 = new PhrasePrefixQuery(); query1.add(new Term("text", "contracts")); query2.add(new Term("text", "contracts")); LinkedList termsWithPrefix = new LinkedList(); IndexReader ir = IndexReader.open("D:\\bea81\\user_projects\\domains\\masdomain\\mas\\index"); TermEnum te = ir.terms(new Term("text", "appl*")); do { if (te.term().text().startsWith("appl")) { termsWithPrefix.add(te.term()); } } while (te.next()); query1.add((Term[])termsWithPrefix.toArray(new Term[0])); query2.add((Term[])termsWithPrefix.toArray(new Term[0])); BooleanQuery qry = new BooleanQuery(); qry.add(query1,true,false); qry.add(new TermQuery(new Term ("Object_Type", "contract")), true, false); Hits result; result = searcher.search(qry); assertEquals(2, result.length()); result = searcher.search(query2); assertEquals(0, result.length()); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
