On Mon, Sep 22, 2008 at 2:49 PM, Erick Erickson <[EMAIL PROTECTED]> wrote: > What do you mean when you say "trying to use the lucene api to build > queries"? > Are you trying to use BooleanQuery? If so, you either construct specific > clauses yourself (presumably by, say, tokenizing things yourself and > creating TermQuerys, PhraseQuerys, etc.) which *don't* need an > analyzer, or add Querys that you get from running stuff through > QueryParser that has a constructor that takes an Analyzer. > > Code snippets or more specific questions would be a great help <G>... > Imagine yourself trying to respond to an e-mail like you sent. There > isn't enough information there to really understand the problem you're > trying to solve, so I have to guess.
Sorry, my question was indeed too generic. I've written several tests to take confidence with behavior of Lucene, all using the StandardAnalyzer and the QueryParser. All the tests pass. Now I'm trying to write the same tests using Term/TermQuery/BooleanQuery but they don't works. Now I've found out that the problem is that using directly Term/TermQuery/BooleanQuery I'm not specifying the analyzer and then the query is not correct. Here one test with the use of the QueryParser, that works, and the current vesion with Term that doesn't work: @Test public void testSimpleSearch() throws Exception { LuceneContext luceneContext = new LuceneContext(); Document luceneInAction = luceneContext.createDocument("Lucene in action", 193, "9.90"); Document luceneForDummies = luceneContext.createDocument("Lucene for dummies", 245, "11.50"); Document tomcatInAction = luceneContext.createDocument("Tomcat in action", 728, "110.30"); luceneContext.addDocument(luceneInAction); luceneContext.addDocument(luceneForDummies); luceneContext.addDocument(tomcatInAction); luceneContext.closeIndex(); QueryParser queryParser = new QueryParser(LuceneContext.TITLE, new StandardAnalyzer()); Hits result = luceneContext.search(queryParser.parse("Lucene")); assertEquals(result, Arrays.asList(luceneInAction, luceneForDummies)); } @Test public void testSimpleSearch() throws Exception { LuceneContext luceneContext = new LuceneContext(); Document luceneInAction = luceneContext.createDocument("Lucene in action", 193, "9.90"); Document luceneForDummies = luceneContext.createDocument("Lucene for dummies", 245, "11.50"); Document tomcatInAction = luceneContext.createDocument("Tomcat in action", 728, "110.30"); luceneContext.addDocument(luceneInAction); luceneContext.addDocument(luceneForDummies); luceneContext.addDocument(tomcatInAction); luceneContext.closeIndex(); Hits result = luceneContext.search(new TermQuery(new Term(LuceneContext.TITLE, "Lucene"))); assertEquals(result, Arrays.asList(luceneInAction, luceneForDummies)); } Now, in our webapp, to execute query on the index we compose a query as string passed to QueryParser. We've read on the lucene documentation that from code is better compose a BooleanQuery using Term/TermQuery/... and then I'm evaluting how do it. Thanks. jean71 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]