W
wangxiaoling
Unregistered / Unconfirmed
GUEST, unregistred user!
我曾经问过http://www.delphibbs.com/delphibbs/dispq.asp?lid=747459
现在还是碰到不少难题,我一直用Delphi,JAVA学起来觉得很吃力
1.这两段是不是要放在Serverlet中?怎么用?
建立索引:
IndexWriter writer = new IndexWriter(INDEX_PATH, new ChineseAnalyzer(), true/false);
Documentdo
c = newdo
cument();
doc.add(Field.Text("content", content);
doc.add(Field.Keyword("id", id);
....
writer.optimize();
writer.close();
全文检索:
Searcher searcher = new IndexSearcher(indexPath);
ChineseAnalyzer anlalyzer = new ChineseAnalyzer();
Query query = QueryParser.parse(queryString, "content", anlalyzer);
Hits hits = searcher.search(query);
//hits 里面就是检索到的内容
....
for (int ii=0;
ii<length;
ii++) {
do
cumentdo
c = hits.doc(ii);
String id =do
c.get("id");
String content =do
c.get("content");
......
}
2。这几句是不是在DOCUMENT对象里建立字段,content,id 是从那来的?
Documentdo
c = newdo
cument();
doc.add(Field.Text("content", content);
doc.add(Field.Keyword("id", id);
MY QQ:
现在还是碰到不少难题,我一直用Delphi,JAVA学起来觉得很吃力
1.这两段是不是要放在Serverlet中?怎么用?
建立索引:
IndexWriter writer = new IndexWriter(INDEX_PATH, new ChineseAnalyzer(), true/false);
Documentdo
c = newdo
cument();
doc.add(Field.Text("content", content);
doc.add(Field.Keyword("id", id);
....
writer.optimize();
writer.close();
全文检索:
Searcher searcher = new IndexSearcher(indexPath);
ChineseAnalyzer anlalyzer = new ChineseAnalyzer();
Query query = QueryParser.parse(queryString, "content", anlalyzer);
Hits hits = searcher.search(query);
//hits 里面就是检索到的内容
....
for (int ii=0;
ii<length;
ii++) {
do
cumentdo
c = hits.doc(ii);
String id =do
c.get("id");
String content =do
c.get("content");
......
}
2。这几句是不是在DOCUMENT对象里建立字段,content,id 是从那来的?
Documentdo
c = newdo
cument();
doc.add(Field.Text("content", content);
doc.add(Field.Keyword("id", id);
MY QQ: