What is the SolrJ

SolrJ is a Java client that accesses Solr service and provides the request method of index and search. SolrJ is usually embedded in the business system and operates Solr service through SolrJ API interface.

SolrJ main method

SolrJ related classes are included in the Solr source org. Apache. Solr. Client. SolrJ package, the package below mainly includes five key categories. SolrClient, SolrRequest, SolrQuery, SolrResponse, ResponseParser. Where the SolrClient class indicates that SolrClient is an abstraction of SolrClient. You can use SolrClient to perform the following operations with Solr Server.

add

Add an index document to Solr Server. To support object-oriented programming, SolrClient provides addBean methods that allow you to submit a Java object directly, Internally, SolrClient uses DocumentObjectBinder to convert Java objects to SolrInputDocument objects. To support bulk indexing of documents, you can also add a Document collection directly or add an object collection via the addBeans method.

commit

That is, explicitly submit an index hard submit request.

optimize

That is, explicitly asking Solr Server to perform an index optimization will trigger Solr’s index segment file merge. This operation is not recommended to be invoked too often.

rollback

Solr Server explicitly asks Solr Server to remove uncommitted index documents from the queue. This rollback is not like a relational database rollback. It does not guarantee a 100% rollback, because your last committed index document may be due to AutoCommit. A hard commit may occur automatically because the buffer is full, or because the interval between AutoCommit and the maximum number of cached index documents has reached a critical value, or because another SolrClient has explicitly committed the index. The index document has been written to hard disk. Rollback will not help.

deleteById &deleteByQuery

These methods are mainly used to initiate an index drop to Solr Server. DeleteById means to delete the index Document based on the Document primary key ID, which is the uniqueKey you configured in schema.xml. DeleteByQuery is used to delete multiple indexed documents according to Solr queries.

query & getById

This set of methods is mainly used to make a query request to Solr Server, where the getById method is a special query request based on the primary key ID of the index document, if your schema.xml is configured with uniqueKey.

ping

Use to make a ping request to check if Solr Server is still “alive” if you need to configure PingRequestHandler in solrconfig.xml.

    <! -- ping/healthcheck -->
    <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
        <lst name="invariants">
            <str name="q">solrpingquery</str>
        </lst>
        <lst name="defaults">
            <str name="echoParams">all</str>
        </lst>
        <! -- <str name="healthcheckFile">server-enabled.txt</str> -->
    </requestHandler>
Copy the code

request

Use to make an HTTP request to the specified Core or Collection of Solr Server.

Reference documentation

  • Client APIs