/** PrefixQuery前缀搜索符合的所有放入map
* @param File indexDir,索引目录;
* @param String word 索引关键词前缀
* @return Map
* @author niewj @since 2011-3-10 */
public
static
Map getPairMap(File indexDir,String field,String word) {
Map pairMap=new
HashMap();
Directory dir=null
;
try
{
dir = new
SimpleFSDirectory(indexDir);
IndexSearcher searcher=new
IndexSearcher(dir);
Term term=new
Term(field,word);
PrefixQuery query=new
PrefixQuery(term);
TopDocs topDocs=searcher.search(query,5000
);
System.out.println("total hit:"
+topDocs.totalHits);
ScoreDoc[] docs=topDocs.scoreDocs;
for
(
int
i=
0
;i
Document doc=searcher.doc(docs[i].doc);
String pair=doc.getField("pairContent"
).stringValue();
String value=doc.getField("pairLines"
).stringValue();
pairMap.put(pair, Integer.parseInt(value));
System.out.println(pair+"-"
+value);
}
} catch
(IOException e) {
e.printStackTrace(); //
}
return
pairMap;
}
* @param File indexDir,索引目录;
* @param String word 索引关键词前缀
* @return Map
* @author niewj @since 2011-3-10 */
public
static
Map getPairMap(File indexDir,String field,String word) {
Map pairMap=new
HashMap();
Directory dir=null
;
try
{
dir = new
SimpleFSDirectory(indexDir);
IndexSearcher searcher=new
IndexSearcher(dir);
Term term=new
Term(field,word);
PrefixQuery query=new
PrefixQuery(term);
TopDocs topDocs=searcher.search(query,5000
);
System.out.println("total hit:"
+topDocs.totalHits);
ScoreDoc[] docs=topDocs.scoreDocs;
for
(
int
i=
0
;i
Document doc=searcher.doc(docs[i].doc);
String pair=doc.getField("pairContent"
).stringValue();
String value=doc.getField("pairLines"
).stringValue();
pairMap.put(pair, Integer.parseInt(value));
System.out.println(pair+"-"
+value);
}
} catch
(IOException e) {
e.printStackTrace(); //
}
return
pairMap;
}