zoukankan      html  css  js  c++  java
  • Lucene.net搜索结果排序(单条件和多条件)

    Lucene支持对搜索条件的排序,一个条件或者多个条件,以及是升序还是降序,部分代码如下:
            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>");

    对于数据量大(索引文件大于50M)的索引,尽量不要用索引中的字段排序,要用索引ID排序(INDEXORDER);两者效率相差近10倍。
  • 相关阅读:
    背水一战 Windows 10 (90)
    背水一战 Windows 10 (89)
    背水一战 Windows 10 (88)
    背水一战 Windows 10 (87)
    背水一战 Windows 10 (86)
    背水一战 Windows 10 (85)
    背水一战 Windows 10 (84)
    背水一战 Windows 10 (83)
    背水一战 Windows 10 (82)
    背水一战 Windows 10 (81)
  • 原文地址:https://www.cnblogs.com/wycg1984/p/2133371.html
Copyright © 2011-2022 走看看