?
Solved

Keyword Search in J2EE

Posted on 2001-06-23
4
Medium Priority
?
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 6

Accepted Solution

by:
jpk041897 earned 1200 total points
ID: 6222321
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
ID: 6225316
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
ID: 7620922
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
ID: 7643006
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

649 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