lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Lea <...@digimem.net>
Subject Re: QueryParser.parse
Date Mon, 27 May 2002 13:07:17 GMT
Why do you not want to tokenize AUTEUR and TITRE? Your example will work
if you do.  Using QueryParser.parse with a standard analyzer your
query will be tokenized and will match the tokens created when you
added the documents to the index.


--
Ian.
ian@digimem.net


> a.katona@ever-team.com (Arpad KATONA) wrote 
>
> Hello,
> 
> under http://jakarta.apache.org/lucene/docs/queryparsersyntax.html is to be
> read :
> 
> +++
> As an example, let's assume a Lucene index contains two fields, title and text
> and text is the default field. If you want to find the document entitled "The
> Right Way" which contains the text "don't go this way", you can enter: 
> 
> title:"The Right Way" AND text:go  
> +++   
> 
> So i tried, see the code below :
> 1) first, i create a document with 3 fields: KEY, AUTEUR and TITRE, the fields
> are NOT to be tokenized.
> 2) second, i read the index to see what it contains (see "output" below).
> 3) third, i would like to find a record with "jean auteur" as AUTEUR or "opus
> primum" as TITRE; thus, the query string is :
> ?AUTEUR:"jean auteur OR TITRE:"opus primum"?. But, h?las!, there is no answer.
> Could you tell me, please, where the error is?
> 
> Thanks
> 
> Arpad KATONA
> a.katona@ever-team.com
> 
> --
> 
> +++
> try {
>   Analyzer analyzer = new StandardAnalyzer();
>   String sIxPath = "D:\\tempo\\lucene\\ix";
>   //
>   // indexing
>   //
>   IndexWriter writer = new IndexWriter(sIxPath, analyzer, true);
>   org.apache.lucene.document.Document doc =
>     new org.apache.lucene.document.Document();
>   Field fd = new Field("KEY", "1", true, true, false);
>   doc.add(fd); fd = null;
>   fd = new Field("AUTEUR", "jean auteur", false, true, false);
>   doc.add(fd); fd = null;
>   fd = new Field("TITRE", "opus primum", false, true, false);
>   doc.add(fd); fd = null;
>   writer.addDocument(doc); doc = null;
>   writer.close(); writer = null;
>   //
>   // checking
>   //
>   IndexReader reader = IndexReader.open(sIxPath);
>   TermEnum tenum = reader.terms();
>   for(; tenum.next(); ) {
>     Term term = tenum.term();
>     String sField = term.field();
>     String sText = term.text();
>     System.out.println("sField=?"+sField+"? sText=?"+sText+"?");
>   }
>   tenum.close(); tenum = null;
>   reader.close(); reader=null;
>   //
>   // searching
>   //
>   String sQuery="TITRE:\"opus primum\" OR AUTEUR:\"jean auteur\"";
>   Query query = QueryParser.parse(sQuery, "", analyzer);
>   System.out.println("query = ?"+query.toString("")+"?");
>   Searcher searcher = new IndexSearcher(sIxPath);
>   Hits hits = searcher.search(query);
>   if(null==hits) {
>     System.out.println("No answer.");
>   } else {
>     int nbHits = hits.length();
>     System.out.println("nbHits = "+Integer.toString(nbHits));
>   }
>   hits = null;
>   searcher.close(); searcher=null;
>   query = null;
> } catch (Exception ex) {
>   ex.printStackTrace();
> }
> +++
> 
> output:
> 
> +++
> sField=?AUTEUR? sText=?jean auteur?
> 
> sField=?KEY? sText=?1?
> 
> sField=?TITRE? sText=?opus primum?
> 
> query = ?TITRE:"opus primum" AUTEUR:"jean auteur"?
> 
> nbHits = 0
> 
> +++

----------------------------------------------------------------------
Searchable personal storage and archiving from http://www.digimem.net/


Mime
View raw message