Skip to content

Commit

Permalink
SOLR-7883: /mlt handler to support facets (apache#1010)
Browse files Browse the repository at this point in the history
* SOLR-7883: /mlt handler to support facets
  • Loading branch information
mkhludnev authored Sep 15, 2022
1 parent f1f32d3 commit 335ba21
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Bug Fixes

* SOLR-16343: Handle MDC snapshot being null (Dee Moore via Kevin Risden)

* SOLR-7883: MoreLikeThisHandler to support facets (Mikhail Khludnev)

Other Changes
---------------------
* SOLR-16351: Upgrade Carrot2 to 4.4.3, upgrade randomizedtesting to 2.8.0. (Dawid Weiss)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.handler.component.FacetComponent;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.request.SimpleFacets;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
Expand Down Expand Up @@ -215,7 +216,10 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
if (mltDocs.docSet == null) {
rsp.add("facet_counts", null);
} else {
SimpleFacets f = new SimpleFacets(req, mltDocs.docSet, params);
final ResponseBuilder responseBuilder =
new ResponseBuilder(req, rsp, Collections.emptyList());
SimpleFacets f = new SimpleFacets(req, mltDocs.docSet, params, responseBuilder);
FacetComponent.FacetContext.initContext(responseBuilder);
rsp.add("facet_counts", FacetComponent.getFacetCounts(f));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.component.FacetComponent;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryRequestBase;
Expand Down Expand Up @@ -236,6 +237,15 @@ public void testInterface() {
"//result/doc[1]/str[@name='id'][.='45']",
"//lst[@name='debug']/lst[@name='explain']");
}

params.set(FacetComponent.COMPONENT_NAME, "true");
params.set("facet.field", "name");
try (SolrQueryRequest mltreq = new LocalSolrQueryRequest(core, params)) {
assertQ(
mltreq,
"//result/doc[1]/str[@name='id'][.='45']",
"//lst[@name='facet_counts']/lst[@name='facet_fields']/lst[@name='name']/int[@name='George'][.='1']");
}
}

@Test
Expand Down

0 comments on commit 335ba21

Please sign in to comment.