| OmniFind, Part II: Integrating OmniFind Text Search Server with DB2 Web Query |
|
|
|
| Database - DB2 | |||
| Written by Gene Cobb | |||
| Wednesday, 08 July 2009 01:00 | |||
|
Organize and secure your documents, and create a GUI to perform text searches on them.
In my previous article "OmniFind, Part I: Add Sizzle to Your SQL with OmniFind Text Search Server for DB2 for i," I introduced IBM OmniFind Text Search Server for DB2 for i , a new IBM i 6.1 product that provides the ability to perform both basic and sophisticated text searching against your DB2 for i data. In this article, I show you how to integrate this exciting new product with DB2 Web Query, the strategic IBM i query and reporting tool.
To recap Part I, the OmniFind Text Search Server supports the searching of a DB2 row based on text contained in either a database column or a document (a PDF file or XML document, for example) that is stored in a database column with a data type such as Large Object Binary (LOB). It provides two new integrated SQL functions (SCORE and CONTAINS) that you can use in your SQL statements to specify and execute text-based searches.
For example, let's say you have a DB2 for i table called INVENTORY that contains information about the all products you sell. Columns in the table include product_number, product_category, and product_name. In addition, for each product, you also have a PDF file stored in a LOB column named tech_spec_doc. Each PDF file contains all of the technical specification information for that particular product. Now, let's say that you have a requirement to find all products containing the string "headphones" in the PDF document. The "OmniFind infused" SQL statement would look something like this:
SELECT product_number, product_name FROM inventory WHERE CONTAINS(tech_spec_doc, 'headphones') = 1
This statement would return all PDF documents stored in column tech_spec_doc that contain the word "headphones."
While this is certainly cool stuff, you may have noticed that it lacks a graphical interface to perform these searches and actually open one of the matching documents. Well, that's where the IBM DB2 Web Query for i product comes in. DB2 Web Query pairs well with OmniFind because it provides the graphical interface needed to collect the search criteria from the end user and display results of the OmniFind search. While there currently is not native support for OmniFind within DB2 Web Query (meaning it does not generate the OmniFind-specific syntax in the SQL statement it submits to the database engine), marrying the two technologies together can be accomplished by using stored procedures. Behold the Stored Procedure!A stored procedure is really just a program object that is registered to the database. It can be written in the SQL procedural language or any supported IBM i language, such as RPG, COBOL, C, or Java. You can use it to execute customized business logic and return a result set to the caller or the client application.
When it comes to DB2 Web Query data sources to base their reports on, many developers only use database objects like tables and views. But a very powerful, yet underutilized feature of DB2 Web Query is its ability to use a stored procedure as a data source, provided the stored procedure returns a result set. When a DB2 Web Query synonym is created over a stored procedure, the result set is used as the format for the synonym. This means that all fields in the result set can be used as columns in the report. In addition, the input parameters of the stored procedures can be used as input parameters for the report. Consequently, you can pass parameter values from a report to the stored procedure, let the procedure use those values to perform the business logic, and return the results to the report.
Why is this such a powerful feature? Because it gives the developer the programmatic control during the execution of the query and, consequently, the ability to do many things, one of which is to call the functions necessary to interface with the OmniFind Text Search Server. For this particular kind of implementation, the stored procedure's job is simple: accept the search criteria as an input parameter, generate the SQL statement with the correct OmniFind function syntax, execute that statement, and return the results as an SQL result set. The result set returned from the stored procedure is received by DB2 Web Query and can be used as the data source for a report.
To best illustrate how everything works together, let's continue with the example that was started in the previous article. In that example, we performed the following tasks:
To extend this example and integrate it into DB2 Web Query, we will take these additional steps:
Step 1: Creating the Stored ProcedureAs previously mentioned, stored procedures can be written in any supported IBM i programming language. For our example stored procedure, we will use an RPGLE program with embedded SQL. The source code for this stored procedure is shown below:
This program does several things for OmniFind integration:
To create this program, issue the following command:
CRTSQLRPGI OBJ(MYLIBRARY/OMF_INV_SP)COMMIT(*NONE)
Once the program has been created, the next step is to register it to the database as a stored procedure. You do this by using either an SQL interface (such as the STRSQL command) or the Run SQL Scripts window in System i Navigator and specifying the following SQL statement:
CREATE PROCEDURE MYLIBRARY.OMF_INVENTORY_SP ( IN SEARCHSTRING CHAR(128) ) LANGUAGE RPGLE NOT DETERMINISTIC READS SQL DATA CALLED ON NULL INPUT EXTERNAL NAME 'MYLIBRARY/OMF_INV_SP' PARAMETER STYLE GENERAL ;
To test the stored procedure, simply call it from the Run SQL Scripts window interface in System i Navigator and specify your search string as the input parameter:
CALL OMF_INVENTORY('Stereo') Step 2: Creating a New Synonym Based on a Stored ProcedureNow that you have a stored procedure that is successfully returning a result set based on OmniFind search syntax, you are ready use it in a DB2 Web Query report. The first thing you must do for any DB2 Web Query report is create a synonym over the data source. As mentioned, a stored procedure is a valid data source. To define the stored procedure synonym, take the following steps:
You have successfully created a synonym for the stored procedure. On to the next step! Step 3: Creating a Report Based on the Stored Procedure SynonymWith the stored procedure synonym in place, you are now ready to create a new report.
The Report Assistant tool is presented. You see a list of all of the columns of the stored procedure result set as well the stored procedure's input parameter (Figure 8).
Figure 8: Your Report Assistant tool looks like this.
When you're finished, the Field Selection tab of your report should look something like Figure 11:
Next, you need to define one input parameter: the search string that the user will specify and that the report will pass to the stored procedure.
Figure 12: Select your criteria.
Figure 13: Run your stereo report!
Step 4: Implementing a URL Drill-DownYou may be perfectly satisfied with this report and be tempted to declare it finished. But one of your users will ultimately ask if the matching documents can be opened directly from the DB2 Web Query report. You may already know that DB2 Web Query has the ability to link to another Web application through the browser. This is known as "URL drill-down," and you can use this technique to similarly drill down into a document that is located on the IFS. If you have a network drive mapped to the IFS of the IBM i or have a file share set up for the IFS directory that contains the documents, you can open files on the IFS using a Web browser.
For example, let's say that you have a file share named MyDocs that points to the IFS path /home. If a PDF file named resume.pdf is stored in that directory, you can open this file from the browser by specifying the following URL:
\\ip_address\mydocs\resume.pdf
This is the naming format we will use to drill into the PDF documents from the report.
Setting Up a File Share
For this example, we are going to set up a file share using the System i Navigator.
Figure 15: Define your file share.
Creating a Defined Field for URL Drill-Down
The final step is to create a defined field and use it for the basis of a URL drill-down. This will allow the user to click on a column in the report and open the underlying document from within a DB2 Web Query browser session.
Figure 16: Create a defined field.
While we do not want to display the DRILLDOWN column in the report, it must be included so that it can be referenced in a drill-down definition. We can simply add it to the report but make it invisible.
For this report, we would like the product number column to be the "hotspot." That is, when the user hovers over that column, a hand appears, indicating that the user can click on that column to drill down and open the underlying document. This is done by defining a drill-down for the PROD_NUM column.
Figure 20: Run the stereo report.
Security ConsiderationsIf you have concerns about exposing sensitive data that is contained in your documents, consider this: DB2 Web Query users must log into the system to identify themselves. Consequently, when they run a report that uses a stored procedure synonym, the underlying program runs with that user's authority. If you have object-level security or row-level security (using SQL views), you will not be exposing sensitive data. Always remember that no DB2 for i interface (including DB2 Web Query) can circumvent object-level security.
If you are concerned about the risk of exposing sensitive data in the documents detached by the stored procedure, you could set up a more secure environment than the one provided in the example above. For example, you could create and secure an IFS directory for each individual DB2 Web Query user and have the stored procedure detach the documents into the current user's directory. For example, for user profile JSMITH, the stored procedure would detach all documents into the path /db2webquery/omnifind/jsmith/, and access to the path would be granted to just that profile. Other user profiles (unless they had *ALLOBJ authority) would not be able to access that directory to get at those detached documents.
You may have other ideas about how to design a secure environment. That's the beauty of utilizing a stored procedure data source: because you have programmatic control, you can implement whatever design you want! The Search Is Over...Hopefully, this two-part article has given you some ideas on how to use the OmniFind and DB2 Web Query products in ways that will dazzle your end users. You may not need all of the features that were covered, but if your IT shop needs one or more of the following...
...you can either develop your own application or use these techniques to deliver a solution that is easy to implement and provides the features you are searching for!
| |||
View all articles by this author
|
|||
| Last Updated on Monday, 06 July 2009 11:36 |

























