I'm using Solr and Solrnet for the first time.
I have managed to create a schema, which has amongst them the following fields:
created_date DateTime
parent_id int
categories string multi-valued
I've been able to get a basic search working against the parent_id
field, as so:
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<SolrNode>>();
ICollection<SolrNode> results = solr.Query(new SolrQueryByField("parent_id", currentNode.Id.ToString()));
I've been able to figure out (kind of) how to return facets for all of my results, as so:
var solrFacet = ServiceLocator.Current.GetInstance<ISolrOperations<SolrNode>>();
var r = solrFacet.Query(SolrQuery.All, new QueryOptions
{
Rows = 0,
Facet = new FacetParameters
{
Queries = new[] {
//new SolrFacetDateQuery("created_date", DateTime.Now /* range start */, DateTime.Now.AddMonths(-6) /* range end */, "+1DAY" /* gap */) {
// HardEnd = true,
// Other = new[] {FacetDateOther.After, FacetDateOther.Before}
//}
new SolrFacetDateQuery("created_date", new DateTime(2011, 1, 1).AddDays(-1) /* range start */, new DateTime(2014, 1, 1).AddMonths(1) /* range end */, "+1MONTH" /* gap */) {
HardEnd = true,
Other = new[] {FacetDateOther.After, FacetDateOther.Before}
}
//,
//new SolrFacetFieldQuery("categories")
},
}
});
//foreach (var facet in r.FacetFields["categories"])
//{
// this.DebugLiteral.Text += string.Format("{0}: {1}{2}", facet.Key, facet.Value, "<br />");
//}
DateFacetingResult dateFacetResult = r.FacetDates["created_date"];
foreach (KeyValuePair<DateTime, int> dr in dateFacetResult.DateResults)
{
this.DebugLiteral.Text += string.Format("{0}: {1}{2}", dr.Key, dr.Value, "<br />");
}
But what I'm not able to figure out is how to plumb it all together. My requirements are as follows:
Page loads - show all search results where parent_id matches N. Query facets of search results and show tick boxes for the facets like so:
Categories
- Category 1
- Category 2
Within
- Last week
- Last month
- Last 3 months
- Last 6 months
- All time
User clicks on relevant tick boxes and then code executes another solr query, passing in both the parent_id criteria, along with the facets the user has selected.
I realise in my description I have simplified the process, and perhaps it is quite a big question to ask on StackOverflow, so I'm of course not expecting a working example (although if you're bored pls feel free ;-)) but could anyone provide any pointers, or examples? SolrNet does have an MVC sample app, but I'm using WebForms and not particularly comfortable with MVC just yet.
Any help would be greatly appreciated.
Thanks in advance Al