This article is a companion article about Apache SOLR. I will analyze each package of Apache SOLR one by one, and try to analyze the SOLR design and architecture in detail. Apache SOLR consists of 12 packages:
- Org. Apache. SOLR. Analysis
- Org. Apache. SOLR. Core
- Org. Apache. SOLR. Request
- Org. Apache. SOLR. Schema
- Org. Apache. SOLR. Search
- Org. Apache. SOLR. Search. Function
- Org. Apache. SOLR. servlet
- Org. Apache. SOLR. TST
- Org. Apache. SOLR. Update
- Org. Apache. SOLR. util
- Org. Apache. SOLR. util. Test
- Org.apache.solr.util.xls t
Apache SOLR is still in development, and the current version is 1.1.0. There are very few annotations in the document. From the user's point of view, the first thing we can see is servlet, because SOLR itself is an independent network application and needs to be run in the servlet container to provide services, therefore, servlet is the outermost layer exposed to users.
Let's take a look at the org. Apache. SOLR. servlet package. This package is very simple and has only two classes: solrservlet and solrupdateservlet. We can easily guess the usage of these two classes from the class name.
The solrservlet class inherits the httpservlet class and has only four methods:
- Init ()
- Destroy ()
- Doget ()
- Dopost ()
In addition to common Java class objects (including servlet-related objects), solrservlet classes have four SOLR classes and a SOLR exception. Two of the classes and one exception belong to the org. Apache. SOLR. core package, and the two classes belong to the org. Apache. SOLR. Request package. Core packages include:
- Config:
- Solrcore:
The request packages include:
- Solrqueryresponse:
- Queryresponsewriter:
Analyze the solrservlet class.
First, Servlet will call the init () method for initialization: Use context to find Java: COMP/ENV/SOLR/home to determine the SOLR home directory (home), and then call config. setinstancedir (home) method to set the directory of this instance. Then, a solrcore instance is obtained through solrcore. getsolrcore.
The destroy () method is called when the servlet object is destroyed, and only the core. Close () method is called to close the solrcore instance.
When a user requests in, dopost () simply submits the task to doget () for completion, and the main task is completed by doget.
Analyze the doget () method:
- Use the solrcore and doget () parameters to generate a solrservletrequest object (Note: This solrservletrequest class is not a public class and is located at Org. apache. SOLR. the servlet package inherits the solrqueryrequestbase class and only accepts solrcore and httpservletrequest objects as parameters)
- Then solrcore executes the execute () method (the parameters are solrservletrequest and solrqueryresponse)
It can be seen that the true processing core is the solrcore execute method. In the next article, we will continue our analysis.