First of all
Reference SolrNet.dll
Microsoft.Practices.ServiceLocation
Httpwebadapters
You can also download the Solrnet package with NuGet in the. NET IDe
Clear last Request (does not clear will cause duplicate request error)
SolrNet.Startup.Container.Clear ();
SolrNet.Startup.InitContainer ();
Connecting the SOLR server
Solrnet.startup.init<object_acceptanceformsolr> ("Http://60.205.149.65:8983/solr/connection");
Define SOLR
isolroperations<object_acceptanceformsolr> SOLR = servicelocator.current.getinstance<isolroperations< Object_acceptanceformsolr>> ();
Establish a sort, condition.
Queryoptions options = new Queryoptions ();
Options. rows =;//number of data bars
Options. start =;//start;//Starting item
Create a Condition Collection
list<isolrquery> query = new list<isolrquery> ();
Create a query condition (this can be a single condition check, or the name of a word-breaker configuration find the value contained in all columns of the field under the word breaker)
var QTB = new Solrquerybyfield ("Text_search", Text_search);
Add condition
Query. ADD (QTB);
Create a time range instance
Solrquerybyrange<datetime> qdaterange = null;
This is used to query the time range of the data definition (no special case value 0: querying all data)
Data within seven days
if (time = = "-7")
{
The last two parameters, one is the start time, the other is the end time
Qdaterange = new Solrquerybyrange<datetime> ("CreateDate", DateTime.Now.AddDays (int). Parse (Time)), DateTime.MaxValue);
}
else if (time = = "0")//All data
{
Qdaterange = new Solrquerybyrange<datetime> ("CreateDate", Datetime.minvalue, DateTime.MaxValue);
}
else//Other
{
Qdaterange = new Solrquerybyrange<datetime> ("CreateDate", DateTime.Today.AddMonths (int). Parse (Time)), DateTime.MaxValue);
}
Query. ADD (Qdaterange);
A list of more worthy relationships
list<isolrquery> depment = new list<isolrquery> ();
for (int i = 0; i < list. Count; i++)
{
Depment.add (New Solrquerybyfield ("department", List[i].childid));
}
Create a relationship, whether or OR and
var qarea = new Solrmultiplecriteriaquery (depment, "OR");
Add to Condition Collection
Query. ADD (Qarea);
//Can be omitted here (there are multiple arrays in the array, judging the relationship of the array relationship to the array within the array)
Solrquerybyrange<datetime> qdaterange = null;
Qdaterange = new Solrquerybyrange<datetime> ("CreateDate", Datetime.minvalue, DateTime.MaxValue);
Query. ADD (Qdaterange);
if (obj.filter! = NULL && Obj.filter.filters! = null && Obj.filter.filters.Count > 0)
{
Li st<isolrquery> filter = new list<isolrquery> ();
for (int i = 0; i < Obj.filter.filters.Count; i++)
{
if (obj.filter.filters[i].filters! = null && Obj.filter.filters[i].filters. Count > 0)
{
List<isolrquery> Filtersli = new list<isolrquery> ();
for (int n = 0; n < obj.fi Lter.filters[i].filters. Count; n++)
{
Filtersli. ADD (New Solrquerybyfield (Obj.filter.filters[i].filters[n].field, Obj.filter.filters[i].filters[n].value));
}
//create relationship, is or OR and
var qareds = new Solrmultiplecriteriaquery (Filtersli, obj.filter.filters[i].logic);
Query. ADD (qareds);
}
Else
{
if (Obj.filter.filters[i].field! = null &&!string. IsNullOrEmpty (Obj.filter.filters[i].field))
{
list<isolrquery> Filtersli = new list<isolrquery> ();
Filtersli. ADD (New Solrquerybyfield (Obj.filter.filters[i].field, Obj.filter.filters[i].value));
Create a relationship, whether or OR and
var qared = new Solrmultiplecriteriaquery (Filtersli, Obj.filter.logic);
Query. ADD (qared);
}
}
}
}
Sort
Options. AddOrder (New Solrnet.sortorder (Obj.sort[i].field, ORDER.ASC));
Relationship between conditional sets
var qtbo = new Solrmultiplecriteriaquery (query, "and");
Executing the query, there are 5 overloads (the default Wt=json in Solr solrconfig), which always reports XML when fetching data: the first column of the first row has been tested I modified the configuration in Solrconfig Wt=xml
solrqueryresults<object_acceptanceformsolr> results = Solr. Query (Qtbo, Options);
It is important to note that the case must be the same with SOLR in the request data, as in the Solr file
For specific SOLR configurations, see
Http://www.cnblogs.com/wenxinghaha/p/3988375.html
Solr. Net-side (Solrnet)