try this 
 
objQuery = QueryParser.parse("John", "name" , objAnalyzer);
or
objQuery = QueryParser.parse("Engineer", "designation", objAnalyzer);
 
I should work. 

The second parameter is the column name you pass. So if you are search for 
"name", it will look for only name column.
 
Hope this help you 
 
Mahaveer

Mohamed Ebrahim Faisal <[EMAIL PROTECTED]> wrote:
Hi all

I have written a simple program to test Indexing & Search. After indexing 
couple of documents, I Searched for the same, but i didn't get Successfull 
matches. I don't know whether it is a bug in Lucene or in the code. I have 
enclosed the code for your review.

But when i used Lucene for bigger applications ( index contains larger 
documents ), search worked amazingly.


Following is the code which didn't work properly

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;

import org.apache.lucene.search.Searcher;

public class testLucene
{
private static final String[] strSTOP_WORDS =
{
"and",
"are",
"was",
"will",
"with" };
private void test() throws Exception
{
Analyzer objAnalyzer = new StandardAnalyzer();
IndexWriter index = new IndexWriter("index",objAnalyzer, true );
Searcher objIndexSearcher = new IndexSearcher("index");


Document d = new Document();

d.add( Field.Text("name","Ebrahim Faisal"));
d.add( Field.Text("address","New York"));
d.add( Field.Text("designation","Software Engineer"));
d.add( Field.Text("xyz","123 IndexWriter index"));

index.addDocument( d );

d = new Document();

d.add( Field.Text("name","John Smith"));
d.add( Field.Text("address","India"));
d.add( Field.Text("designation","Sr. Software Engineer"));
d.add( Field.Text("xyz","456 StandardAnalyzer true"));

index.addDocument( d );



index.optimize();
index.close();


Query objQuery = null;

objQuery = QueryParser.parse("Engineer", "name"
, objAnalyzer);


Hits objHits = objIndexSearcher.search(objQuery);


for (int nStart = 0; nStart < objHits.length(); nStart++) 
{
d = objHits.doc(nStart);
System.out.println(" address "+d.get("address"));
}

}
public static void main(String[] args) throws Exception
{
new testLucene().test();
}
}

                
---------------------------------
Do you Yahoo!?
 Jazz up your holiday email with celebrity designs. Learn more.

Reply via email to