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.
When querying Solr using SolrNet, what is the easiest way to see the actual Url that gets requested?
Asked
Active
Viewed 3,461 times
5
-
wireshark/fiddler is also an option. – Lei Yang Apr 02 '22 at 04:16
4 Answers
4
There is a question on the SolrNet Google Group - Get Raw Solr Query that provides a couple of ways to get this output.

Paige Cook
- 22,415
- 3
- 57
- 68
4
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);

Fontanka16
- 1,161
- 1
- 9
- 37
-
2Just an FYI: This won't show any parameters created using SolrQueryInList -- it only gets SolryQueryByField parms. – LandonC May 21 '15 at 19:59
2
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
{
}

Thymine
- 8,775
- 2
- 35
- 47
0
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
}

Justin
- 115
- 4