有类似这样的数据:
“type.234.2311111.type”
“type.234.12222.2311111.type”
“type.234.2.2311111.type”
“type.234.3.2311111.type”
“type.234.4.2311111.type”
“type.234.4.2311111.type”
“type.234.6.2311111.type”
“type.234.6.2311111.type”
“type.234.7.2311111.type”我建立索引的时候是这样的语句:
IndexWriter writer = new IndexWriter(indexpath,analyzer,true,IndexWriter.MaxFieldLength.UNLIMITED);
我检索方法如下:
/**基础搜索里面增加一个文件id检索*/ 
public List search(String file_id,String key) {
long start=System.currentTimeMillis();
String indexpath1=indexpath;
// 获取Paoding中文分词器
Analyzer analyzer = new PaodingAnalyzer();
// 检索
IndexReader reader;
try {
reader = IndexReader.open(indexpath1);
/* 下面这个表示要同时搜索这两个域,而且只要一个域里面有满足我们搜索的内容就行 */
BooleanClause.Occur[] clauses = { 
BooleanClause.Occur.SHOULD,BooleanClause.Occur.SHOULD,
BooleanClause.Occur.SHOULD,BooleanClause.Occur.SHOULD };
Query query = MultiFieldQueryParser.parse(key, new String[]{"pk_auto_id", "type", "title", "post_user_name" }, clauses, analyzer);
TopDocCollector collector = new TopDocCollector(perPage * CACHE_PAGE); // perPage
Searcher searcher = new IndexSearcher(reader);
searcher.search(query, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
System.out.println();System.out.println(" key:"+key);
for(int i=0;i<hits.length;i++){
int docId = hits[i].doc;
Document doc3 = searcher.doc(docId);
String id=doc3.get("pk_auto_id");
String title = doc3.get("title");
String content=doc3.get("post_user_name");
System.out.println(" id:"+id+"   title:"+title+"   post_user_name:"+content);

}
int numTotalHits = collector.getTotalHits();
String str="";
str+="search :" + numTotalHits+",   查询花了"+(System.currentTimeMillis()-start)+"毫秒---->";
System.out.println(" time:" + str);
System.out.println();
//System.out.println(" serch'size:" + numTotalHits);


} catch (CorruptIndexException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}

return null;
}
我用的是庖丁解牛中文分词技术,检索的时候,我希望当关键词是“.234.”的时候,所有的字符串带有'.234.'的都检索出来,当关键词是“.234.6.”的时候,所有的字符串带有'.234.6.'的都检索出来;但是目前碰到问题了,当关键词填入“.234.”时候,一个数据也检索不出来,百度了下 google了下,说是目前的分词技术不支持数字检索,问下,如何做才能支持这样的数字检索呢?

解决方案 »

  1.   

    我怎么记得支持呢?呵呵!!
    .234.6.
    这个关键词里面的点,保存到索引时要不去掉,要不替换为 \\.看看type.234.2311111.type你搜索 234.2311111 这个数字就能搜索到了。
    数字的拆词算法,不会把一个数字拆分成 2,34 234 23 231 23111 等多个的,而是一个整体。
      

  2.   

    对了,测试地址:http://www.java2000.net/p4381你搜索看看就知道了,我的也是庖丁的
      

  3.   


    说的很对的,建议将.换成|试试看!比如 type.234.2311111.type 换成type|234|2311111|type 来建立文件索引!