In the previous section we demonstrated the use of the facet feature in Solradmin for grouping statistics, which we looked at how to use. NET to develop facet functionality in SOLR. While the facet function is spoken,
Let's see. How to use SOLR queries in net. Using the client tool is easysorl.net, everyone can go to CodePlex download. This tool is very useful.
See, that's the function we're going to demonstrate.
1. Fuzzy query
A fuzzy query is a search for a given character to get a result. The following example is to query all items that contain white in the product name, and the resulting results are as follows
Code
public void Query () {if (string. Isnullorwhitespace (TextBox1.Text.Trim ())) {#region query all var resu LT = operations. Query ("Collection1", "/select", solrquery.all, NULL); var header = Binaryresponseheaderparser.parse (result); var examples = Binaryqueryresultsparser.parse (result); This.dataGridView1.DataSource = examples. ToList (); #endregion} else {#region fuzzy query by product name Isolrquery Solrquery = New Solrquery (TextBox1.Text.Trim ()); var result = operations. Query ("Collection1", "/select", solrquery, NULL); var header = Binaryresponseheaderparser.parse (result); var examples = Binaryqueryresultsparser.parse (result); This.dataGridView1.DataSource = examples. ToList (); #endregion}}
2. Accurate query
at the time of the query, we sometimes have to search for an item based on the ID of the product or the code of the product. The following example demonstrates the ability to accurately query by commodity encoding.
if (string. Isnullorwhitespace (TextBox2.Text.Trim ())) { return; } String conditon = "ProductCode:" + TextBox2.Text.Trim (); Isolrquery solrquery = new Solrquery (conditon); var result = operations. Query ("Collection1", "/select", solrquery, null); var header = Binaryresponseheaderparser.parse (result); var examples = Binaryqueryresultsparser.parse (result); This.dataGridView1.DataSource = examples. ToList ();
3.Facet Grouping statistics
When querying, sometimes we need to group the results of the query, for example, to know how many items are in each category that contains the product, and how many items are in each price range.
The following example counts how many items are in each category.
<summary>//Facet enquiry by Type///</summary>//<param name= "Sender" ></param> ; <param name= "E" ></param> private void Button3_Click (object sender, EventArgs e) { Label3. Visible = true; var dic=new dictionary<string,icollection<string>> (); dic["facet"] = new string[] {"true"}; var options = new list<string> (); Options. ADD ("CategoryName"); dic["Facet.field"] = options; var result = operations. Query ("Collection1", "/select", solrquery.all,dic); var header = Binaryresponseheaderparser.parse (result); var examples = Binaryqueryresultsparser.parse (result); Group List<facetfield> idictionary<string, ilist<facetfield>> facetdic=new BinaryFacetFieldsPar Ser (). Parse (result); String strfacet = ""; foreach (var item in Facetdic) {Strfacet + = "Group field:" +item. key+ "\ r \ n"; foreach (Var facetitem in item. Value) {Strfacet + = Facetitem.name + "(" + facetItem.Count.ToString () + ")" + "---"; }} label3. Text = Strfacet; This.dataGridView1.DataSource = examples. ToList (); }
Demo Download: http://download.csdn.net/detail/zx13525079024/7385945