You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Daniel de Souza Teixeira <da...@ccuec.unicamp.br> on 2004/06/15 17:21:38 UTC
How to use PhraseQuery Class?
Hi!
I need some information about PhraseQuery Class.
How to use this class ?
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
Re: indexing with 1.4-rc3 only yields single .cfs file
Posted by Otis Gospodnetic <ot...@yahoo.com>.
We switched from multi-file to compound index structure in one of the
recent RCs. This should be mentioned in CHANGES.txt file. The change
was made to make it more difficult for people to reach 'Too many open
files' situations.
Otis
--- Claude Devarenne <cl...@library.ucsf.edu> wrote:
> Hi,
>
> I just upgraded to 1.4-rc3 and re-indexed my data. I did not change
> any code and noticed that in the index directory there is a single
> .cfs
> file which I am guessing stands for compound file system. Search
> works
> fine but after checking out the latest from CVS I did not see this
> mentioned in the fileformats documentation. Is this the normal
> behavior for indexes from now on or is something else going on? When
>
> creating the index I see the .tis, .frq and other files being
> created.
> Maybe I need to update my indexer, sorry if I did not RTFM.
>
> Claude
>
>
> ---------------------------------------------------------------------
> 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
indexing with 1.4-rc3 only yields single .cfs file
Posted by Claude Devarenne <cl...@library.ucsf.edu>.
Hi,
I just upgraded to 1.4-rc3 and re-indexed my data. I did not change
any code and noticed that in the index directory there is a single .cfs
file which I am guessing stands for compound file system. Search works
fine but after checking out the latest from CVS I did not see this
mentioned in the fileformats documentation. Is this the normal
behavior for indexes from now on or is something else going on? When
creating the index I see the .tis, .frq and other files being created.
Maybe I need to update my indexer, sorry if I did not RTFM.
Claude
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: How to use PhraseQuery Class?
Posted by Daniel de Souza Teixeira <da...@ccuec.unicamp.br>.
Thanks Erik!
Now, it's working.
Regards!
--
Daniel
> On Jun 16, 2004, at 8:45 AM, Daniel de Souza Teixeira wrote:
>> Do I need to use some special kind of Analyzer on the index method ?
>
> What analyzer did you use? SimpleAnalyzer lowercases....
>
>> 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);
>
> And so your "How" term should be "how" in order to match what you
> indexed.
>
> Be sure to read and understand issues you can encounter with analysis
> in the picture, or in your case in the picture during indexing, but not
> during querying:
>
> http://wiki.apache.org/jakarta-lucene/AnalysisParalysis
>
> In other words, knowing *exactly* what you indexed is extremely vital
> in understanding issues with querying.
>
> Erik
>
>
> ---------------------------------------------------------------------
> 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
Re: How to use PhraseQuery Class?
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jun 16, 2004, at 8:45 AM, Daniel de Souza Teixeira wrote:
> Do I need to use some special kind of Analyzer on the index method ?
What analyzer did you use? SimpleAnalyzer lowercases....
> 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);
And so your "How" term should be "how" in order to match what you
indexed.
Be sure to read and understand issues you can encounter with analysis
in the picture, or in your case in the picture during indexing, but not
during querying:
http://wiki.apache.org/jakarta-lucene/AnalysisParalysis
In other words, knowing *exactly* what you indexed is extremely vital
in understanding issues with querying.
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: How to use PhraseQuery Class?
Posted by Daniel de Souza Teixeira <da...@ccuec.unicamp.br>.
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
Re: How to use PhraseQuery Class?
Posted by Thimal Jayasooriya <th...@cs.york.ac.uk>.
Since Erik didn't mention this article that he wrote, I'll chip in with
it ... *grin*
http://today.java.net/pub/a/today/2003/11/07/QueryParserRules.html
Doesn't have a direct example of PhraseQuery, but it was useful reading
to get started (for me, anyway).
Regards,
Thimal
Erik Hatcher wrote:
> 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
Re: How to use PhraseQuery Class?
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
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