Use of solr.net and solr.net

Source: Internet
Author: User

Use of solr.net and solr.net
Introduction

Recently, I was working on a log system. I encountered a query bottleneck when using a common relational database for data query. I thought of using mature search application services, the mature search application services I know include solr and elasticsearch. Due to the rush of time, I finally chose solr.

Introduction SOLR

Solr is a high-performance full-text search server developed using Java 5 and based on Lucene. At the same time, it is expanded to provide a richer query language than Lucene, and at the same time, it is configurable and scalable, and the query performance is optimized, it also provides a complete functional management interface, which is an excellent full-text search engine. It is a fully-developed full-text search Server Based on Lucene. How to deploy solr on a windows server, we recommend that you use a mailing peak blog http://www.cnblogs.com/wenxingha/tag/.net%20%20solr. Solr 5.0 currently does not support IK word splitting, so we have to use solr 4.10. solr is easy to deploy. You can use the configuration file to index the database data to the solr server, data can be synchronized to the solr server at regular intervals Based on the index time.

Solr driver in. NET

We used the C # language during the query, so solr should be used in.. NET driver. Currently, solr is popular. NET and easynet. solr, solr. NET is a relatively stable open-source solr driver, easynet. solr works together in solr. NET has been encapsulated. I use the most native solr.net driver https://github.com/mausch/solrnet. Since the solr server provides restful interface operations, solrnet's solr service requests are actually based on http requests.

Solrnet applications

I have explained too much about solrnet applications. Here I mainly want to talk about solrnet grouping queries.

Code attachment

Public class SolrNetOperate {static SolrNetOperate () {Startup. init <LogItems> ("http: // 000.000.000.000: 8080/solr/logs ");} /// <summary> /// </summary> /// <param name = "dictPars"> query parameter dictionary </param> /// <param name = "start "> Start Time of the page </param> /// <param name =" rows "> page size </param> /// <param name =" startTime "> Start Time </param> /// <param name = "endTime"> end time </param> /// <param name = "count"> total number of output parameters </param> /// <return S> </returns> /// <remarks> oldman July 23, 2015 14:11:43 </remarks> public static List <int> GroupingSerach (Dictionary <string, string> dictPars, int start, int rows, DateTime startTime, DateTime endTime, out int count) {// defines solr var solr = ServiceLocator. current. getInstance <ISolrOperations <LogItems> (); var queryOptions = new QueryOptions (); // defines the group var groupingParameters = new GroupingParameters (); grou PingParameters. fields = new Collection <string> {"logs_id"}; groupingParameters. ngroups = true; // set the total number of query groups to true // define the filter condition var timeRange = new SolrQueryByRange <DateTime> ("logs_time", startTime, endTime); queryOptions. addFilterQueries (timeRange); foreach (string key in dictPars. keys) {queryOptions. addFilterQueries (new SolrQueryByField (key, dictPars [key]);} // defines the sorting queryOptions. orderBy = new Coll Ection <SortOrder> {new SortOrder ("logs_id", Order. DESC)}; queryOptions. grouping = groupingParameters; queryOptions. start = start; queryOptions. rows = rows; SolrQueryResults <LogItems> res = solr. query (SolrQuery. all, queryOptions); GroupedResults <LogItems> items = res. grouping ["logs_id"]; count = items. ngroups ?? 0; return items. Groups. Select (item => Convert. ToInt32 (item. GroupValue). ToList ();}}

Here is the query, sorting, and paging After grouping. The code is very clear. If you have any questions, please contact me.

With source code: https://github.com/lipeng1991/SolrDemo

My. NET technology exchange group: 226704167

Studying hard is just a dream.

Related Article

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.