Advanced Search Using Hibernate Search

In one of my applications, I am to execute a search on multiple fields/columns. Its an Advanced Search and there are over 20 fields using which a user can search for results. For example, a user can search for bookings based on

  • Booking Id
  • Passenger Name
  • Passenger Age
  • From Location
  • To Location
  • Booking Status
  • Name of the Airline
  • and 13 such fields.

    I am trying to figure out if

  • Hibernate Search can and should be used here? If so, how? I was unable to find an example for such a complex search using Hibernate Search.

  • Instead of Hibernate search, I can simply use Hibernate and maybe design a multi-threaded search depending in the number of parameters. Would that be a good idea?

  • Is it possible to use Hibernate Filters here?

  • Can someone please provide inputs or reference links?


    For these kinds of queries, I generally use a Criteria query with a form object. I then check for null in each passed form field, and if not null , then add another Restriction into the query, using that field. Using a Criteria query keeps the Java code very clean and eliminates messy string concatenation. An example for your case:

    // Form object
    public class bookingSearchForm {
        private String bookingId;
        public getBookingId()...
        public setBookingId()...
    }
    
    // Hibernate
    Criteria criteria = getSession().createCriteria(Booking.class);
    if(form.getBookingId() != null) {
        criteria.add(Restrictions.eq("bookingId", form.getBookingId()));
    }
    criteria.list();
    

    I think your decision should be based on the requirement for capacity. Ordinary Hibernate query might be sufficient for searching on those many fields.

    Hibernate Search will help if you want to get the search query fast for large amount of data, using reverse index. What you should do is to load your database with the capacity you expect in the next 5 years for example. If your ordinary Hibernate query is considered acceptable I think you should stick with ordinary Hibernate query.

    You can introduce the Hibernate Search in later stage as well.

    EDIT: You may opt not to use Hibernte Search, go down to the lower level and use Apache Lucene instead. You can generate your own Apache Lucene index. This way you don't have to worry about which field in order to find records because you will have full control on how the tokenizing and indexing process. You can store the row and column name as part of the search result if you choose this way.


    Yes, Hibernate Search is going to be very useful in such a case. You can use filters, but Hibernate Search has filters as well.

    链接地址: http://www.djcxy.com/p/59138.html

    上一篇: 在PHP 5.3.0中,“use”标识符的功能是什么?

    下一篇: 高级搜索使用Hibernate搜索