Reputation: 4768
I'm trying to debug a application that is using SolrNet to query Solr. I'm trying to figure out what url that actually gets requested from SolrNet so that I can debug it more easilly in a web browser.
Upvotes: 5
Views: 3805
Reputation: 115
If you're not using .Net Core nor dependency injection this is how I did it.
using SolrNet.Impl.FieldSerializers;
using SolrNet.Impl.QuerySerializers;
public void function()
{
var serializer = new DefaultQuerySerializer(new DefaultFieldSerializer());
string rawQuery = serializer.Serialize(abstractSolrQuery);
// do something
}
Upvotes: 0
Reputation: 9205
Wrote both things (query only, or all parameters) into a LinqPad script for easier, complete reference:
void Main()
{
//Reset from scratch since doesn't play great with linqpad
Startup.InitContainer();
//Setup the container contents
Startup.Init<FakeModel>("http://localhost:8983/solr");
var queries = new List<ISolrQuery>
{
new SolrQueryByField("category_facet", "Fjärrin"),
new SolrQueryByField("branch_facet", "sigel"),
new SolrQueryByField("isArchived", "false"),
SolrQuery.All
};
var q = new SolrMultipleCriteriaQuery(queries, "AND");
var opts = new QueryOptions
{
Start = 20,
Rows = 15,
OrderBy = new[] { new SolrNet.SortOrder("myFakeField") }
};
DumpQuery(q);
DumpAllParameters(q, opts);
}
private void DumpQuery(ISolrQuery q)
{
var serializer = ServiceLocator.Current.GetInstance<ISolrQuerySerializer>();
var queryRaw = serializer.Serialize(q);
//Dump is a LinqpadMethod, running elsewhere this needs to be modified
queryRaw.Dump("Query only");
}
private void DumpAllParameters(ISolrQuery q, QueryOptions opts)
{
var queryExecuterInterface = ServiceLocator.Current.GetInstance<ISolrQueryExecuter<FakeModel>>();
var queryExecuter = queryExecuterInterface as SolrQueryExecuter<FakeModel>;
queryExecuter.GetAllParameters(q, opts).Dump("All Parameters");
}
public class FakeModel
{
}
Upvotes: 2
Reputation: 1323
Just to save you the effort of heading out to the forum :
var serializer = ServiceLocator.Current.GetInstance<ISolrQuerySerializer>();
queries = new List<ISolrQuery>
{
new SolrQueryByField("category_facet", "Fjärrin"),
new SolrQueryByField("branch_facet", sigel),
new SolrQueryByField("isArchived", "false"),
SolrQuery.All
};
var q = new SolrMultipleCriteriaQuery(queries,"AND");
var queryRaw = serializer.Serialize(q);
Debug.WriteLine(queryRaw);
Upvotes: 5
Reputation: 22555
There is a question on the SolrNet Google Group - Get Raw Solr Query that provides a couple of ways to get this output.
Upvotes: 4