E-commerce on your Fingertips---(9) facet capabilities in. NET Development SOLR

Source: Internet
Author: User
Tags solr

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&gt        ;            <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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.