aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Search in Action: What do you mean by Search exactly? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Search in Action: What do you mean by Search exactly?" Watch "Hibernate Search in Action: What do you mean by Search exactly?" New topic
Author

Hibernate Search in Action: What do you mean by Search exactly?

Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Hello Emmanuel and John,

I recently had a Problem with Hibernate HQL Delete.

When I look at your book title Hibernate Search in Action the term Search seems to be the focus of your book .

Can I substitute Search with Select?

What about the data manipulation stuff delete, update and insert?

Regards,
Darya


SCJP, SCJD, SCWCD, SCBCD
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Can I substitute Search with Select?

No.

Search refers to "free text" search. Lucene developers will not thank me for using this term because they are not directly comparable but think of it as a google like search.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
But then, what makes Hibernate in between ?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not sure what you mean. Hibernate still exists in the application. Hibernate Search is an extension of this functionality, not a replacement for it.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Originally posted by Paul Sturrock:
Hibernate Search is an extension of this functionality, not a replacement for it.


Which functionality do you mean .
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Hibernate's ORM functionality.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
I only know the classical core Hibernate. Do you think that data manipulation like delete, update and insert play a role for Hibernate Search?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Darya Akbari:
I only know the classical core Hibernate. Do you think that data manipulation like delete, update and insert play a role for Hibernate Search?


No, they remain a part of the core of Hibernate. Hibernate Search adds an integration with Lucene to allow "free text" searching capabilities. You don't use Hibernate Search for CRUD operations - you do those with Hibernate.

Some background: What is the difference between a "free text" search and a SQL/HQL select? A select statements searches one mapped entity based on known properties using well defined rules. For example consider the following HQL:

This searches for all foo objects whose name contains the characters 'blah'.

In an information retrieval system like Lucene you don't need to define that your search is only against foo objects, it could be against anything that is contained in an index. So I could index every table in my database in one index. I also don't need to define that I am only searching against the name field, I can search accross all indexed fields.

So why use select statements at all given information retrieval systems like Lucene exist? One reason is the overhead of indexing. If you let Hibernate index as it goes thats an bunch of extra work to do every time I perform a CUD operation. This overhead (and other considerations) also mean the indices can (in fact, probably will) be out of date. Hibernate Search in a clustered environment for example uses JMS to trigger index writes. A last possibility is the need to limit what the user can see. A simple use case could be selecting all foo objects created by me. "free text" searching is often too free.

So, Hibernate Search is just about free text search. When it comes to normal CRUD operations, it is Hibernate itself that you would use.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Thanks Paul.
Emmanuel Bernard
author
Ranch Hand

Joined: Oct 22, 2008
Posts: 62
To complement or reword Paul's posts.
Hibernate Search provides full-text search for Hibernate application.
It's very easy to change a HQL query with a full-text query, the programmatic model remains the same (same Query API, same managed objects returns that handle lazy loading etc)

Full-text search is primary useful to create an efficient user focused search engine. Let's say you do a DVDStore, writing a search engine that can find DVDs and Actors while handling search for multiple words ('luke R2D2' => returns the starwars trilogy), work around word typos (Zolander returns Zoolander), recognize synonyms (love, like etc are somewhat synonyms), search by work family (compute, computing, computerized etc are all related to the same idea).
If you try do to that in HQL (and SQL) you will end up with tons of problems (either unsolvable or triggering very slow queries). Full-text search provide a very efficient solution to all these problems.

Note that full-text search can solve other problems but Human focused queries are the main focus.
Darya Akbari
Ranch Hand

Joined: Aug 21, 2004
Posts: 1855
Thanks for the explanation Emmanuel. Based on your both description I start thinking to use it in our application .
Emmanuel Bernard
author
Ranch Hand

Joined: Oct 22, 2008
Posts: 62
Ram kovis
Ranch Hand

Joined: Jun 23, 2005
Posts: 130
Thanks Darya for asking question. I was about to google for it..
Thanks Paul,Emmanuel..

Nice feature.. Need to try this out this weekend..
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

In an information retrieval system like Lucene you don't need to define that your search is only against foo objects, it could be against anything that is contained in an index. So I could index every table in my database in one index. I also don't need to define that I am only searching against the name field, I can search accross all indexed fields.


How do you define an index ? Is it same as db index?


Groovy
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

No, but its a simmilar concept. An index in either is an organised structure to use to lookup data.
Emmanuel Bernard
author
Ranch Hand

Joined: Oct 22, 2008
Posts: 62
In practice, most of the time the Lucene index structure is store in a file system directory as opposed to the database.
Ram kovis
Ranch Hand

Joined: Jun 23, 2005
Posts: 130
Oh.. How do they work together? DB might have index on EmployeeNumber, whereas Lucene has on Emp.Name. which one takes precedence during the actual query?
Emmanuel Bernard
author
Ranch Hand

Joined: Oct 22, 2008
Posts: 62
Ram,
The database and the Lucene index are kept synchronized by Hibernate Search. Every time the database changes via Hibernate Core, the index is updated as well.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Can I say that google search is free text search?
John Griffin
author
Greenhorn

Joined: Oct 24, 2008
Posts: 22
Prad,

Yes, it is. Whereas Google is designed to search for text in Internet documents, Hibernate Search functions in a very similar manner on database fields.

Hope this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Search in Action: What do you mean by Search exactly?