DBPrism Servlet Engine
DBPrism CMS Search Engine

Before show the java source, I'll show the corresponding entry into setupcms.xml file, which set the association of this dynamic services with the CMS structure.


  <CMS:documents>

    <CMS:document src="/Home.xml"/>
    <CMS:document src="/NotFound.xml" parent="no"/>
    <CMS:document src="/live/search.xml" parent="no"/>
    .....

This fragment of the setupcms.xml config file tells to the Upload Utility to insert a page in the content metadata named "Result Page" and which has no parent and, unlike other CMS pages the content is loaded with a sample document his content will be dynamic.

The code below shows the most important part of the Search Engine, this search engine uses a function

translate(avQueryString)
taked from the section code examples of Oracle Technology Network which translates Altavista (TM) query syntax to Oracle interMedia (TM) syntax and is not relevant at this point. I will try to explain each part of the code following.

  public void doSearch(String ext,
                       String baseURL,
                       String avQueryString)
  throws SQLException,IOException,SAXException {

Arguments, this function receives three arguments. ext means html, wml or xml given the posibilty of making different behaviours depending on the target output. baseURL is added to the begining of the links when the search engine makes urls to documents which contain the query string. avQueryString is the query string with Altavista (TM) syntax.

    String interMediaQueryString = translate(avQueryString);

interMediaQueryString hold the converted query string, now with Oracle interMedia (TM) query syntax.

    if (avQueryString.equalsIgnoreCase("nullQuery")) {
      Jxtp.tagOpen("body");
      Jxtp.tagOpen("s1","title='Advanced Search is not implemented yet'");
      Jxtp.tagClose("s1");
      Jxtp.tagClose("body");
      Jxtp.tagClose("document");
      return;
    }

If no query string is given as argument value implements Advance Search modality, like "find documents which contains DBPrism in titles of level 1, obviusly not implemented yet because document-v10.dtd do not include specifications for XForm tags.

    Jxtp.tagOpen("body");
    Jxtp.tagOpen("s1","title='Search result for:"+avQueryString+"'");
    Jxtp.tagOpen("table");
      // Title
      Jxtp.tagOpen("tr");
        Jxtp.tag("th","Rank");
        Jxtp.tag("th","Page");
        Jxtp.tag("th","Long Name");
        Jxtp.tag("th","Comments");
      Jxtp.tagClose("tr");

The resulting output of the search is enclosed in a html table like structure, at this point the code makes the corresponding header for the table.

      QueryResult qryResult = null;
      try {
        #sql qryResult = { select score(1) rank,cn_id_page,path,name,longname,comments
                           from content,pages
                           where contains(content, :interMediaQueryString, 1)>0
                           and cn_id_page=id_page
                           and version=current_version
                           order by rank desc };
        while(qryResult.next()) {
          String name = qryResult.name();
          Jxtp.tagOpen("tr");
            Jxtp.tag("td","("+qryResult.rank()+"%)");
            Jxtp.tagOpen("td");
              Jxtp.tag("link",name,
                       "href='"+baseURL+qryResult.path()+name+"."+ext+"'");
            Jxtp.tagClose("td");
            Jxtp.tag("td",qryResult.longname());
            String comments = qryResult.comments();
            if (comments!=null)
              Jxtp.tag("td",comments);
            else
              Jxtp.tag("td","");
          Jxtp.tagClose("tr");
        }

Execute the query on the table content only with the current documents, remember that the CMS stores previous version of the documents. The result is stored into the SQLJ iterator

qryResult
, then the while iterates over the result making links to the target documents.

SQLJ's select expresion uses the interMedia funtion
contains(columnName,query,1)
which returns values higher than cero when the XML documents stored in the selected column contains the given query.
      } catch (SQLException sqe) {
        Jxtp.tagOpen("tr");
          Jxtp.tag("td","0");
          Jxtp.tag("td","Pages found for");
          Jxtp.tag("td",avQueryString);
          Jxtp.tag("td","");
        Jxtp.tagClose("tr");
      }

Commonly this catch receives SQL No Data Found Exception which means no documents contain the given query.

    Jxtp.tagClose("table");
    Jxtp.tagClose("s1");
    Jxtp.tagClose("body");
    Jxtp.tagClose("document");
  }

This part of code closes the XML sections opened in the prevous part. One is the table, opened before the query, and the last is

<document>
opened by
showMetaData
function.

This work is licensed under a Creative Commons License . Creative Commons License
(C) 1999-2008 - DBPrism ~ DBPrism CMS | Marcelo F. Ochoa | TANDIL ~ Argentina | 2008-10-07T20:18:16
DBPrism at SourceForgeBuilt with Cocoon2