[ 
https://issues.apache.org/jira/browse/SOLR-13156?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16751404#comment-16751404
 ] 

Andrey Kudryavtsev commented on SOLR-13156:
-------------------------------------------

{code:java}
protected NamedList<Integer> getListedTermCounts(String field, final 
ParsedParams parsed, List<String> terms) throws IOException {
  final SolrParams params = parsed.params;
  Integer mincount = parsed.params.getFieldInt(field, 
FacetParams.FACET_MINCOUNT);
  int offset = params.getFieldInt(field, FacetParams.FACET_OFFSET, 0);
  int limit = params.getFieldInt(field, FacetParams.FACET_LIMIT, 100);
  if (limit == 0) return new NamedList<>();
  if (mincount==null) {
    Boolean zeros = params.getFieldBool(field, FacetParams.FACET_ZEROS);
    mincount = (zeros!=null && !zeros) ? 1 : 0;
  }
  boolean missing = params.getFieldBool(field, FacetParams.FACET_MISSING, 
false);
  String sort = params.getFieldParam(field, FacetParams.FACET_SORT);
  String prefix = params.getFieldParam(field, FacetParams.FACET_PREFIX);
  final HashSet includeTerms = new HashSet<>(terms);
  final Predicate<BytesRef> termFilter = bytesRef -> 
includeTerms.contains(bytesRef.utf8ToString());
  boolean exists = params.getFieldBool(field, FacetParams.FACET_EXISTS, false);

  return getFacetTermEnumCounts(searcher, parsed.docs, field, offset, limit, 
mincount, missing, sort, prefix, termFilter, exists);
}{code}
 

"List terms order' doesn't work obviously, but 'code reusing' level is high. 

> Limiting field facet with certain terms via {!terms} not taking into account 
> sorting
> ------------------------------------------------------------------------------------
>
>                 Key: SOLR-13156
>                 URL: https://issues.apache.org/jira/browse/SOLR-13156
>             Project: Solr
>          Issue Type: Bug
>      Security Level: Public(Default Security Level. Issues are Public) 
>          Components: Facet Module
>            Reporter: Konstantin Perikov
>            Priority: Major
>         Attachments: SOLR-13156.patch
>
>
> When I'm doing limiting facet keys with \{!terms} it doesn't take into 
> account sorting.
> First query not limiting the facet keys:
> {{facet.field=title&facet.sort=count&facet=on&q=*:*}}
> Response as expected:
> {{"facet_counts":\{ "facet_queries":{}, "facet_fields":\{ "title":[ 
> "book2",3, "book1",2, "book3",1]}, "facet_ranges":{}, "facet_intervals":{}, 
> "facet_heatmaps":{}}}}}
>  
> When doing it with limiting:
> {{facet.field=\{!terms=Book3,Book2,Book1}title&facet.sort=count&facet=on&q=*:*}}
> I'm getting the exact order of how I list terms:
> {{"facet_counts":\{ "facet_queries":{}, "facet_fields":\{ "title":[ 
> "Book3",1, "Book2",3, "Book1",2]}, "facet_ranges":{}, "facet_intervals":{}, 
> "facet_heatmaps":{}}}}}
> I've looked at the code, and it's clearly an issue there:
>  
> org.apache.solr.request.SimpleFacets#getListedTermCounts
>  
> {{for (String term : terms) {}}
> {{    int count = searcher.numDocs(ft.getFieldQuery(null, sf, term), 
> parsed.docs);}}
> {{    res.add(term, count);}}
> {{}}}
>  
> it's just basically iterating over terms and don't do any sorting at all. 
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to