public void SearcherMaxField() throws ParseException, IOException {
Query query = null;
Hits hits = null;
IndexSearcher indexSearcher= null;
QueryParser queryParser= null;
queryParser = new QueryParser("name1",new StandardAnalyzer());
query = queryParser.parse("程序员");
indexSearcher= new IndexSearcher("c:\\index");
hits = indexSearcher.search(query);
System.out.println("您搜的是:程序员");
System.out.println("找到了"+hits.length()+"个结果");
System.out.println("它们分别是:");
for (int i = 0; i < hits.length(); i++){
Document doc = hits.doc(i);
System.out.println(doc.get("name1"));
}
query = queryParser.parse("程序员之家");
indexSearcher= new IndexSearcher("c:\\index");
hits = indexSearcher.search(query);
System.out.println("您搜的是:程序员之家");
System.out.println("找到了"+hits.length()+"个结果");
System.out.println("它们分别是:");
for (int i = 0; i < hits.length(); i++){
Document doc = hits.doc(i);
System.out.println(doc.get("name1"));
}
queryParser = new QueryParser("name2",new StandardAnalyzer());
query = queryParser.parse("Welcome");
indexSearcher= new IndexSearcher("c:\\index");
hits = indexSearcher.search(query);
System.out.println("您搜的是:Welcome");
System.out.println("找到了"+hits.length()+"个结果");
System.out.println("它们分别是:");
for (int i = 0; i < hits.length(); i++){
Document doc = hits.doc(i);
System.out.println(doc.get("name2"));
}
query = queryParser.parse("the");
indexSearcher= new IndexSearcher("c:\\index");
hits = indexSearcher.search(query);
System.out.println("您搜的是:the");
System.out.println("找到了"+hits.length()+"个结果");
System.out.println("它们分别是:");
for (int i = 0; i < hits.length(); i++){
Document doc = hits.doc(i);
System.out.println(doc.get("name2"));
}
query = queryParser.parse("home");
indexSearcher= new IndexSearcher("c:\\index");
hits = indexSearcher.search(query);
System.out.println("您搜的是:home");
System.out.println("找到了"+hits.length()+"个结果");
System.out.println("它们分别是:");
for (int i = 0; i < hits.length(); i++) {
Document doc = hits.doc(i);
System.out.println(doc.get("name2"));
}
}
Query query = null;
Hits hits = null;
IndexSearcher indexSearcher= null;
QueryParser queryParser= null;
queryParser = new QueryParser("name1",new StandardAnalyzer());
query = queryParser.parse("程序员");
indexSearcher= new IndexSearcher("c:\\index");
hits = indexSearcher.search(query);
System.out.println("您搜的是:程序员");
System.out.println("找到了"+hits.length()+"个结果");
System.out.println("它们分别是:");
for (int i = 0; i < hits.length(); i++){
Document doc = hits.doc(i);
System.out.println(doc.get("name1"));
}
query = queryParser.parse("程序员之家");
indexSearcher= new IndexSearcher("c:\\index");
hits = indexSearcher.search(query);
System.out.println("您搜的是:程序员之家");
System.out.println("找到了"+hits.length()+"个结果");
System.out.println("它们分别是:");
for (int i = 0; i < hits.length(); i++){
Document doc = hits.doc(i);
System.out.println(doc.get("name1"));
}
queryParser = new QueryParser("name2",new StandardAnalyzer());
query = queryParser.parse("Welcome");
indexSearcher= new IndexSearcher("c:\\index");
hits = indexSearcher.search(query);
System.out.println("您搜的是:Welcome");
System.out.println("找到了"+hits.length()+"个结果");
System.out.println("它们分别是:");
for (int i = 0; i < hits.length(); i++){
Document doc = hits.doc(i);
System.out.println(doc.get("name2"));
}
query = queryParser.parse("the");
indexSearcher= new IndexSearcher("c:\\index");
hits = indexSearcher.search(query);
System.out.println("您搜的是:the");
System.out.println("找到了"+hits.length()+"个结果");
System.out.println("它们分别是:");
for (int i = 0; i < hits.length(); i++){
Document doc = hits.doc(i);
System.out.println(doc.get("name2"));
}
query = queryParser.parse("home");
indexSearcher= new IndexSearcher("c:\\index");
hits = indexSearcher.search(query);
System.out.println("您搜的是:home");
System.out.println("找到了"+hits.length()+"个结果");
System.out.println("它们分别是:");
for (int i = 0; i < hits.length(); i++) {
Document doc = hits.doc(i);
System.out.println(doc.get("name2"));
}
}