lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James liu" <liuping.ja...@gmail.com>
Subject is it wrong with my code?
Date Fri, 14 Jul 2006 19:37:54 GMT
i can compile it correctly.but it can not search anything.
i can't find error...so wanna u help me?




package kk;

import java.io.*;
import java.util.Date;
//import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.analysis.cjk.CJKAnalyzer;
import org.apache.lucene.document.Document;
//port org.apache.lucene.index.FilterIndexReader;
//import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.*;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.search.Query;
import org.apache.lucene.index.*;

public class MySearch
{

public String test() {
return "test is ok hohoho";
}


// private MySearch()
// {
// }



// public static void main(String args[])
// throws Exception
// {
// String info = searchword(args[0],args[1]);
// System.out.println(info);
// }

public String searchword(String ss,String index_path) throws Exception {
String queryStr = ss;
String result = "Result:<br />";
File indexDir = new File(index_path);
FSDirectory directory = FSDirectory.getDirectory(indexDir,false);
if(!indexDir.exists()){
result = "The Lucene index is not exist";
return result;
}
IndexSearcher searcher = new IndexSearcher(directory);
CJKAnalyzer anlalyzer = new CJKAnalyzer();
QueryParser qp = new QueryParser("contents", anlalyzer);

Hits hits = searcher.search(qp.Query(queryStr));
if(hits.length()<=0){
System.out.println("result:<0" + hits.length());
return result;
}
for(int i = 0; i < hits.length(); i++){
Document document = hits.doc(i);
result += "<br />jl";
}
searcher.close();
System.out.println("result:<0" + hits.length());
return result;
}
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message