High-performance solr c # client easynet. SOLR

Source: Internet
Author: User

Easynet. SOLR (http://easynet.codeplex.com) is a SOLR (http://lucene.apache.org/solr) C # client developed by myself. It has the following features:

 

1. Support for SOLR 3.1 (not compatible with SOLR 1.4.x)

2. By default, SOLR's most efficient javabin protocol is supported.

3. The interface-based serialization and deserialization protocols are not reflected.

4. other protocols supported by SOLR, such as XML and JSON, can be easily extended based on the architecture.

 

The following is a basic example:

Indexing and retrieval of entity class used

Public Class Example
{
Public String ID {Get; set ;}
Public string name {Get; set ;}
}

Create Index
Serialization for implement serialization

Public class exampleobjectserializer: iobjectserializer <example>
{
Public ilist <solrinputdocument> serializer (ienumerable <example> objs)
{
Ilist <solrinputdocument> docs = new list <solrinputdocument> ();

Foreach (example OBJ in objs)
{
Solrinputdocument Doc = new solrinputdocument ();

Doc. Add ("ID", new solrinputfield ("ID", obj. ID ));
Doc. Add ("name", new solrinputfield ("name", obj. Name ));

Docs. Add (DOC );
}

Return docs;
}
}

Index

Icodecfactory codecfactory = new binarycodecfactory ();
Isolrconnection <namedlist> con = new solrconnection <namedlist> ("http: // localhost: 8088/SOLR ");
Iupdateoperationparametersconvert <namedlist> updateopparametersconvert = new binaryupdateoperationparametersconvert ();
Isolrresponseparser <namedlist, responseheader> responseheaderparser = new binaryresponseheaderparser ();
Isolrupdateoperations <namedlist> updateop = new solrupdateoperations <namedlist> (con, updateopparametersconvert );

Ilist <example> examples = new list <example> ();

Examples. Add (new example () {id = "16", name = "Terry" + datetime. Now. tolongtimestring ()});
Examples. Add (new example () {id = "18", name = "Terry" + datetime. Now. tolongtimestring ()});
Examples. Add (new example () {id = "17", name = "Terry" + datetime. Now. tolongtimestring ()});

Iobjectserializer <example> objectserializer = new exampleobjectserializer ();
Ilist <solrinputdocument> docs = objectserializer. serializer (examples );

Addoptions? Addoptions = new addoptions () {commitwithin = 10 };
Commitoptions? Commitoptions = new commitoptions () {waitflush = true, waitsearcher = true };
Optimizeoptions? Optimizeoptions = new optimizeoptions () {waitflush = true, waitsearcher = true };

Namedlist addres = updateop. Add (Docs, null, commitoptions, optimizeoptions );

Responseheader = responseheaderparser. Parser (addres );

Query
Implement implement deserialize in Reverse Sequence

Public class exampleobjectdeserialize: iobjectdeserialize <example>
{
Public ienumerable <example> deserialize (solrdocumentlist result)
{
Ilist <example> examples = new list <example> ();

Foreach (solrdocument doc in result)
{
Examples. Add (new example () {id = Doc ["ID"]. tostring (), name = Doc ["name"]. tostring ()});
}

Return examples;
}
}

Query

Isolrconnection con = new solrconnection ("http: // localhost: 8088/SOLR ");
Iobjectdeserialize <example> objectdeserialize = new exampleobjectdeserialize ();
Isolrresponseparser <namedlist, queryresults <example> qrp = new binaryqueryresultsparser <example> (objectdeserialize );
Isolrqueryoperations <namedlist> qop = new solrqueryoperations <namedlist> (CON );
Namevaluecollection Options = new namevaluecollection ();

Options. Add (commonparams. Start, "0 ");
Options. Add (commonparams. Rows, "10 ");

Namedlist res = qop. Query (solrquery. All, options );
Queryresults <example> exps = qrp. Parser (RES );

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.