home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / xmlsearching.xml < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  15.4 KB  |  352 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" "document-v10.dtd">
  18.  
  19. <document>
  20.   <header>
  21.     <title>XML Searching</title>
  22.     <subtitle>Search resources in Apache Cocoon</subtitle>
  23.     <version>1.0</version> 
  24.     <type>Technical document</type> 
  25.     <authors>
  26.       <person name="Bernhard Huber" email="berni_huber@a1.net"/>
  27.       <person name="Jeremy Quinn" email="jeremy@apache.org"/>
  28.     </authors>
  29.   </header>
  30.  
  31.   <body>
  32.     <s1 title="Introduction">
  33.       <p>
  34.         This document describes indexing, and searching XML documents
  35.         in Apache Cocoon.
  36.       </p>
  37.       <p>
  38.         Indexing is the process of fetching XML documents from an Apache Cocoon
  39.         instance, and building an index file.
  40.         Searching is the process of querying the once built index.
  41.       </p>
  42.       <p>
  43.         See also Wiki: 
  44.         <link href="http://wiki.cocoondev.org/Wiki.jsp?page=LuceneIndexTransformer">LuceneIndexTransformer</link>
  45.       </p>
  46.     </s1>
  47.  
  48.     <s1 title="Decomposition of XMLSearching">
  49.       <p>
  50.         The indexing process is split up into crawling, fetching URL resource, 
  51.         and generating the index.
  52.       </p>
  53.       <p>
  54.         The searching process is split up into searching, 
  55.         and feeding search result into the
  56.         Apache Cocoon pipeline.
  57.       </p>
  58.       <s2 title="Crawling">
  59.         <p>
  60.           The crawling process is specified by  
  61.         </p>
  62.         <ol>
  63.           <li>Base URL to start crawling from</li>
  64.           <li>Included, and excluded URLs</li>
  65.           <li>Cocoon view to use for requesting links from an XML resource</li>
  66.         </ol>
  67.         <p>
  68.           Specifying the base URL determines the protocol for fetching XML resources.
  69.           The  implementation offers to specify <code>http:</code> URLs, 
  70.           crawling an Apache Cocoon instance deployed in a servlet-engine.
  71.           Alternatively you may specify an URI, e.g.: <code>/documents/index.html</code>,
  72.           offering to crawl the local Apache Cocoon instance only, either
  73.           servlet-deployed, or in commandline-mode.
  74.         </p>
  75.       </s2>
  76.       <s2 title="Fetching URL resource">
  77.         <p>
  78.           This processing step fetches the URL resource from Apache Cocoon.
  79.         </p>
  80.         <p>
  81.           Apache Cocoon offers the feature of views.
  82.           This feature is used to fetch the 'bare' content of an URL.
  83.         </p>
  84.         <p>
  85.           The crawling component described above is used by the this processing step
  86.           to retrieve a link of an XML document. 
  87.           The link name is augmented by a cocoon view name for fetching the XML resource.
  88.         </p>
  89.         <p>
  90.           The Avalon component <code>CocoonCrawler</code> defines the interface
  91.           of a crawler.
  92.         </p>
  93.         <p>
  94.           The Avalon component <code>SimpleCocoonCrawlerImpl</code> is the implementation. 
  95.           It can be configured to use a specific view, or default to the 'content' view.
  96.         </p>
  97.       </s2>
  98.       <s2 title="Generating index">
  99.         <p>
  100.           A xml resource is fed into a indexing engine.
  101.           Generating an index specifies which elements of an XML resources
  102.           should get indexed, how the elements are stored in the index.
  103.           Moreover the physical file location of the index is specified by
  104.           this processing step.
  105.         </p>
  106.         <p>
  107.           The current implementation splits up an XML resource the following way:
  108.         </p>
  109.         <ul>
  110.           <li>Use an Lucene Analyzer for splitting up text</li>
  111.           <li>Each XML element is indexed using its name as Lucene field name.</li>
  112.           <li>Each XML attribute is indexed using its element name and the attribute name
  113.             as field name. An attribute has following field name 
  114.             <code>{element-name}@{attribute-name}</code>.
  115.           </li>
  116.           <li>XML elements that match the names you configured in cocoon.xconf are added as stored fields.</li>
  117.         </ul>
  118.         <p>
  119.           The Avalon component <code>LuceneCocoonIndexer</code> defines the interface
  120.           of an indexer.
  121.         </p>
  122.         <p>
  123.           The Avalon component <code>LuceneXMLIndexer</code> defines an interface
  124.           for building an lucene index from an XML document. It uses an SAX content handler
  125.           for parsing an XML document, and generating Lucene fields, the current 
  126.           index layout is implemented by <code>SimpleLuceneXMLIndexerImpl</code>,
  127.           and <code>LuceneIndexContentHandler</code>.
  128.         </p>
  129.       </s2>
  130.  
  131.       <s2 title="Searching">
  132.         <p>
  133.           This process uses a search engine for querying the index. 
  134.           The input of this process is a search query string, the result is the
  135.           search result of the search engine.
  136.         </p>
  137.         <p>
  138.           The Avalon component <code>LuceneCocoonSearcher</code> defines an interface
  139.           for searching a Lucene index.
  140.         </p>
  141.       </s2>
  142.       <s2 title="Feeding Search Results">
  143.         <p>
  144.           This is the final step for presenting information stored in the index.
  145.           The result of search engine is feed into the Cocoon processing pipeline.
  146.         </p>
  147.         <p>
  148.           A GUI for the searching process may be developed using any
  149.           java enabled script language, like JSP, or XSP. 
  150.           Moreover a sitemap generator component <code>SearchGenerator</code>
  151.           is provided which transforms the search result to XML, and feeds it
  152.           into the Cocoon processing pipeline.
  153.         </p>
  154.       </s2>
  155.     </s1>
  156.     
  157.     <s1 title="Interdependencies">
  158.       <p>
  159.         As both Avalon components <code>LuceneXMLIndexer</code>, and 
  160.         <code>LuceneCocoonSearcher</code> may use the same Lucene index, you must
  161.         take care of the Lucene index structure in both components.
  162.       </p>
  163.       <p>
  164.         The current implementation uses following Lucene index layout
  165.       </p>
  166.       <ul>
  167.         <li>Lucene field <code>body</code> indexed field of the pure text of an XML document.
  168.           The <code>body</code> field is the default field name for searching. Thus the
  169.           query-string <code>foo</code>, and <code>body:foo</code> is equivalent.
  170.         </li>
  171.         <li>Each XML element generates a Lucene field having the same name as the XML element name.
  172.           For example searching for occurences of <code>Cocoon</code> inside of an XML abstract
  173.           element, use query-string <code>abstact:Cocoon</code>.
  174.         </li>
  175.         <li>Each XML attribute generates a Lucene field having the name
  176.           <code>{element-name}@{attribute-name}</code>. 
  177.           For example searching for occurrences of <code>Cocoon</code> inside of an XML title attribute
  178.           of s1 element, use query-string <code>s1@title:Cocoon</code>.
  179.         </li>
  180.         <li>
  181.           The Lucene field <code>url</code> stores the URI of the indexed document. As
  182.           all fields described above are only indexed information, and no XML document 
  183.           is stored inside the Lucene index, this field is the only reference to the 
  184.           XML document resource.
  185.         </li>
  186.         <li>
  187.           The Lucene field <code>uid</code> stores an unique id for implementing updating
  188.           the index. This field is used for checking if the XML resource is newer than
  189.           the information stored in the Lucene index.
  190.         </li>
  191.         <li>
  192.           Further Stored fields can be added, depending on your configuration. 
  193.           Stored fields are returned in the hits found by the engine.
  194.         </li>
  195.       </ul>
  196.     </s1>
  197.       
  198.     <s1 title="Configuration">
  199.       <p>
  200.         Configuring the indexing, and searching Avalon components is specified
  201.         in the <code>cocoon.xconf</code> file.
  202.       </p>
  203.       <s2 title="example">
  204.                 <p>This would set up the crawler to crawl all of your site, except pages in the 'search' section, also we are telling the crawler to use a non-standard cocoon-view for getting the links in documents, called <code>my-search-links</code>. </p>
  205. <source><![CDATA[
  206. <cocoon-crawler logger="core.search.crawler">
  207.   <exclude>.*/search/.*</exclude>
  208.   <link-view-query>cocoon-view=my-search-links</link-view-query>
  209. </cocoon-crawler>
  210. ]]></source>
  211.           <p>This tells the indexer to use the non-standard 'my-search-content' view to retrieve the content for indexing. Also it tells the indexer that we would like to have any <code>title</code> or <code>subtitle</code> XML elements in the document added to the index as stored fields, so they can be retrieved and displayed to the user with any hits they get.</p>
  212. <source><![CDATA[
  213. <lucene-xml-indexer logger="core.search.lucene">
  214.   <store-fields>title, subtitle</store-fields>
  215.   <content-view-query>cocoon-view=my-search-content</content-view-query>
  216. </lucene-xml-indexer>
  217. ]]></source>
  218.       </s2>
  219.       <p>
  220.         Setting up the sitemap component SearchGenerator takes place in the
  221.         <code>sitemap.xmap</code> file.
  222.       </p>
  223.       <s2 title="example">
  224.                 <p>This would generate a document from a search, getting the query and other information from request parameters.</p>
  225. <source><![CDATA[
  226. <map:generate type="search"/>
  227. ]]></source>
  228.           <p>This would generate a document from a search, getting the query from the sitemap parameter '1' and other information from request parameters.</p>
  229. <source><![CDATA[
  230. <map:generate type="search">
  231.   <map:parameter name="query" value="{1}"/>
  232. </map:generate>    
  233. ]]></source>
  234.       </s2>
  235.     </s1>
  236.     
  237.     <s1 title="Implementation notes">
  238.       <p>
  239.         The package <code>org.apache.cocoon.components.search</code> holds
  240.         all searching relevant components.
  241.         The current implementation uses
  242.         <link href="http://jakarta.apache.org/lucene">Jakarta Lucene</link>
  243.         as its indexing, and searching engine.
  244.       </p>
  245.       <p>
  246.         SearchGenerator is sitemap generator and is available in
  247.         the package <code>org.apache.cocoon.generation</code>.
  248.       </p>
  249.       <p>
  250.         The package <code>org.apache.cocoon.components.crawler</code> holds
  251.         all crawling relevant sources.
  252.       </p>
  253.     </s1>
  254.     
  255.     <s1 title="WebApp Sample usage">
  256.       <p>
  257.         The Cocoon sample webapplication has a link for generating,
  258.         an index of the Cocoon documentation, and searching the 
  259.         Cocoon documentation.
  260.       </p>
  261.       <p>
  262.         The following list describes step by step how to make use of
  263.         webapp sample page:
  264.       </p>
  265.       <ol>
  266.         <li>Go to the page "Search the docs".
  267.         </li>
  268.         <li>Create an index, follow the link "create".
  269.           Creating an index may take some time, as the implementation
  270.           accesses the XML resources via http: protocol.
  271.         </li>
  272.         <li>Next you may query the index, by following the 
  273.           link "XSP", or "Cocoon Generators". Typing in a query will
  274.           result in the table of hits orderer by relevance.
  275.         </li>
  276.       </ol>
  277.       <p>
  278.         As a result of the creation step, there should exist an
  279.         Lucene index in the directory <code>index</code> 
  280.         below the temporary working directory of the servlet engine.
  281.       </p>
  282.       <p>
  283.         The "XSP" link for searching shows an XSP implementation of
  284.         invoking the Avalon component <code>CocoonSearch</code>. 
  285.         Using this approach gives fine grained control
  286.         over the searching process.
  287.       </p>
  288.       <p>
  289.         The "Cocoon Generator" links defines in the sitemap using
  290.         the SearchGenerator, and transforming the XML search result to HTML.
  291.         This approach tries to minimize your effort of using searching,
  292.         as you need to adapt the XSLT transformation step only to your
  293.         needs.
  294.       </p>
  295.     </s1>
  296.     <s1 title="Extending the Sample">
  297.       <p>
  298.         It is easy to extend the search sample to display more information about the search hit than just the url of the resource.</p>
  299.             <p>In order to show, for example, the title and summary of a document, these first need to be added to the search index as 'Stored Fields'. Then when the documents are found during a search, that information is available to display, from the search engine itself.</p>
  300.       <p>First, decide which fields you want to store.</p>
  301.       <p>Decide where is the best place in your pipeline for content to be extracted for indexing, it might not always be the default view 'content'.</p>
  302.       <p>Next, decide if you need an XSLT transformation on your documents, to make them more suitable for indexing. This may include deciding on one of several titles in your document, what part of your document gets added to the summary etc. You might want to strip certain tags out because you don't want their content searched. You might be able to raise hit scores on documents by re-arranging content, or keeping larger amounts of content in fewer tags.</p>
  303.             <p>Now you tell the search engine (in cocoon.xconf) which tags you'd like storing.</p>
  304. <source><![CDATA[
  305. <lucene-xml-indexer logger="core.search.lucene">
  306.   <store-fields>title, summary</store-fields>
  307.   <content-view-query>cocoon-view=search-content</content-view-query>
  308. </lucene-xml-indexer>
  309. ]]></source>
  310.             <p>This example tells the indexer to store any tags called 'title' or 'summary' it finds in your documents. It also tells the indexer to get it's content from the view called 'search-content'.</p>
  311. <source><![CDATA[
  312. <map:view from-label="search" name="search">
  313.   <map:transform src="search-filter.xsl"/>
  314.   <map:serialize type="xml"/>
  315. </map:view>
  316. ]]></source>
  317.             <p>This is how you might setup that custom view in your sitemap. You would then add a label attribute <code>label="search"</code> to the appropriate place in your pipelines. See the section on views for more information.</p>
  318.             <p>After you have re-indexed the site, when you do searches, the new fields will be available in the XML output by Lucene, in the form of a <code>search:field</code> tag, you will need to modify your XSLT that displays the hits to show this.</p>
  319. <source><![CDATA[
  320. <xsl:template match="search:hit">
  321.   <tr>
  322.     <td>
  323.       <xsl:value-of select="format-number( @search:score, '### %' )"/>
  324.     </td>
  325.     <td>
  326.       <xsl:value-of select="@search:rank"/>
  327.     </td>
  328.     <td>
  329.       <a target="_blank" href="{@search:uri}">
  330.         <xsl:attribute name="title">
  331.           <xsl:value-of select="search:field[@search:name='summary']"/>
  332.         </xsl:attribute>
  333.         <xsl:value-of select="search:field[@search:name='title']"/>
  334.       </a>
  335.     </td>
  336.   </tr>
  337. </xsl:template>
  338. ]]></source>
  339. <p>This is how the search sample's xslt might be changed. All the fields you made for each document are available to you as <code>search:field</code> elements in the <code>search:hit</code> elements. The code above assumes you only had one 'title' and one 'summary' per document.</p>
  340.     </s1>
  341.     <s1 title="Summary">
  342.       <p>
  343.         This document gives an overview of the components for
  344.         using an indexing, and searching engine in Cocoon.
  345.         It described the component decomposition of the Cocoon
  346.         XMLSearch subsystem.
  347.       </p>
  348.     </s1>
  349.   </body>
  350. </document>
  351.  
  352.