Sun Java logo     Previous      Contents      Index      Next     

Sun logo
Sun Java System Portal Server 6 2004Q2 Developer's Guide 

Chapter 24
Example of Submitting a Query

This chapter contains the following sections:


Introduction

To send the RDMHeader and RDMQuery objects to the search engine to perform a query request, you can use the pre-built sendrdm program (located in portal-server-install-root/SUNWps/lib directory). This program takes an RDM request (which is a message in SOIF format), sends it to the search engine, and outputs the results as a SOIF stream. You can also use HTTP to post an RDM stream directly to the server through its URL (http://server:port/portal/search). The program must be run in a search-enabled Sun Java System Portal Server software instance directory such as the default /var/opt/SUNWps/serverinstance/portal directory.

You should also change the definitions for MY_CSID, MY_SCOPE and MY_ATTR_VIEW to suit your needs.


RDMHeader and RDMQuery Object Parameters

The following table describes the RDMHeader and RDMQuery object parameters in the first (left) column and provides a description of the corresponding parameter in the second (right) column

MY_CSID

ID of the search engine instance. This parameter specifies the specific search engine that you created in the search engine Administration Interface. You can find the exact value in /var/opt/SUNWps/serverinstance/portal/config/search.conf. For SSL enabled server instances, use x-catalogs instead of x-catalog in the CSID.

MY_SCOPE

Query string. The default is to search for documents containing the string varrius. For example, if you want to search for all documents containing the string style_sheets, then set MY_SCOPE to style_sheets.

MY_ATTR_VIEW

Attributes to be printed, such as URL, title and description.

Code Example 24-1 generates an RDM for querying a search engine database. You can pipe the output of the sample program to a temporary file and then use the sendrdm program to post it to the search engine.

Code Example 24-1  RDM API to Submit a Query Example  

/******* Example Use of the RDM API to submit a query *******/

#include <stdio.h>

#include “soif.h”

#include “rdm.h”

#define MY_SCOPE “varrius”

#define MY_CSID “x-catalog://budgie.siroe.com:6714/search1”

#define MY_ATTR_VIEW “title,content-type”

int main(int argc, char *argv)

{

    RDMQuery *myquery = NULL;

    CSID *csid = NULL;

    RDMHeader *myheader = NULL;

    SOIFStream *out = SOIF_PrintInitFile(stdout);

    /* Create the RDMQuery and specify its scope */

    if(!(myquery = RDMQuery_Create(MY_SCOPE))) {

        perror(“RDMQuery_Create\n”);

        exit(-1);

    }

    /* Set the view attributes of the RDMQuery */

    RDMQuery_SetViewAttr(myquery, MY_ATTR_VIEW);

    /* Create the CSID that points to your search engine instance */

    if(!(csid = CSID_Parse(MY_CSID))) {

        perror(“CSID_Parse\n”);

        exit(-1);

    }

    /* Create the RDMHeader */

    if(!(myheader = RDMHeader_CreateRequest(RDM_RD_REQ, “search”,

    csid))) {

        perror(“RDMHeader_CreateRequest\n”);

        exit(-1);

    }

    /* print the RDMHeader to the output SOIF stream */

    /* print the RDMQuery to the output SOIF stream */

    (*out->print)(out, myheader->soif);

    (*out->print)(out, myquery->soif);

    /* free the structures and exit */

    RDMHeader_Free(myheader);

    RDMQuery_Free(myquery);

    SOIFStream_Finish(out);

    exit(0);

}

/*********** EOF ****************/


Running the Example

To run the example described in Code Example 24-1, follow these steps:

  1. Edit the definitions for MY_SCOPE, MY_CSID, and MY_ATTR_VIEW as appropriate for your situation. For more information, see Code Example 24-2.
  2. Save the file in portal-server-install-root/SUNWps/sdk/rdm/examples directory. For example, save the file as example4.c in portal-server-install-root/SUNWps/sdk/rdm/examples directory.
  3. Create a makefile. You can find sample makefiles at portal-server-install-root/SUNWps/sdk/rdm/examples directory. Edit the makefile to include example4.c. Code Example 24-2 shows the makefile with the changes needed for example4.c in bold:
  4. Code Example 24-2  Makefile for SOIF/RDM examples  

    # Makefile for SOIF/RDM SDK examples

    # Use make and cc.

    CC = cc

    SDKDIR = ..

    SDKLIB = $(SDKDIR)/lib/librdm.a

    SDKINC = $(SDKDIR)/include/

    CFLAGS = -I$(SDKINC) -DXP_UNIX

    CFLAGS += -DSOLARIS

    #CFLAGS += -DIRIX

    #CFLAGS += -DHPUX

    #CFLAGS += -DAIX

    EXAMPLES = example1 example2 example3 example4

    all: $(EXAMPLES)

    example1: example1.o

    $(CC) -o $@ $@.o $(SDKLIB)

    example2: example2.o

    $(CC) -o $@ $@.o $(SDKLIB)

    example3: example3.o

    $(CC) -o $@ $@.o $(SDKLIB)

    example4:       example4.o

    $(CC) -o $@ $@.o $(SDKLIB)

  5. From the portal-server-install-root/SUNWps/sdk/rdm/examples directory, build the example as follows:
  6. Solaris: gmake

  7. From the portal-server-install-root/SUNWps/sdk/rdm/examples directory, run the example4.c program to generate the RDM file.
  8. example4.c > rdm.soif

The file rdm.soif created in must be placed into the server instance directory.

  1. Send the SOIF contained in rdm.soif to the program sendrdm. For example, type:
  2. ./run-cs-cli sendrdm -u /portal/search rdm.soif

    The current directory should be the server instance directory. If rdm.soif is not in the server instance directory, reference the file from where is was created. For example:

    1. Change directories to server_instace_dir.
    2. Type ./run-cs-cli sendrdm -u /portal/search sdk_dir/rdm.soif.
    3. The results of the sendrdm program will be a SOIF stream containing the results of the query, such as the following example:
    4. @RDMHEADER { -

      catalog-service-id{41}:x-catalog://budgie.siroe.com:6714/budgie

      rdm-version{3}: 1.0

      rdm-type{11}: rd-response

      rdm-response-interpret{51}:20 results out of 36281 hits across 88985 documents

      }

      @DOCUMENT {

      http://fury.sesta.com:999/it/newsref/pr/newsrelease417.html

      content-type{9}: text/html

      score{3}: 100

      title{17}: Comunicato stampa

      }

      @DOCUMENT {

      http://fury.sesta.com:999/it/newsref/pr/newsrelease374.html

      content-type{9}: text/html

      score{3}: 100

      title{17}: Comunicato stampa

      }

You can pipe the output of sendrdm (which is a SOIFStream) to another program to print the results of the query.



Previous      Contents      Index      Next     


Copyright 2004 Sun Microsystems, Inc. All rights reserved.