SOLR incremental index, solr incremental

Source: Internet
Author: User

SOLR incremental index, solr incremental

Yesterday I wrote about SOLR service deployment and full index creation. Today I will continue to talk about the SOLR incremental index problem. What is incremental index? Instead of indexing all the data in the database, you only need to create an index for the changed data during the last index creation to the current time, the index created last time does not change. The object for creating an incremental index includes the newly added or modified or falsely deleted data in the database during this period. Next, we will first create an incremental index for the added or modified data;

First, there is a dataimport. properties file in my F: \ SOLR_HOME \ collection1 \ conf folder. Open this file and you can see the following information:

Here we can see the last_index_time attribute, which is displayed at 03:27:23 yesterday afternoon. That is to say, the last time I created the index was 15 \: 27 \: 23. Remember this time first, let's take a look at the database data:

The table data was created yesterday afternoon, so how can I configure it to allow you to add data to the database, the data is automatically added to your index instead of re-indexing all the data in the database? The following is the time to witness the miracle.

I. Add a timestamp field to the database table

Add the UpdateTime field to the database table. Of course, this name can be used at will without any impact. The type of this field is timestamp. You can give a default value of CURRENT_TIMESTAMP (this is MYSQL's, ORACLE may need to be changed. I am not familiar with ORACLE, so you know ).

2. Modify the data-config.xml File

  

To add the field you added to the database to the middle of the corresponding <entity> </entity>. Add two statements under the query statement, which areDeltaImportQueryAndDeltaQueryThese two statements exist specifically for incremental indexes, and are familiar with last_index_time in the deltaQuery statement. This is the data in dataimport. properties that we will see at the beginning. The deltaQuery statement isQuery the data that changes in the database after the last index is created.(Of course, the deletion is not included here.About the deletion, I will talk about it next time. This demo is not done, so I will talk about it in the next article)IDNote that the deltaImportQuery statement returns only the ID of the changed data. The deltaImportQuery statement queries all the content of these records based on the ID returned by the deltaQuery statement. Note that deltaImportQuery = "select * from tuser whereUserID= '$ {Dih. delta.UserID} '", You must note that when I first started writing, I did not pay attention to writing it casually. Later I found the problem after looking for a long time.

3. Modify the schema. xml file

  

Also add the field to the schame. xml file, note that the name should correspond to the data-config.xml.

4. Confirm the JAR File

Yesterday when doing full index has put these two jar files into the D: \ apache-tomcat-7.0.63 \ webapps \ solr \ WEB-INF \ lib folder, importing data to these two jar files is essential. Wait for another jar file to be added during scheduled incremental import.

5. add data to the database

Next I will add several new data entries to the database, as shown below:

A total of three pieces of data were added. to distinguish the ancients above, I added three modern people. Let's take a look.

6. start Tomcat and access the solr page

After tomcat is started, access localhost: 8080/solr, go to collection1, and click Dataimport To Go To The following page:

This page is used for data import, but I still need to go to the Query page and check the number of current indexes to distinguish our incremental indexes, here is a bit of a headache. I have configured a regular incremental index in my example. The time is still one minute. I wrote some text here And I updated it over there, I stopped tomcat and changed the scheduled time so I had to try again. Let's take a look at the current index:

After adding data to the database, I have 15 data records, and now there are also 15 indexes, which correspond to each other. Next I will re-add several data records to the database and re-create the incremental index:

I added my brother and Chao Wei to the database. Now there are 17 data records. Go to the solr page, click Dataimport, and select delta-import in command, as shown below:

Click the checkpoint in front of the following clean statement. Otherwise, the created index is clearly displayed. Then, click the Execute button. After the execution is complete, it is shown as follows:

Go to the Query page to Query:

It can be found that the index data has changed to 17 items, which means that our incremental index is good. Some people will say that the number of your Indexes has changed. But who knows that you have added the index to me? OK. Let's query the index of the brother. The query method is as follows:

Did my brother send me out? Of course someone said again, you sent your brother out, but is there another Stephen Chow? He also changed his name to Zhou runfa .. This is a problem with solr word divider. The solr word divider has limited support for Chinese characters, today, I am also suffering from this tokenizer. Let's talk about the tokenizer in detail. Now I don't have to configure the tokenizer myself, you can check the following page to find out what the situation is:

Solr's word divider divides Zhou runfa into three words: "Week", "run", and "send, during the index query, all the content containing the three words will be checked out. During the index query and sending, xingye will also be able to get the content. This is not my experience.

I wanted to write the timed incremental index, but I still have to go to EasyUI's tutorial. So I will write it again tomorrow. I will also write the deleted incremental index along with the timing, as well as the word divider, it should be the three items. The day after tomorrow, I may write solrJ to operate the index, which is CRUD. This is what I will do for the time being. By the way, there is also a multicore, however, I have not provided an example for the moment. I will give an example first. If you can write it for everyone, I will use it later.

Well, for the time being, you are welcome to correct anything you have said wrong.

 

 

 

  

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.