<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    皮杜妮

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      887 Posts :: 3 Stories :: 7 Comments :: 0 Trackbacks
    facet 自己理解就是分組聚合用的, 如下說明
     


    http://blog.csdn.net/a925907195/article/details/47257243



    Solr中的group與facet的區別

    如果是簡單的使用的話,那么Facet與group都可以用來進行數據的聚合查詢,但是他們還是有很大的區別的。

    首先上facet跟group的操作:

    Facet的例子:

    public voidFacetFieldQuery() throws Exception {

          solrServer = createSolrServer();

          SolrQueryquery = newSolrQuery();//建立一個新的查詢

          query.setQuery("jobsName:計算機維護");

          query.setFacet(true);//設置facet=on

          // 分類信息分為:薪水,發布時間,教育背景,工作經驗,公司類型,工作類型

          query.addFacetField(new String[] {"salary","publishDate",

                "educateBackground","jobExperience","companytype","jobsType" });//設置需要facet的字段

          query.setFacetLimit(10);// 限制facet返回的數量

          query.setFacetMissing(false);//不統計null的值

          query.setFacetMinCount(1);// 設置返回的數據中每個分組的數據最小值,比如設置為1,則統計數量最小為1,不然不顯示

     

          //query.addFacetQuery("publishDate:[2014-04-11T00:00:00Z TO2014-04-13T00:00:00Z]");

          QueryResponseresponse = solrServer.query(query);

          System.out.println("查詢時間:" + response.getQTime());

          List<FacetField>facets = response.getFacetFields();//返回的facet列表

          for (FacetField facet :facets) {

             System.out.println(facet.getName());

             System.out.println("----------------");

             List<Count>counts = facet.getValues();

             for (Count count : counts){

                System.out.println(count.getName()+":"+ count.getCount());

             }

             System.out.println();

          }

     

       }

    運行結果如下:

    查詢時間:66

    salary

    ----------------

    面議:6882

    2001-4000:1508

    其他:671

    4001-6000:536

    3000-4499:224

    2000-2999:181

    6001-8000:179

    3000-5000:82

    1000-2000:81

    4500-5999:75

     

    publishDate

    ----------------

    2014-08-05T00:00:00Z:793

    2014-08-04T00:00:00Z:775

    2014-07-30T00:00:00Z:601

    2014-08-07T00:00:00Z:548

    2014-08-06T00:00:00Z:539

    2014-08-11T00:00:00Z:472

    2014-08-20T00:00:00Z:439

    2014-08-12T00:00:00Z:438

    2014-08-01T00:00:00Z:405

    2014-08-03T00:00:00Z:376

     

    educateBackground

    ----------------

    大專:4486

    本科:1872

    其他:1344

    不限:1147

    中專:680

    高中:472

    薪水范圍::430

    中技:161

    初中:140

    碩士:94

     

    jobExperience

    ----------------

    其他:2623

    不限:2249

    1-3年:1770

    1年:1301

    2年:773

    3-4年:528

    3-5年:379

    應屆畢業生:309

    5-7年:162

    1年以上:136

     

    companytype

    ----------------

    民營公司:3702

    民營:2605

    國企:835

    股份制企業:729

    其他:707

    合資:632

    外資(非歐美):377

    外商獨資:350

    外資(歐美):271

    上市公司:228

     

    jobsType

    ----------------

    全職:10734

    兼職:59

    實習:39

     

     

    Group查詢:

    /**group查詢

        * @throws Exception

        */

       public void GroupFieldQuery() throws Exception {

          solrServer = createSolrServer();

           SolrQuery query = new SolrQuery("jobsName:計算機維護");

            // 設置通過facet查詢為true,表示查詢時使用facet機制

            query.setParam(GroupParams.GROUP,true);   

            query.setParam(GroupParams.GROUP_FIELD,"salary");

            // 設置每個quality對應的

            query.setParam(GroupParams.GROUP_LIMIT,"1");

            // 設置返回doc文檔數據,因只需要數量,故設置為0

            query.setRows(10);

            QueryResponse response = solrServer.query(query);

            if (response !=null) {

              GroupResponse groupResponse =response.getGroupResponse();   

                if(groupResponse !=null) {   

              List<GroupCommand> groupList =groupResponse.getValues();    

              for(GroupCommand groupCommand : groupList){   

                  List<Group> groups =groupCommand.getValues();   

                  for(Group group : groups) {

                    System.out.println("group查詢..."+group.getGroupValue()+"數量為:"+group.getResult().getNumFound());

                  }   

              }   

                }   

            }

     

       }

    group查詢...面議數量為:6882

    group查詢...4500-5999數量為:75

    group查詢...2001-4000數量為:1508

    group查詢...其他數量為:671

    group查詢...2000-2999數量為:181

    group查詢...4001-6000數量為:536

    group查詢...2000-4000數量為:19

    group查詢...2000-3000數量為:34

    group查詢...3000-4499數量為:224

    group查詢...3000-5000數量為:82

     

    facet的查詢結果主要是分組信息:有什么分組,每個分組包括多少記錄;但是分組中有哪些數據是不可知道的,只有進一步搜索。
    group則類似于關系數據庫的group by,可以用于一個或者幾個字段去重、顯示一個group的前幾條記錄等。

    The Grouping feature only works if groups are inthe same shard. You must use the custom sharding feature to use the Groupingfeature.

     

    兩者其實用起來還是有比較大的區別的,但是如果說區別的話可以看下wiki上的這段

    Field Collapsing and Result Grouping aredifferent ways to think about the same Solr feature.

    Field Collapsing collapsesa group of results with the same field value down to a single (or fixed number)of entries. For example, most search engines such as Google collapse on site soonly one or two entries are shown, along with a link to click to see moreresults from that site. Field collapsing can also be used to suppress duplicatedocuments.

    Result Grouping groupsdocuments with a common field value into groups, returning the top documentsper group, and the top groups based on what documents are in the groups. Oneexample is a search at Best Buy for a common term such as DVD, that shows thetop 3 results for each category ("TVs &Video","Movies","Computers", etc)

     

    下面這兩個查詢語句一個是facet的一個是group的

    http://localhost:8080/solr/JobsOtherWeb0/select?q=jobsName%3A%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%B4%E6%8A%A4&group=true&group.field=salary&group.limit=1&rows=10

    http://localhost:8080/solr/JobsOtherWeb0/select?q=jobsName%3A%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%B4%E6%8A%A4&facet=true&facet.field=salary&facet.field=publishDate&facet.field=educateBackground&facet.field=jobExperience&facet.field=companytype&facet.field=jobsType&facet.limit=10&facet.missing=false&facet.mincount=1

     

    其中facet查詢出的如下:(只截取部分結果)




    根據條件查詢出的是查詢結果,facet是聚類后的信息跟查詢條件是分開的,查詢結果也跟facet沒關系。

    但是下面看group查詢的




    也就是你的查詢條件是跟group相關的,返回的查詢結果也是跟group相關的,比如說你想要查詢的結果在每個分組中 都有數據采集,那么就最好用group,這樣出來的數據跟group也是相關的,但是有個問題,比如說你要查詢group每個采集1個,ok那么你查詢的 時候的條件rows就無效了(也不能說無效,主要是看你怎么使用),就是最多每個分組給你返回一個,多了沒有了。

    再細說點就是如果你想查詢歸查詢聚類歸聚類,那么使用facet,如果想使用類似采集的效果,每個group分組采集多少個,那么使用group查詢。

    posted on 2016-05-03 16:34 豬眼睛 閱讀(725) 評論(0)  編輯  收藏 所屬分類: 搜索引擎
    主站蜘蛛池模板: 亚洲av无码成人精品区| 成人毛片18女人毛片免费96| 国产一区二区视频免费| 亚洲AV一二三区成人影片| 1024免费福利永久观看网站| 亚洲网站在线免费观看| 美女被免费喷白浆视频| 亚洲区日韩精品中文字幕| 国产网站免费观看| v片免费在线观看| 亚洲一区爱区精品无码| 美女视频黄的免费视频网页| 久久夜色精品国产噜噜噜亚洲AV | 亚洲a∨无码一区二区| 最近最新的免费中文字幕| 亚洲AV无码AV日韩AV网站| 亚洲不卡无码av中文字幕| 91精品成人免费国产| 4444亚洲国产成人精品| 欧美在线看片A免费观看| 妇女自拍偷自拍亚洲精品| 亚洲人成网站观看在线播放| 久久九九免费高清视频| 久久亚洲精品人成综合网| 一二三四在线观看免费高清中文在线观看| 激情五月亚洲色图| 亚洲精品色婷婷在线影院| 免费一级毛片无毒不卡| 国产成人精品日本亚洲专一区| 伊人久久亚洲综合影院| 免费看成人AA片无码视频吃奶| 亚洲一区二区三区国产精品无码| 国产成人无码区免费A∨视频网站 国产成人涩涩涩视频在线观看免费 | 亚洲欧美日韩久久精品| 亚洲国产精品成人网址天堂| 最新国产乱人伦偷精品免费网站 | 成人黄软件网18免费下载成人黄18免费视频 | 亚洲午夜无码久久久久软件| 国产亚洲美女精品久久久| 中文字幕天天躁日日躁狠狠躁免费| 亚洲a∨国产av综合av下载|