Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-8721 Added solr & lucene version to the response for debug reasons #16

Open
wants to merge 3 commits into
base: branch_5_5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -256,7 +256,8 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
// Copied from StandardRequestHandler... perhaps it should be added to doStandardDebug?
if (dbg == true) {
try {
NamedList<Object> dbgInfo = SolrPluginUtils.doStandardDebug(req, q, mlt.getRawMLTQuery(), mltDocs.docList, dbgQuery, dbgResults);
NamedList<Object> dbgInfo = SolrPluginUtils.doStandardDebug(req, q, mlt.getRawMLTQuery(),
mltDocs.docList, dbgQuery, dbgResults, dbg);
if (null != dbgInfo) {
if (null != filters) {
dbgInfo.add("filter_queries", req.getParams().getParams(CommonParams.FQ));
Expand Down
Expand Up @@ -97,9 +97,9 @@ public void process(ResponseBuilder rb) throws IOException
results = rb.getResults().docList;
}

NamedList stdinfo = SolrPluginUtils.doStandardDebug( rb.req,
rb.getQueryString(), rb.wrap(rb.getQuery()), results, rb.isDebugQuery(), rb.isDebugResults());
NamedList stdinfo = SolrPluginUtils.doStandardDebug(rb.req,
rb.getQueryString(), rb.wrap(rb.getQuery()), results, rb.isDebugQuery(), rb.isDebugResults(), rb.isDebugAll());

NamedList info = rb.getDebugInfo();
if( info == null ) {
rb.setDebugInfo( stdinfo );
Expand Down Expand Up @@ -138,7 +138,6 @@ public void process(ResponseBuilder rb) throws IOException
}
}


private void doDebugTrack(ResponseBuilder rb) {
SolrQueryRequest req = rb.req;
String rid = req.getParams().get(CommonParams.REQUEST_ID);
Expand Down Expand Up @@ -177,7 +176,7 @@ public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest
}
}
} else {
sreq.params.set(CommonParams.DEBUG_QUERY, "false");
sreq.params.set(CommonParams.DEBUG_QUERY, rb.isDebugAll() ? "true" : "false");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may look cumbersome, but it is needed in order to be able pass the "debugQuery" parameter to the shard in case that the query is distributed and doesn't return any results.

sreq.params.set(CommonParams.DEBUG, "false");
}
if (rb.isDebugTimings()) {
Expand Down
27 changes: 24 additions & 3 deletions solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
Expand Up @@ -30,6 +30,8 @@
import java.util.TreeMap;
import java.util.regex.Pattern;

import com.google.common.collect.ImmutableMap;
import org.apache.lucene.LucenePackage;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.search.BooleanClause;
Expand All @@ -50,6 +52,7 @@
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.RequestParams;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.component.HighlightComponent;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.ShardDoc;
Expand Down Expand Up @@ -78,8 +81,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.ImmutableMap;

/**
* <p>Utilities that may be of use to RequestHandlers.</p>
*
Expand Down Expand Up @@ -278,6 +279,21 @@ public static Set<String> getDebugInterests(String[] params, ResponseBuilder rb)
}
return debugInterests;
}


public static void doSolrVersionDebug(NamedList dbg) {
Package p = SolrCore.class.getPackage();
String specificationVersion = p.getSpecificationVersion();
dbg.add("solr-spec-version", specificationVersion == null ? "" : specificationVersion);
}

public static void doLuceneVersionDebug(SolrQueryRequest req,NamedList dbg) {
Package p = LucenePackage.class.getPackage();
String specificationVersion = p.getSpecificationVersion();
dbg.add("lucene-spec-version", specificationVersion == null ? "" : specificationVersion);
dbg.add("lucene-match-version", req.getSchema().getDefaultLuceneMatchVersion().toString());
}

/**
* <p>
* Returns a NamedList containing many "standard" pieces of debugging
Expand Down Expand Up @@ -322,10 +338,15 @@ public static NamedList doStandardDebug(
Query query,
DocList results,
boolean dbgQuery,
boolean dbgResults)
boolean dbgResults,
boolean dbgVersion)
throws IOException
{
NamedList dbg = new SimpleOrderedMap();
if (dbgVersion){
doSolrVersionDebug(dbg);
doLuceneVersionDebug(req, dbg);
}
doStandardQueryDebug(req, userQuery, query, dbgQuery, dbg);
doStandardResultsDebug(req, query, results, dbgResults, dbg);
return dbg;
Expand Down
Expand Up @@ -17,8 +17,12 @@
package org.apache.solr.handler;

import java.util.ArrayList;

import org.apache.lucene.util.Version;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.*;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.MoreLikeThisParams;
import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.core.SolrCore;
Expand All @@ -38,107 +42,123 @@ public class MoreLikeThisHandlerTest extends SolrTestCaseJ4 {
@BeforeClass
public static void moreLikeThisBeforeClass() throws Exception {
initCore("solrconfig.xml", "schema.xml");
lrf = h.getRequestFactory("standard", 0, 20 );
lrf = h.getRequestFactory("standard", 0, 20);
}

@Test
public void testInterface() throws Exception
{
public void testInterface() throws Exception {
SolrCore core = h.getCore();
MoreLikeThisHandler mlt = new MoreLikeThisHandler();

ModifiableSolrParams params = new ModifiableSolrParams();
SolrQueryRequestBase req = new SolrQueryRequestBase( core, params) {};

SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
};

// requires 'q' or single content stream
try {
mlt.handleRequestBody( req, new SolrQueryResponse() );
}
catch( Exception ex ) {} // expected
mlt.handleRequestBody(req, new SolrQueryResponse());
} catch (Exception ex) {
} // expected

// requires 'q' or single content stream
try {
ArrayList<ContentStream> streams = new ArrayList<>( 2 );
streams.add( new ContentStreamBase.StringStream( "hello" ) );
streams.add( new ContentStreamBase.StringStream( "there" ) );
req.setContentStreams( streams );
mlt.handleRequestBody( req, new SolrQueryResponse() );
}
catch( Exception ex ) {} // expected
ArrayList<ContentStream> streams = new ArrayList<>(2);
streams.add(new ContentStreamBase.StringStream("hello"));
streams.add(new ContentStreamBase.StringStream("there"));
req.setContentStreams(streams);
mlt.handleRequestBody(req, new SolrQueryResponse());
} catch (Exception ex) {
} // expected
finally {
req.close();
}
assertU(adoc("id","42","name","Tom Cruise","subword","Top Gun","subword","Risky Business","subword","The Color of Money","subword","Minority Report","subword", "Days of Thunder","subword", "Eyes Wide Shut","subword", "Far and Away", "foo_ti","10"));
assertU(adoc("id","43","name","Tom Hanks","subword","The Green Mile","subword","Forest Gump","subword","Philadelphia Story","subword","Big","subword","Cast Away", "foo_ti","10"));
assertU(adoc("id","44","name","Harrison Ford","subword","Star Wars","subword","Indiana Jones","subword","Patriot Games","subword","Regarding Henry"));
assertU(adoc("id","45","name","George Harrison","subword","Yellow Submarine","subword","Help","subword","Magical Mystery Tour","subword","Sgt. Peppers Lonley Hearts Club Band"));
assertU(adoc("id","46","name","Nicole Kidman","subword","Batman","subword","Days of Thunder","subword","Eyes Wide Shut","subword","Far and Away"));

assertU(adoc("id", "42", "name", "Tom Cruise", "subword", "Top Gun", "subword", "Risky Business", "subword", "The Color of Money", "subword", "Minority Report", "subword", "Days of Thunder", "subword", "Eyes Wide Shut", "subword", "Far and Away", "foo_ti", "10"));
assertU(adoc("id", "43", "name", "Tom Hanks", "subword", "The Green Mile", "subword", "Forest Gump", "subword", "Philadelphia Story", "subword", "Big", "subword", "Cast Away", "foo_ti", "10"));
assertU(adoc("id", "44", "name", "Harrison Ford", "subword", "Star Wars", "subword", "Indiana Jones", "subword", "Patriot Games", "subword", "Regarding Henry"));
assertU(adoc("id", "45", "name", "George Harrison", "subword", "Yellow Submarine", "subword", "Help", "subword", "Magical Mystery Tour", "subword", "Sgt. Peppers Lonley Hearts Club Band"));
assertU(adoc("id", "46", "name", "Nicole Kidman", "subword", "Batman", "subword", "Days of Thunder", "subword", "Eyes Wide Shut", "subword", "Far and Away"));
assertU(commit());

params.set(CommonParams.Q, "id:42");
params.set(MoreLikeThisParams.MLT, "true");
params.set(MoreLikeThisParams.SIMILARITY_FIELDS, "name,subword");
params.set(MoreLikeThisParams.INTERESTING_TERMS, "details");
params.set(MoreLikeThisParams.MIN_TERM_FREQ,"1");
params.set(MoreLikeThisParams.MIN_DOC_FREQ,"1");
params.set("indent","true");
params.set(MoreLikeThisParams.MIN_TERM_FREQ, "1");
params.set(MoreLikeThisParams.MIN_DOC_FREQ, "1");
params.set("indent", "true");

SolrQueryRequest mltreq = new LocalSolrQueryRequest( core, params);
assertQ("morelikethis - tom cruise",mltreq
,"//result/doc[1]/int[@name='id'][.='46']"
,"//result/doc[2]/int[@name='id'][.='43']");
SolrQueryRequest mltreq = new LocalSolrQueryRequest(core, params);
assertQ("morelikethis - tom cruise", mltreq
, "//result/doc[1]/int[@name='id'][.='46']"
, "//result/doc[2]/int[@name='id'][.='43']");

params.set(MoreLikeThisParams.BOOST, "true");
mltreq.close(); mltreq = new LocalSolrQueryRequest( core, params);
assertQ("morelikethis - tom cruise",mltreq
,"//result/doc[1]/int[@name='id'][.='46']"
,"//result/doc[2]/int[@name='id'][.='43']");

mltreq.close();
mltreq = new LocalSolrQueryRequest(core, params);
assertQ("morelikethis - tom cruise", mltreq
, "//result/doc[1]/int[@name='id'][.='46']"
, "//result/doc[2]/int[@name='id'][.='43']");

params.set(CommonParams.Q, "id:44");
mltreq.close(); mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ("morelike this - harrison ford",mltreq
,"//result/doc[1]/int[@name='id'][.='45']");
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ("morelike this - harrison ford", mltreq
, "//result/doc[1]/int[@name='id'][.='45']");

// test MoreLikeThis debug
params.set(CommonParams.DEBUG_QUERY, "true");
mltreq.close(); mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ("morelike this - harrison ford",mltreq
,"//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='rawMLTQuery']"
,"//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='boostedMLTQuery']"
,"//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='realMLTQuery']"
,"//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/lst[@name='explain']/str[@name='45']"
);
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ("morelike this - harrison ford", mltreq
, "count(//str[@name='solr-spec-version'])=1"
, "count(//str[@name='lucene-spec-version'])=1"
, "//str[@name='lucene-match-version']='" + Version.LATEST.toString() + "'"
, "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='rawMLTQuery']"
, "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='boostedMLTQuery']"
, "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/str[@name='realMLTQuery']"
, "//lst[@name='debug']/lst[@name='moreLikeThis']/lst[@name='44']/lst[@name='explain']/str[@name='45']"
);

// test that qparser plugins work
params.remove(CommonParams.DEBUG_QUERY);
params.set(CommonParams.Q, "{!field f=id}44");
mltreq.close(); mltreq = new LocalSolrQueryRequest(h.getCore(), params);
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ(mltreq
,"//result/doc[1]/int[@name='id'][.='45']");
, "count(//str[@name='solr-spec-version'])=0"
, "count(//str[@name='lucene-spec-version'])=0"
, "count(//str[@name='lucene-match-version'])=0"
, "//result/doc[1]/int[@name='id'][.='45']");

params.set(CommonParams.Q, "id:42");
params.set(MoreLikeThisParams.QF,"name^5.0 subword^0.1");
mltreq.close(); mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ("morelikethis with weights",mltreq
,"//result/doc[1]/int[@name='id'][.='43']"
,"//result/doc[2]/int[@name='id'][.='46']");
params.set(MoreLikeThisParams.QF, "name^5.0 subword^0.1");
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ("morelikethis with weights", mltreq
, "//result/doc[1]/int[@name='id'][.='43']"
, "//result/doc[2]/int[@name='id'][.='46']");


// test that qparser plugins work w/ the MoreLikeThisHandler
params.set(CommonParams.QT, "/mlt");
params.set(CommonParams.Q, "{!field f=id}44");
mltreq.close(); mltreq = new LocalSolrQueryRequest(h.getCore(), params);
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ(mltreq
,"//result/doc[1]/int[@name='id'][.='45']");
, "//result/doc[1]/int[@name='id'][.='45']");

// test that debugging works (test for MoreLikeThis*Handler*)
params.set(CommonParams.QT, "/mlt");
params.set(CommonParams.DEBUG_QUERY, "true");
mltreq.close(); mltreq = new LocalSolrQueryRequest(h.getCore(), params);
mltreq.close();
mltreq = new LocalSolrQueryRequest(h.getCore(), params);
assertQ(mltreq
,"//result/doc[1]/int[@name='id'][.='45']"
,"//lst[@name='debug']/lst[@name='explain']"
, "count(//str[@name='solr-spec-version'])=1"
, "count(//str[@name='lucene-spec-version'])=1"
, "//str[@name='lucene-match-version']='" + Version.LATEST.toString() + "'"
, "//result/doc[1]/int[@name='id'][.='45']"
, "//lst[@name='debug']/lst[@name='explain']"
);

// params.put(MoreLikeThisParams.QF,new String[]{"foo_ti"});
Expand Down
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.regex.Pattern;

import org.apache.lucene.util.Version;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
Expand Down Expand Up @@ -50,6 +51,9 @@ public static void beforeClass() throws Exception {
public void testBasicInterface() throws Exception {
//make sure the basics are in place
assertQ(req("q", "*:*", CommonParams.DEBUG_QUERY, "true"),
"count(//str[@name='solr-spec-version'])=1",
"count(//str[@name='lucene-spec-version'])=1",
"//str[@name='lucene-match-version']='" + Version.LATEST.toString() + "'",
"//str[@name='rawquerystring']='*:*'",
"//str[@name='querystring']='*:*'",
"//str[@name='parsedquery']='MatchAllDocsQuery(*:*)'",
Expand All @@ -74,6 +78,9 @@ public void testBasicInterface() throws Exception {
public void testPerItemInterface() throws Exception {
//Same as debugQuery = true
assertQ(req("q", "*:*", "debug", "true"),
"count(//str[@name='solr-spec-version'])=1",
"count(//str[@name='lucene-spec-version'])=1",
"//str[@name='lucene-match-version']='" + Version.LATEST.toString() + "'",
"//str[@name='rawquerystring']='*:*'",
"//str[@name='querystring']='*:*'",
"//str[@name='parsedquery']='MatchAllDocsQuery(*:*)'",
Expand All @@ -92,6 +99,9 @@ public void testPerItemInterface() throws Exception {
);
//timing only
assertQ(req("q", "*:*", "debug", CommonParams.TIMING),
"count(//str[@name='solr-spec-version'])=0",
"count(//str[@name='lucene-spec-version'])=0",
"count(//str[@name='lucene-match-version'])=0",
"count(//str[@name='rawquerystring'])=0",
"count(//str[@name='querystring'])=0",
"count(//str[@name='parsedquery'])=0",
Expand All @@ -107,6 +117,9 @@ public void testPerItemInterface() throws Exception {
);
//query only
assertQ(req("q", "*:*", "debug", CommonParams.QUERY),
"count(//str[@name='solr-spec-version'])=0",
"count(//str[@name='lucene-spec-version'])=0",
"count(//str[@name='lucene-match-version'])=0",
"//str[@name='rawquerystring']='*:*'",
"//str[@name='querystring']='*:*'",
"//str[@name='parsedquery']='MatchAllDocsQuery(*:*)'",
Expand All @@ -119,6 +132,9 @@ public void testPerItemInterface() throws Exception {

//explains
assertQ(req("q", "*:*", "debug", CommonParams.RESULTS),
"count(//str[@name='solr-spec-version'])=0",
"count(//str[@name='lucene-spec-version'])=0",
"count(//str[@name='lucene-match-version'])=0",
"count(//str[@name='rawquerystring'])=0",
"count(//str[@name='querystring'])=0",
"count(//str[@name='parsedquery'])=0",
Expand All @@ -133,6 +149,9 @@ public void testPerItemInterface() throws Exception {

assertQ(req("q", "*:*", "debug", CommonParams.RESULTS,
"debug", CommonParams.QUERY),
"count(//str[@name='solr-spec-version'])=0",
"count(//str[@name='lucene-spec-version'])=0",
"count(//str[@name='lucene-match-version'])=0",
"//str[@name='rawquerystring']='*:*'",
"//str[@name='querystring']='*:*'",
"//str[@name='parsedquery']='MatchAllDocsQuery(*:*)'",
Expand Down