Overview:
There is often a need to query for certain content when developing a website. If you do a search based on a database query, the efficiency is often very bad because you want to do fuzzy matching on multiple fields. In this case, SOLR can be used to improve the efficiency of the search. SOLR is a stand-alone enterprise Search application server that provides API interfaces similar to Web-service. This describes the environment and configuration of SOLR, and then applies the solrnet client operation to the SOLR server.
First, SOLRinstallation
Software Downloads:SOLR 5.0,JDK 7 or above
Install the jdk. . SOLR directly after the extraction, with the command line can be started directly.
Enter the server folder on the command line and start the SOLR service with the following command :
Enter the following address in the browser: http://localhost:8983/solr/. You can open the following page to indicate that the SOLR service has started normally.
SOLR is a Java-based developer and requires a JDK environment. The downloaded SOLR package comes with a jetty Web server. Here is the use of self-brought.
Ii. SOLRConfiguration
New core:
You can do this by opening the Web interface above. Click on the core admin menu to access the core management interface.
Click the <add core> button to create a new Core, prompting for a configuration file.
So let's create a new folder called "Test" under the path to \SOLR-5.0.0\SERVER\SOLR. To the Solr-5.0.0\server\solr\configsets\basic_configs folder, copy the Conf folder to the Test folder you just created . This provides the required configuration files, and then describes the configuration files.
Then click the Add Core button to complete the core creation.
Configure Schema.xml for Solr :
In general , you can use SOLRAs long as you configure the Schema file. the Schema file is used to describe the data structure of the SOLRS index.
FieldType: Describes the data types supported by SOLR
UniqueKey: Tag SOLR 's primary key field
Field: Fields that Mark the index of SOLR
DynamicField: An indexed field that supports wildcard characters that is not found in field matches the field
In general, to add a field node, field corresponds to the fields you want to query. Added the title field.
Then set the primary key in UniqueKey. Set the ID field as the primary key.
Third, solrnetBuild Index
Download solrnet.
Recommendation: http://download.csdn.net/download/tp4479/4666325. Compile it yourself after downloading. Although it can be downloaded from Nuget, this version seems to have bugs.
To build an index using solr :
The following code adds an index data to the SOLR server. Bulk add indexes are similar.
1Startup.init<solrdocument> ("http://localhost:8983/solr/test");2 varSOLR = servicelocator.current.getinstance<isolroperations<solrdocument>>();3 varDoc =NewSolrdocument () {id="Key1", title="TT1"};4 SOLR. ADD (DOC);5Solr.commit ();
Iv. solrnetEnquiry
querying data using SOLR :
1 varSOLR = servicelocator.current.getinstance<isolroperations<solrdocument>>();2Queryoptions options =Newqueryoptions ();3Options. Rows =Ten;//number of results obtained4Options. Start =0;//the starting position of the result, for pagination5Ilist<isolrquery> qlist =NewList<isolrquery>();6 varQfied =NewSolrquerybyfield ("Title","TT1");7 varQkey =NewSolrquerybyfield ("Id","Key1");8 qlist. ADD (qfied);9 qlist. ADD (Qkey);Ten varQS =NewSolrmultiplecriteriaquery (Qlist,"or");//Enquirythe relationship between conditions One varRes2 = Solr. Query (qs,options);
Fuzzy query: Using wildcard characters to implement
var res1 = Solr. Query (New Solrquery ("title:*a1*"), options);
Summarize
Here is a brief introduction to the process of using. NET client solrnet to manipulate SOLR. I hope to let the friends who have not contacted have a general concept of the application of SOLR.
Using SOLR to improve search efficiency in. NET (Getting started)