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倍。

    注:lucene.net版本为:2.0.0.4
  • 相关阅读:
    OTA JAR和JAD的mime不同
    document.getElementById('selCatalog').remove(i)突然无效???!
    判断WAP1.1和WAP2.0并解析为wml或xhtml
    IE和firefox下显示html内容
    unixrisk tip
    unixftp windows
    unixstdin/stdout/stderr
    峰鸟摄影
    linuxgrep commond
    unixtutorial(recommended)
  • 原文地址:https://www.cnblogs.com/weekzero/p/1224045.html
Copyright © 2011-2022 走看看