I am still a newbie in Solr, and writing these articles is just to record my experience in learning Solr in the recent period.
What is Solr?
When I was learning Solr recently, I kept seeing a sentence that Solr is an out-of-the-box search server based on Lucene that can be used by enterprises. I thought about it for a long time but didn't understand what this sentence meant. What is a search server? After getting in touch with it, I discovered that the so-called search server is a project of a search program that can run in the server (Tomcat, Jetty).
What can Solr do?
Anyone who knows Lucene knows that Lucene does two things, index management and search, and Solr is no exception. It does the same two things, but makes it simpler.
If you don’t know much about Lucene, I recommend reading Juexian’s blog: http://www.cnblogs.com/forfuture1978/category/300665.html. This blog was very helpful when I first came into contact with full-text search. In addition, I recommend a book, the English version of Lucene In Action, and the Chinese version of Lucene in Action.
Now, let’s get to the point. Since Solr is a search server, of course we need it to be managed in our Eclipse. Let me write down some of my experiences.
Running Solr in Eclipse
1. Download the complete package of Solr, I use Solr 3.6.1;
2. Create a new Dynamic Web project in Eclipse. My name is solr. You can do the same. If it is different, just pay attention when you visit.
3. Delete all the contents under WebContent in the new project, decompress apache-solr-3.6.1.war in the dist directory in the downloaded Solr complete package, and copy all the contents inside to WebContent. After the copy is completed, If there is a red cross, ignore it and pretend you don’t see it.
4. Specify solrHome. solrHome is where solr core configuration files and indexes are stored.
Open the WEB-INF/web.xml file and add the following nodes:
Copy the code code as follows:
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>E:/solr</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
The env-entry-name must be solr/home, and the env-entry-value node is where you want to place the solr configuration file.
5. Add solr configuration file <BR>There are two methods, create it yourself or copy and download the core configuration file in the complete package.
The first method: Copy, enter the example/mutiCore directory in the download package, you can see core1, core2, copy this folder and the following solr.xml file to solrHome.
The second method: (1). Create a new one, enter solrHome, create a new solr.xml file, and configure it as follows:
Copy the code code as follows:
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
<cores adminPath="/admin/cores">
<core name="merchant" instanceDir="merchant" />
</cores>
</solr>
The adminPath file is as shown in the code. It is best not to change it. The name in the core is arbitrary, and it is best to have a certain practical meaning. instanceDir, here specifies the directory of the core, and here the merchant is configured, which means solrHome. The merchant directory under.
Let's explain the multi-core configuration here. In the example here, I only store one core because our product only needs to perform full-text search on one merchant. If necessary, for example, if you need to retrieve coupon and other files, you need to configure multiple cores. Multi-core examples are given in the example/muticore folder, you can refer to them.
(2). Create a new merchant directory (consistent with the instanceDir in the configuration), then create a new conf directory under the merchant, and create two xml files in conf, namely schema.xml and solrconfig.xml. The configurations of these two xml will be I will describe it in detail in the next blog. If you don’t know how to configure it, just copy the two files in example/muticore/core1/conf.
6. Start solr in Eclipse Create a new server in the servers window, and then add the newly created project into it;
Modify the port, double-click the newly created server, and modify the HTTP/1.1 port in the port to 8983. It can be customized here. It is best not to duplicate it with your other projects. Then save;
Start the server.
7. Open the solr management panel in the browser <BR>Open the following address, http://localhost:8983/solr/, and then you can see the Admin merchant option. Click to enter, which is the management of the merchant core you just configured. panel.