Solved

Keyword Search in J2EE

Posted on 2001-06-23
4
266 Views
Last Modified: 2013-11-24
I'm looking for some guidelines/best practices for implementing a keyword search for products in J2EE.  I've referred to the Java Pet Store example, but unfortunately, the search they implemented is not designed according to the J2EE Blueprints (they even admit it in the comments).

Do I...
 1. Implement the search as an entity bean with a "findByKeywordSearch()" finder?  (I've done this and it works, but I'm not convinced that it's the best way).
 2. Implement the search as a stateless session bean returning value objects representing the results of the search?
 3. Implement the search the way that the JPS did and just settle with it being out of whack with the Blueprints?
 4. Some other way?

The points go to the person who provides the best solution with the best justification for their solution.  Special consideration given to solutions that come with references to articles and/or books that back up the solution.

0
Comment
Question by:mwalls
4 Comments
 
LVL 6

Accepted Solution

by:
jpk041897 earned 300 total points
Comment Utility
Actualy, I don't think there is "best way" to perform a keyword search. At least not something that coud be made into a pattern. There are just to many variables.

First of, it depends on what DB engiene your running it on and what sort of packages/plugins it has. For instance, Oracle comes with the Contex cartidge which contains an API that helps locate records in text fieds or indexes in a quick and eficient manner. If such a tool is available in your DB, then a BMP Entity bean could be your best bet.

Additionaly, DB caching availability in you app. server might also influence your desition.

Another factor would be just how complex a search language you want to define. If your only foing to allow AND  operations then a CMP entity bean could work out just fine but if you are going to allow complex expretions with combinations of AND,OR and NOT; you would end up requiring both a session and an entity bean.

The type of sesion bean would depend on weather you want to support multiple subset retrieval of the result set or a single dump.

All these reasons (and probably some I haven't though of) probaby influenced the fact that the Finf in the JPS does not comnform to Blueprint specs.

Looking at your specifiv questions:

 1. Implement the search as an entity bean with a "findByKeywordSearch()" finder?  (I've done this and
it works, but I'm not convinced that it's the best way).

Its not necesarily the best way, no. It depends on how you have designed your DB. If you have an index set for each keyword then it could be (and at least for your app probably is) good enough.

On the other hand, for a very large set of data, the overhead caused by CMP entity beans could prove to be to expensive.


2. Implement the search as a stateless session bean returning value objects representing the results
of the search?

This option is certanly more flexible, and could work out prey well if using specialized tools such as ConTex. Of course, it breaks up the specs prety badly and does not support multiple result set subset retrieval.

Personaly, I would avoid this solution.

3. Implement the search the way that the JPS did and just settle with it being out of whack with the
Blueprints?

This is probably a good bet (though I would not go about it in the manner that Sun wrote it). Suns solution works, but was written wit "works" in mind, not as an efficient solution.

4. Some other way?

If I were writing it, IMO I would go with a statefull session bean (called by a mechanism that could limit the staefulnes to, say a page context, such as a JSP or servlet). This bean would make calls to one or more CMP entity beans (One for each clasification of keyword) that return index enumerations. Once I had these, I would implement the complex query logic using a parser.

I would make the Entity bean(s) CMP to allow for portabity (even at the expense of efitiancy) but that probably stems from the fact that I'm lazy and prefer code resusabiliy.

Once I had the list of valid indices, I would make the actual retrievel from the DB (set up a getter method that would allow for multiple subset retrievel based on nuber of requested records). Just exactly how such a getter could be made more effitient would again depend on the specific DB being used since many DB's don't support subset retrievel in their SQL etentions.


I don't have any actual refs. or links but you might want to have a look at page 255 of Mastering Enterprise Java Beans by Ed Roman, which you can download from:

http://theserverside.com/home/index.jsp


The book is a bit dated (covering th EJB 1.1 spec) but still prety good.


Hope this helps.
0
 

Author Comment

by:mwalls
Comment Utility
I am using Oracle with ConText/interMedia.  However, the specifics of how I performed the search (whether by using interMedia or by some other mechanism such as LIKE) I was going to abstract away in a DAO.

The big question for me was:  Who's going to use that DAO?  In my current prototype I have a BMP Entity Bean using the DAO in a findByKeywordSearch() finder.  It works fine, although I'm somewhat concerned (probably over-concerned) about the efficiency of entity beans, especially for what could potentially be a large result set.

My next thought was a stateless session bean.  A cursory glance at the pet store code showed that they implemented a search function as part of a stateless session bean.  Oddly enough, when I did a more detailed investigation of their code I discovered that they didn't use that session bean anywhere.

Instead, the actual search is done in a plain-vanilla JavaBean that has application scope.  (Note:  The stateless session bean above extends this JavaBean, exposing the searchProducts() method in its remote interface.)

So that's where I became confused.

(jpk)Your feedback is good.  So far you are easily the leading contender for the points.  However, I'm going to wait it out until this weekend to see if I get any other valuable info.  The problem with this type of question is that it there isn't a right or wrong answer...only a best answer...therefore I don't want to give the points away until I've given ample opportunity to find the best answer.
0
 
LVL 5

Expert Comment

by:vemul
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- points to jpk

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

vemul
Cleanup Volunteer
0
 

Expert Comment

by:modulo
Comment Utility
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now