Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-4240

Stats response always shows one extra empty facets element in Solr 4.0.

    XMLWordPrintableJSON

    Details

      Description

      If I don't specify stats.facet, it still shows one extra facets element.
      http://localhost:8888/solr/select?q=*:*&rows=0&stats=true&stats.field=szkb

       
      <lst name="stats">
      	<lst name="stats_fields">
      		<lst name="szkb">
      			<double name="min">1.0</double>
      			<double name="max">3.0</double>
      			<long name="count">4980</long>
      			<long name="missing">0</long>
      			<double name="sum">10369.0</double>
      			<double name="sumOfSquares">22637.0</double>
      			<double name="mean">2.082128514056225</double>
      			<double name="stddev">0.4586561046404609</double>
      			<lst name="facets"/> ===> extra facets elment
      		</lst>
      	</lst>
      </lst>
      

      If I specify stats.facet, then for each facet value, it shows one extra facets element.
      http://localhost:8888/solr/select?q=*:*&rows=0&stats=true&stats.field=szkb&stats.facet=filetype

       
      <lst name="facets">
      	<lst name="filetype">
      		<lst name="ppt">
      			<double name="min">1.0</double>
      			<double name="max">1.0</double>
      			<long name="count">1</long>
      			<long name="missing">0</long>
      			<double name="sum">1.0</double>
      			<double name="sumOfSquares">1.0</double>
      			<double name="mean">1.0</double>
      			<double name="stddev">0.0</double>
      			<lst name="facets"/> ===> extra facets elment, this is bad.
      		</lst>
      	</lst>
      </lst>
      

      The empty facets elment is no use, and annoying.

      The culprit is the code:
      org.apache.solr.handler.component.AbstractStatsValues.getStatsValues()

      StatsValuesFactory.java
      public NamedList<?> getStatsValues() {
       // add the facet stats
       ===> Here it always adds facets, in stead, it should check whether it is empty: if (!facets.isEmpty())
      NamedList<NamedList<?>> nl = new SimpleOrderedMap<NamedList<?>>();
      for (Map.Entry<String, Map<String, StatsValues>> entry : facets.entrySet()) {
        NamedList<NamedList<?>> nl2 = new SimpleOrderedMap<NamedList<?>>();
        nl.add(entry.getKey(), nl2);
        for (Map.Entry<String, StatsValues> e2 : entry.getValue().entrySet()) {
      	nl2.add(e2.getKey(), e2.getValue().getStatsValues());
        }
      }
      res.add(FACETS, nl);
      return res;
      }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              yuanyun.cn jefferyyuan
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: