Lucene.net搜索结果排序(单条件和多条件)

string INDEX_STORE_PATH = Server.MapPath( " index " );   // INDEX_STORE_PATH 为索引存储目录
         string keyword = TextBox2.Text;                      // 搜索内容

         Hits myhit
= null ;
         
         IndexSearcher mysea
= new IndexSearcher(INDEX_STORE_PATH);
         QueryParser q
= new QueryParser( " indexcontent " , new StandardAnalyzer());
         Query query
= q.Parse(keyword);

         Sort sort
= new Sort();
         SortField f
= new SortField( " createdate " , SortField.STRING, true ); // 按照createdate字段排序,true表示降序
         sort.SetSort(f);

        
// 多个条件排序
        
// Sort sort = new Sort();
        
// SortField f1 = new SortField("createdate", SortField.DOC, true);
        
// SortField f2 = new SortField("bookname", SortFiedl.INT, false);
        
// sort.setSort(new SortField[] { f1, f2 });

         myhit = mysea.Search(query, sort);
         Response.Write(
" 关于: " + keyword + "    搜索到 " + myhit.Length() + " 个结果<br> " );

你可能感兴趣的:(Lucene)