Return-Path: Delivered-To: apmail-lucene-solr-dev-archive@minotaur.apache.org Received: (qmail 1139 invoked from network); 7 Jan 2010 23:15:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Jan 2010 23:15:16 -0000 Received: (qmail 19729 invoked by uid 500); 7 Jan 2010 23:15:15 -0000 Delivered-To: apmail-lucene-solr-dev-archive@lucene.apache.org Received: (qmail 19630 invoked by uid 500); 7 Jan 2010 23:15:15 -0000 Mailing-List: contact solr-dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: solr-dev@lucene.apache.org Delivered-To: mailing list solr-dev@lucene.apache.org Received: (qmail 19572 invoked by uid 99); 7 Jan 2010 23:15:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jan 2010 23:15:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jan 2010 23:15:14 +0000 Received: from brutus.apache.org (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 5F714234C052 for ; Thu, 7 Jan 2010 15:14:54 -0800 (PST) Message-ID: <81667553.110151262906094376.JavaMail.jira@brutus.apache.org> Date: Thu, 7 Jan 2010 23:14:54 +0000 (UTC) From: "Peter Sturge (JIRA)" To: solr-dev@lucene.apache.org Subject: [jira] Resolved: (SOLR-1672) RFE: facet reverse sort count In-Reply-To: <1642315213.1261130058217.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/SOLR-1672?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Peter Sturge resolved SOLR-1672. -------------------------------- Resolution: Fixed Marking as resolved. > RFE: facet reverse sort count > ----------------------------- > > Key: SOLR-1672 > URL: https://issues.apache.org/jira/browse/SOLR-1672 > Project: Solr > Issue Type: Improvement > Components: search > Affects Versions: 1.4 > Environment: Java, Solrj, http > Reporter: Peter Sturge > Priority: Minor > Attachments: SOLR-1672.patch > > Original Estimate: 0h > Remaining Estimate: 0h > > As suggested by Chris Hosstetter, I have added an optional Comparator to the BoundedTreeSet in the UnInvertedField class. > This optional comparator is used when a new (and also optional) field facet parameter called 'facet.sortorder' is set to the string 'dsc' > (e.g. &f..facet.sortorder=dsc for per field, or &facet.sortorder=dsc for all facets). > Note that this parameter has no effect if facet.method=enum. > Any value other than 'dsc' (including no value) reverts the BoundedTreeSet to its default behaviour. > > This change affects 2 source files: > > UnInvertedField.java > [line 438] The getCounts() method signature is modified to add the 'facetSortOrder' parameter value to the end of the argument list. > > DIFF UnInvertedField.java: > - public NamedList getCounts(SolrIndexSearcher searcher, DocSet baseDocs, int offset, int limit, Integer mincount, boolean missing, String sort, String prefix) throws IOException { > + public NamedList getCounts(SolrIndexSearcher searcher, DocSet baseDocs, int offset, int limit, Integer mincount, boolean missing, String sort, String prefix, String facetSortOrder) throws IOException { > [line 556] The getCounts() method is modified to create an overridden BoundedTreeSet(int, Comparator) if the 'facetSortOrder' parameter equals 'dsc'. > DIFF UnInvertedField.java: > - final BoundedTreeSet queue = new BoundedTreeSet(maxsize); > + final BoundedTreeSet queue = (sort.equals("count") || sort.equals("true")) ? (facetSortOrder.equals("dsc") ? new BoundedTreeSet(maxsize, new Comparator() > { @Override > public int compare(Object o1, Object o2) > { > if (o1 == null || o2 == null) > return 0; > int result = ((Long) o1).compareTo((Long) o2); > return (result != 0 ? result > 0 ? -1 : 1 : 0); //lowest number first sort > }}) : new BoundedTreeSet(maxsize)) : null; > > SimpleFacets.java > [line 221] A getFieldParam(field, "facet.sortorder", "asc"); is added to retrieve the new parameter, if present. 'asc' used as a default value. > DIFF SimpleFacets.java: > + String facetSortOrder = params.getFieldParam(field, "facet.sortorder", "asc"); > > [line 253] The call to uif.getCounts() in the getTermCounts() method is modified to pass the 'facetSortOrder' value string. > DIFF SimpleFacets.java: > - counts = uif.getCounts(searcher, base, offset, limit, mincount,missing,sort,prefix); > + counts = uif.getCounts(searcher, base, offset, limit, mincount,missing,sort,prefix, facetSortOrder); > Implementation Notes: > I have noted in testing that I was not able to retrieve any '0' counts as I had expected. > I believe this could be because there appear to be some optimizations in SimpleFacets/count caching such that zero counts are not iterated (at least not by default) > as a performance enhancement. > I could be wrong about this, and zero counts may appear under some other as yet untested circumstances. Perhaps an expert familiar with this part of the code can clarify. > In fact, this is not such a bad thing (at least for my requirements), as a whole bunch of zero counts is not necessarily useful (for my requirements, starting at '1' is just right). > > There may, however, be instances where someone *will* want zero counts - e.g. searching for zero product stock counts (e.g. 'what have we run out of'). I was envisioning the facet.mincount field > being the preferred place to set where the 'lowest value' begins (e.g. 0 or 1 or possibly higher), but because of the caching/optimization, the behaviour is somewhat different than expected. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.