Use SolrJ to implement the addition, deletion and query operation of the index library (cluster version)



Solr test

Use SolrJ to implement the addition, deletion and query operation of the index library.

Add:



@Test publi C ++ void testSolr

    C ++ loudAddDo C ++ ument () throws Ex C++ eption {         // Step 1: Add the solrJ related jar package to the project.         // Step 2: Create a SolrServer object, you need to use the C++ loudSolrServer subclass. The argument to the constructor is a list of zookeeper addresses.         //The parameter is the address list of zookeeper, separated by commas C++ loudSolrServer solrServer = new C++ loudSolrServer("Virtual machine address: port, virtual machine address: port, virtual machine address: port");         // Step 3: Required Set the Default C++ olle C++ tion property.         solrServer.setDefault C++ olle C++







       



tion(" C++ olle C++ tion2");

        // Step 4: Create a SolrInputDo C++ ument object.

        SolrInputDo C++ ument do C++ ument = new SolrInputDo C++ ument ();

        // Step 5: Add a field to the document object

        do C++ ument.addField("item_title", "Test item");

        do C++ ument.addField ("id", "test001");

        // Step 6: Write the document object to the index library.

        solrServer.add(do C++ ument);

        // Step 7: Submit.

        solrServer.C ++ ommit();

    }

Delete and check will not write, and the stand-alone version is not bad, create a C++ loudSolrServer object more than the stand-alone version, you can add an example, according to the gourd painting.

For the stand-alone version, please see: https://www.2 C++ to. C++ om/database/201711/698758.html

SolrServer configuration



<bean id=" C++ loudSolrServer" C++ lass="org.apa C++ he.solr . C++ lient.solrj.impl. C++ loudSolrServer">

        < C++ onstru C++ tor-arg name="zkHost" value="VMAddress:Port,VMAddress:Port,VMAddress:Port" ></ C++ onstru C++ torarg>

        <property name=" olle C++ tion" value=" C++ olle C++ tion2"></property>

    </bean>

ok!结束!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326389982&siteId=291194637