Use the domain model (domain object) to index, search

Source: Internet
Author: User
Tags config in domain

For the domain object mapping to relational databases, hibernate and other persistence frameworks do a lot of work, so that the business logic only needs to interact with the persistence layer such as hibernate, without the need to interact directly with the specific database.

This gives programmers a lot of convenience in business logic processing, as long as the domain object can be.

When using Lucene for indexing and search development, the most frequently encountered concept is document and field, and one of the things you have to do in a program is to map the properties of a domain object to the field of document, and when searching, You also build DTOs (Data Transfor object) based on the document and field to return to the Web layer. This is similar to one of the drawbacks of EJB, which cannot be returned to the Web layer as an entity bean, but as a dto that encapsulates the entity bean.

What we want is the convenience of a technology like Pojo, which is persisted in domain object, and is also domain object returned to the Web layer.

When we index and search domain object, we also want to be able to operate directly on the domain object level, rather than dealing directly with document and field. And we can do that with the compass framework.

Compass uses the Lucene search engine framework, which provides a set of Open-source, high-performance, flexible search frameworks that provide search capabilities for users ' applications. It can also be integrated with existing frameworks such as spring and hibernate.

COMAPSS's API structure is very similar to hibernate, and if a hibernate programmer uses Comapass, the API is basically handy.

Let's take a look at an example

compassconfiguration config = new compassconfiguration (). Configure ();
Compass Compass = Config.buildcomapss ();
Compasssession session = Compass.opensession ();
Compasstransaction tx = NULL;
Try
{
tx = Session.begintransaction ();
Book book = new book ();
Book.setname ("C + + programming Idea");
Book.setauthor ("Bruce Eckel");
Session.save (book);
Tx.commit ();
}  catch (Exception e)
{
if (tx!=null)
{
tx.rollback ();
}
}finally
{
session.close ();
}

Hiberanete programmer should be very familiar with the above code, compass completely let you away from the Lucene API, so that your code more focused on business logic, and the index and search for the matter to the Compass bar. This also brings an advantage, that is, the use of compass is very easy to the existing system to add search capabilities.

So how to let domain object is compass use, of course, and hibernate like, as long as the completion of some Domai object configuration file can be, specific can read compass with example.

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.