Compass-What enhancements have been made on Lucene?

Source: Internet
Author: User
Original post address:
Added Opensymphony Of Compass Yes Lucene Search Engine Enhancements in enterprise applications (database applications. Lucene's API is very simple. Let's take a look at Beef up Web Search apps with Lucene I have probably understood what kind of enhancement can compass do?

1. In my project, the most practical enhancement is the data mirror function.

Datamirror maps the addition, deletion, and modification of the database to the index file in real time. If you use an ORM scheme such as Hibernate, you only need to annotate annotation in pojo, and compass will be combined with the hibernate event mechanism or use the AOP method, the index is automatically changed when the database is added, deleted, or modified. If you only use JDBC, you can also configure table mapping or resultset mapping in the XML file, specify the version column, and perform regular Index Update on compasss. In addition, compass supports transactions. If an exception occurs during database traversal, transaction control is performed at the index segments file level.

Without compass, we usually re-create an index every night. Compared with compass,
One slow response with an average latency of half a day;
Second, the efficiency is not as high as compass. If the index is completely re-built, the efficiency is not required. If you perform an incremental index, you need to add a field to perform special processing during data updates. data cannot be deleted directly after Lucene deletes the index, in this way, Lucene is very opaque to the application.
Transactions are not supported. If an exception occurs during index creation, the status of the index file is uncontrollable.

2. Compass also simplifies the query API and can be used in consideration.

For details, seeRefer to 10.5 searching, Simple and direct use of session find, such

Compasshits hits=Session. Find ("Name: Jack");

Add sorting, change word segmentation analyzer, and use querybuilder ()

Compasshits hits= Session. createquerybuilder ()
. Querystring ("+ Name: Jack + familyname: London" )
. Setanalyzer ("An1")//Use a different Analyzer
. Toquery ()
. Addsort ("Familyname" , Compassquery. sortpropertytype. String)
. Hits ();

3. For other compass functions, You need to view the fate of the unused features: 

Put the Lucene index file into the database or memory.
The index files are separated by subindex based on different topics.
Map and index XML data ....

4. A Pragmatic Compass searchProgramIt is written as follows:

1. Use annotation to map pojo to searchable. (For more information, see references.If JDK 5 is not available, referXml configuration)

Public Class Product {
@ Searchableid
 Private Integer ID;
 Private String name;
@ Searchableproperty (name= "Name" )
Public String getname (){
Return This . Name;
}
}

2. UseSpring2 schema provided by compassTo configure the combination of compass, hibernate, and spring.
Configuration of schemabaseSet as a new feature of spring 2.0, compared with the original configurationCodeLess.

3. Compile the search result display page and display the hits, command, and page variables.
The code reuse of compass has reached the Controller level. You only need to configure the controller with the compass bean and the Result Display JSP. The Controller provides sufficient configuration parameters so that they can be completely reused. This is a learning point for springside.
Even if your web application does not adopt spring MVC, you can directly use it without large-scale rewriting, so that struts and spring MVC coexist.

 5. When the default query of controller needs to be extended

By default, contrller queries keywords in all fileld queries. If you need to limit the field, add sorting, add and, exclude, fuzzy query, and so on, it does not apply. The advanced search page generally provides a large number of filter condition input boxes for users to enter, and then re-combine these input conditions in the controller.

The combination method can be eitherLucene query syntaxCombine the SQL statements and get the sentence "+ name: Jack-familyname: London.

You can also use a method similar to the hibernate criteria API, for example:

Compasshits hits= Session. createquerybuilder (). bool ()
. Addmust (querybuilder. term ("Name","Jack" ))
. Addmustnot (querybuilder. term ("Familyname","London" ))
. Toquery (). Hits ();

Therefore, if your Lucene application is database-oriented, use compass.
Another thing I learned about compass is that it fully considers the needs of user customization. Enough thing can be configure, so that even the controller can be reused.

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.