lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: How to use PhraseQuery Class?
Date Tue, 15 Jun 2004 20:45:44 GMT
On Jun 15, 2004, at 11:21 AM, Daniel de Souza Teixeira wrote:
> Hi!
> I need some information about PhraseQuery Class.
>
> How to use this class ?

Are you using QueryParser to create the query?  If so, have a look at 
the query parser syntax page in the docs (or the Lucene website) - 
basically just surround the phase with double-quotes - "this is some 
phrase".

If you are using PhraseQuery directly, have a look at Lucene's own 
JUnit test cases (notice a trend here of me pointing folks to the test 
cases for documentation?!  :)  Here's a copy/paste:

     Query query = new PhraseQuery();
     query.setSlop(2);
     query.add(new Term("field", "one"));
     query.add(new Term("field", "five"));

Erik




>
> I tried to use, but I couldn't.
> I created an index, just with 2 fields:
>    - path: path of the file
>    - contents: the text of the file (pdf,txt,html,doc,rtf ...)
>
> I want to search with phrases... Is it possible ?
>
> This is te code...
>
> public void indexFiles(String filePath, String documentText, String
> indexName, boolean create) {
>
> 	try {
>
>
> 		IndexWriter writer = null;
>
> 		File index = new File ("./" + indexName);
>
> 		if (!index.exists()) {
> 			writer = new IndexWriter(indexName, null, true);
> 			writer.optimize();
> 			writer.close();
> 		}
>
> 		writer = new IndexWriter(indexName, new StandardAnalyzer(), false);
>
> 		Document doc = new Document();
>
> 		doc.add(Field.UnIndexed ("path",filePath));
> 		doc.add(Field.Text("contents",documentText));
>
> 		writer.addDocument(doc);
>
> 		doc = null;
> 		writer.close();
> 	}
>
> 	catch (Exception ex) {
> 		System.out.println("Error - " + ex);
> 	}
>
> }
>
> Thanks!
>
> Regards.
>
> -- 
> Daniel de Souza Teixeira
> Laboratório de Inovação em Software - Unicamp/Ci&T
> Campinas-SP
> Brasil
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Mime
View raw message