lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel de Souza Teixeira" <dan...@ccuec.unicamp.br>
Subject Re: How to use PhraseQuery Class?
Date Wed, 16 Jun 2004 12:45:28 GMT
Hello again...

I already had written that article... Thanks...

Well, I used this sintax and did not work!

The engine answered "no hits!".

Do I need to use some special kind of Analyzer on the index method ?

I used this code to search...

IndexSearcher searcher = new IndexSearcher(indexName);

//Query query = QueryParser.parse("How", "contents", new SimpleAnalyzer());

PhraseQuery query = new PhraseQuery();
query.setSlop(2);
query.add(new Term("contents", "How"));
query.add(new Term("contents", "can"));

System.out.println( "Query: " + query.toString());

Hits hits = searcher.search(query);

System.out.println( "Hits: " + hits.length()); //  this part returns 0
(zero) hits. If I use a simple query, just for single words, work it.

Did you see something like that before ?

Thanks!

-- 
Daniel

> 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
>
>


---------------------------------------------------------------------
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