Return-Path: Delivered-To: apmail-jakarta-lucene-user-archive@www.apache.org Received: (qmail 16562 invoked from network); 7 Nov 2003 01:05:29 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 7 Nov 2003 01:05:29 -0000 Received: (qmail 36763 invoked by uid 500); 7 Nov 2003 01:05:09 -0000 Delivered-To: apmail-jakarta-lucene-user-archive@jakarta.apache.org Received: (qmail 36726 invoked by uid 500); 7 Nov 2003 01:05:08 -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 36712 invoked from network); 7 Nov 2003 01:05:08 -0000 Received: from unknown (HELO c000.snv.cp.net) (209.228.32.66) by daedalus.apache.org with SMTP; 7 Nov 2003 01:05:08 -0000 Received: (cpmta 10130 invoked from network); 6 Nov 2003 17:05:15 -0800 Received: from 24.51.109.181 (HELO ehatchersolutions.com) by smtp.hatcher.net (209.228.32.66) with SMTP; 6 Nov 2003 17:05:15 -0800 X-Sent: 7 Nov 2003 01:05:15 GMT Date: Thu, 6 Nov 2003 20:05:26 -0500 Subject: Re: Rephrase My Question - How To Search Database With More Than One Pair of Property/Value as Parameters Using Lucene? Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v552) From: Erik Hatcher To: "Lucene Users List" Content-Transfer-Encoding: 7bit In-Reply-To: <20031107005355.35812.qmail@web11507.mail.yahoo.com> Message-Id: <7923DA53-10BE-11D8-9334-000393A564E6@ehatchersolutions.com> X-Mailer: Apple Mail (2.552) 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 On Thursday, November 6, 2003, at 07:53 PM, Caroline Jen wrote: > Hi, let me see if I have got the idea. For example, > if I want to search the database for articles written > by Elizabeth Castro, we do what is shown below in > Lucene: It sounds like you're asking a lot of hypothetical questions without actually trying things out with Lucene. It's quite approachable and easy to do some Test Driven Learning with some very simple JUnit test cases. If you're familiar with JUnit, this should be straightforward: public class SearchingTest extends TestCase { private Directory directory; private String[] docs = {"I come from nowhere mostly.", "I mostly come from space."}; private String[] keys = {"http://www.timreynolds.com/biography/", "http://www.timreynolds.com"}; protected void setUp() throws Exception { directory = new RAMDirectory(); addDocuments(directory); } private void addDocuments(Directory directory) throws Exception { IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true); for (int i = 0; i < docs.length; i++) { Document doc = new Document(); doc.add(Field.Text("contents", docs[i])); doc.add(Field.Keyword("url", keys[i])); writer.addDocument(doc); } writer.close(); } public void testTerm() throws Exception { IndexSearcher searcher = new IndexSearcher(directory); Term t = new Term("contents", "space"); Query query = new TermQuery(t); Hits hits = searcher.search(query); assertEquals(1, hits.length()); t = new Term("contents", "i"); hits = searcher.search(new TermQuery(t)); assertEquals(2, hits.length()); searcher.close(); } } Substitute in the QueryParser stuff where the TermQuery is constructed and index some documents of your choosing in the docs field. > Nonetheless, both "creator" and the name of the > creator are variables. We depend on the user to give > us the information and we pass the information to form > a query; probably this way: Whether to use QueryParser completely or not is a decision you'll have to make, but using it for the entire Query may not be quite what you're after. > I think I want to put my hand on the idea on how to > pass the information (two pairs of field and its > value) provided by a user to form a query. Should I > do this: > > public static final Query getQuery( > String value1, > String field1, > String value2, > String field2) throws ParameterException { > try { > return > QueryParser.parse(value1,field1,value2,field2, > getAnalyzer()); > } Well, if you had tried this, you'd realize this is incorrect API usage, so no, you shouldn't do this! :) (nor could you) > return QueryParser.parse(value1,field1,value2,field2, > getAnalyzer()); > > How does the Luncene know it is AND instead of OR we > want? QueryParser has a setOperator method on it to change the default operator to AND rather than OR. Again, please have a go at implementing some examples and come back to us with informed questions should you have some. Trying this stuff first hand is the best way to really get a feel for how it works and will ensure you're asking the right questions. Test Driven Learning - embrace learning. It's my new fad. Erik --------------------------------------------------------------------- To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: lucene-user-help@jakarta.apache.org