cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/generation SearchGenerator.java
Date Fri, 06 Sep 2002 03:35:34 GMT
vgritsenko    2002/09/05 20:35:34

  Modified:    .        Tag: cocoon_2_0_3_branch changes.xml
               src/documentation/xdocs/userdocs/generators Tag:
                        cocoon_2_0_3_branch search-generator.xml
               src/java/org/apache/cocoon/generation Tag:
                        cocoon_2_0_3_branch SearchGenerator.java
  Log:
  Add <field/> to the <hit/> to allow context in the search result
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.138.2.47 +7 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.138.2.46
  retrieving revision 1.138.2.47
  diff -u -r1.138.2.46 -r1.138.2.47
  --- changes.xml	15 Aug 2002 03:13:46 -0000	1.138.2.46
  +++ changes.xml	6 Sep 2002 03:35:33 -0000	1.138.2.47
  @@ -40,6 +40,12 @@
   
    <release version="@version@" date="@date@">
     <action dev="VG" type="update">
  +    SearchGenerator now includes &lt;field name=""/&gt; elements into &lt;hit/&gt;
  +    element. These elements contain stored fields of a found Document,
  +    making it possible to provide additional info about document in the
  +    search result list (only when index created with some stored fields).
  +  </action>
  +  <action dev="VG" type="update">
       In addition to attributes in same namespace with elements,
       link serializer reacts on non-namespaced attributes too. This allows
       processing of (strict) XHTML.
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +5 -0      xml-cocoon2/src/documentation/xdocs/userdocs/generators/search-generator.xml
  
  Index: search-generator.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/documentation/xdocs/userdocs/generators/search-generator.xml,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- search-generator.xml	3 Jan 2002 12:31:04 -0000	1.1
  +++ search-generator.xml	6 Sep 2002 03:35:33 -0000	1.1.2.1
  @@ -213,6 +213,11 @@
      uri CDATA #IMPLIED
   >
   
  +<!ELEMENT field (#PCDATA)>
  +<!ATTLIST field
  +   name CDATA #REQUIRED
  +>
  +
   <!ELEMENT navigation (navigation-page)*>
   <!ATTLIST navigation
      total-count CDATA #IMPLIED
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.8.2.1   +50 -128   xml-cocoon2/src/java/org/apache/cocoon/generation/SearchGenerator.java
  
  Index: SearchGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/generation/SearchGenerator.java,v
  retrieving revision 1.8
  retrieving revision 1.8.2.1
  diff -u -r1.8 -r1.8.2.1
  --- SearchGenerator.java	8 Mar 2002 04:12:14 -0000	1.8
  +++ SearchGenerator.java	6 Sep 2002 03:35:33 -0000	1.8.2.1
  @@ -71,6 +71,7 @@
   
   import org.apache.lucene.analysis.Analyzer;
   import org.apache.lucene.document.Document;
  +import org.apache.lucene.document.Field;
   import org.apache.lucene.search.Hits;
   import org.apache.lucene.store.Directory;
   
  @@ -82,6 +83,7 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +import java.util.Enumeration;
   
   /**
    * Generates an XML representation of a search result.
  @@ -98,22 +100,26 @@
    * </p>
    * <pre><tt>
    * &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  + *
    * &lt;search:results date=&quot;1008437081064&quot; query-string=&quot;cocoon&quot;
  - * start-index=&quot;0&quot; page-length=&quot;10&quot;
  - * xmlns:search=&quot;http://apache.org/cocoon/search/1.0&quot;
  - * xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
  - * &lt;search:hits total-count=&quot;125&quot; count-of-pages=&quot;13&quot;&gt;
  - * &lt;search:hit rank=&quot;0&quot; score=&quot;1.0&quot;
  - * uri=&quot;http://localhost:8080/cocoon/documents/hosting.html&quot;/&gt;
  - * ...
  - * &lt;/search:hits&gt;
  - * &lt;search:navigation total-count=&quot;125&quot; count-of-pages=&quot;13&quot;
  - * has-next=&quot;true&quot; has-previous=&quot;false&quot; next-index=&quot;10&quot;
previous-index=&quot;0&quot;&gt;
  - * &lt;search:navigation-page start-index=&quot;0&quot;/&gt;
  - * &lt;search:navigation-page start-index=&quot;10&quot;/&gt;
  - * ...
  - * &lt;search:navigation-page start-index=&quot;120&quot;/&gt;
  - * &lt;/search:navigation&gt;
  + *     start-index=&quot;0&quot; page-length=&quot;10&quot;
  + *     xmlns:search=&quot;http://apache.org/cocoon/search/1.0&quot;
  + *     xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
  + *   &lt;search:hits total-count=&quot;125&quot; count-of-pages=&quot;13&quot;&gt;
  + *     &lt;search:hit rank=&quot;0&quot; score=&quot;1.0&quot;
  + *         uri=&quot;http://localhost:8080/cocoon/documents/hosting.html&quot;&gt;
  + *       &lt;search:field name="title"&gt;Document Title&lt;search:field/&gt;
  + *     &lt;search:hit/&gt;
  + *     ...
  + *   &lt;/search:hits&gt;
  + *
  + *   &lt;search:navigation total-count=&quot;125&quot; count-of-pages=&quot;13&quot;
  + *       has-next=&quot;true&quot; has-previous=&quot;false&quot; next-index=&quot;10&quot;
previous-index=&quot;0&quot;&gt;
  + *     &lt;search:navigation-page start-index=&quot;0&quot;/&gt;
  + *     &lt;search:navigation-page start-index=&quot;10&quot;/&gt;
  + *     ...
  + *     &lt;search:navigation-page start-index=&quot;120&quot;/&gt;
  + *   &lt;/search:navigation&gt;
    * &lt;/search:results&gt;
    * </tt></pre>
    *
  @@ -127,29 +133,21 @@
   
       /**
        * The XML namespace for the output document.
  -     *
  -     * @since
        */
       protected final static String namespace = "http://apache.org/cocoon/search/1.0";
   
       /**
        * The XML namespace for xlink
  -     *
  -     * @since
        */
       protected final static String xlinkNamespace = "http://www.w3.org/1999/xlink";
   
       /**
        * Description of the Field
  -     *
  -     * @since
        */
       protected final static String CDATA = "CDATA";
   
       /**
        * Root element of generated xml content, ie <code>results</code>.
  -     *
  -     * @since
        */
       protected final static String RESULTS_ELEMENT = "results";
   
  @@ -157,64 +155,48 @@
        * Attribute <code>date</code> of <code>results</code> element.
        * It contains the date a long value, indicating when a search
        * generated this xml content.
  -     *
  -     * @since
        */
       protected final static String DATE_ATTRIBUTE = "date";
   
       /**
        * Attribute <code>query-string</code> of <code>results</code>
element.
        * Echos the <code>queryString</code> query parameter.
  -     *
  -     * @since
        */
       protected final static String QUERY_STRING_ATTRIBUTE = "query-string";
   
       /**
        * Attribute <code>start-index</code> of <code>results</code>
element.
        * Echos the <code>startIndex</code> query parameter.
  -     *
  -     * @since
        */
       protected final static String START_INDEX_ATTRIBUTE = "start-index";
   
       /**
        * Attribute <code>page-length</code> of <code>results</code>
element.
        * Echos the <code>pageLenth</code> query parameter.
  -     *
  -     * @since
        */
       protected final static String PAGE_LENGTH_ATTRIBUTE = "page-length";
   
       /**
        * Child element of generated xml content, ie <code>hits</code>.
        * This element describes all hits.
  -     *
  -     * @since
        */
       protected final static String HITS_ELEMENT = "hits";
   
       /**
        * Attribute <code>total-count</code> of <code>hits</code>
element.
        * The value describes total number of hits found by the search engine.
  -     *
  -     * @since
        */
       protected final static String TOTAL_COUNT_ATTRIBUTE = "total-count";
   
       /**
        * Attribute <code>count-of-pages</code> of <code>hits</code>
element.
        * The value describes number of pages needed for all hits.
  -     *
  -     * @since
        */
       protected final static String COUNT_OF_PAGES_ATTRIBUTE = "count-of-pages";
   
       /**
        * Child element of generated xml content, ie <code>hit</code>.
        * This element describes a single hit.
  -     *
  -     * @since
        */
       protected final static String HIT_ELEMENT = "hit";
   
  @@ -222,146 +204,116 @@
        * Attribute <code>rank</code> of <code>hit</code> element.
        * The value describes the count index of this hits, ranging between 0, and
        * total-count minus 1.
  -     *
  -     * @since
        */
       protected final static String RANK_ATTRIBUTE = "rank";
   
       /**
        * Attribute <code>score</code> of <code>hit</code> element.
        * The value describes the score of this hits, ranging between 0, and 1.0.
  -     *
  -     * @since
        */
       protected final static String SCORE_ATTRIBUTE = "score";
   
       /**
        * Attribute <code>uri</code> of <code>hit</code> element.
        * The value describes the uri of a document matching the search query.
  -     *
  -     * @since
        */
       protected final static String URI_ATTRIBUTE = "uri";
   
       /**
  +     * Child element <code>field</code> of the <code>hit</code>
element.
  +     * This element contains value of the stored field of a hit.
  +     *
  +     * @since 2.0.4
  +     */
  +    protected final static String FIELD_ELEMENT = "field";
  +
  +    /**
        * Child element of generated xml content, ie <code>navigation</code>.
        * This element describes some hints for easier navigation.
  -     *
  -     * @since
        */
       protected final static String NAVIGATION_ELEMENT = "navigation";
   
       /**
        * Child element of generated xml content, ie <code>navigation</code>.
        * This element describes the start-index of page containing hits.
  -     *
  -     * @since
        */
       protected final static String NAVIGATION_PAGE_ELEMENT = "navigation-page";
   
       /**
        * Attribute <code>has-next</code> of <code>navigation-page</code>
element.
        * The value is true if a next navigation control should be presented.
  -     *
  -     * @since
        */
       protected final static String HAS_NEXT_ATTRIBUTE = "has-next";
   
       /**
        * Attribute <code>has-next</code> of <code>navigation-page</code>
element.
        * The value is true if a previous navigation control should be presented.
  -     *
  -     * @since
        */
       protected final static String HAS_PREVIOUS_ATTRIBUTE = "has-previous";
   
       /**
        * Attribute <code>next-index</code> of <code>navigation-page</code>
element.
        * The value describes the start-index of the next-to-be-presented page.
  -     *
  -     * @since
        */
       protected final static String NEXT_INDEX_ATTRIBUTE = "next-index";
   
       /**
        * Attribute <code>previous-index</code> of <code>navigation-page</code>
element.
        * The value describes the start-index of the previous-to-be-presented page.
  -     *
  -     * @since
        */
       protected final static String PREVIOUS_INDEX_ATTRIBUTE = "previous-index";
   
       /**
        * Setup parameter name of index directory, ie <code>index</code>.
  -     *
  -     * @since
        */
       protected final static String INDEX_PARAM = "index";
   
       /**
        * Default value of setup parameter <code>index</code>, ie <code>index</code>.
  -     *
  -     * @since
        */
       protected final static String INDEX_PARAM_DEFAULT = "index";
   
       /**
        * Setup parameter name specifying the name of query-string query parameter,
        * ie <code>query-string</code>.
  -     *
  -     * @since
        */
       protected final static String QUERY_STRING_PARAM = "query-string";
   
       /**
        * Default value of setup parameter <code>query-string</code>, ie <code>queryString</code>.
  -     *
  -     * @since
        */
       protected final static String QUERY_STRING_PARAM_DEFAULT = "queryString";
   
       /**
        * Setup parameter name specifying the name of start-index query parameter,
        * ie <code>start-index</code>.
  -     *
  -     * @since
        */
       protected final static String START_INDEX_PARAM = "start-index";
   
       /**
  -     *Description of the Field
  -     *
  -     * @since
  +     * Default value of setup parameter <code>start-index</code>, ie <code>startIndex</code>.
        */
       protected final static String START_INDEX_PARAM_DEFAULT = "startIndex";
   
       /**
        * Setup parameter name specifying the name of start-next-index query parameter,
        * ie <code>start-next-index</code>.
  -     *
  -     * @since
        */
       protected final static String START_INDEX_NEXT_PARAM = "start-next-index";
   
       /**
  -     *Description of the Field
  -     *
  -     * @since
  +     * Default value of setup parameter <code>start-next-index</code>, ie <code>startNextIndex</code>.
        */
       protected final static String START_INDEX_NEXT_PARAM_DEFAULT = "startNextIndex";
   
       /**
        * Setup parameter name specifying the name of start-previous-index query parameter,
        * ie <code>start-previous-index</code>.
  -     *
  -     * @since
        */
       protected final static String START_INDEX_PREVIOUS_PARAM = "start-previous-index";
   
       /**
  -     *Description of the Field
  -     *
  -     * @since
  +     * Default value of setup parameter <code>start-previous-index</code>,
ie <code>startPreviousIndex</code>.
        */
       protected final static String START_INDEX_PREVIOUS_PARAM_DEFAULT = "startPreviousIndex";
   
  @@ -375,8 +327,6 @@
       /**
        * Setup parameter name specifying the name of page-length query parameter,
        * ie <code>page-length</code>.
  -     *
  -     * @since
        */
       protected final static String PAGE_LENGTH_PARAM = "page-length";
   
  @@ -405,50 +355,36 @@
        * <p>
        *   By default this directory is set to the <code>WORKING_DIR</code> of
Cocoon.
        * </p>
  -     *
  -     * @since
        */
       private File workDir = null;
   
       /**
        * The avalon component to use for searching.
  -     *
  -     * @since
        */
       private LuceneCocoonSearcher lcs;
   
       /**
        * Absolute filesystem directory of lucene index directory
  -     *
  -     * @since
        */
       private File index = null;
   
       /**
        * Query-string to search for
  -     *
  -     * @since
        */
       private String queryString = "";
   
       /**
        * Attributes used when generating xml content.
  -     *
  -     * @since
        */
       private final AttributesImpl atts = new AttributesImpl();
   
       /**
        * startIndex of query parameter
  -     *
  -     * @since
        */
       private Integer startIndex = null;
   
       /**
        * pageLength of query parameter
  -     *
  -     * @since
        */
       private Integer pageLength = null;
   
  @@ -585,31 +521,6 @@
   
   
       /**
  -     * Create an Integer from a String.
  -     * <p>
  -     *   Create an Integer from String s, iff conversion fails use default_value.
  -     * </p>
  -     *
  -     * @param  s              Converting s to an Integer
  -     * @param  default_value  Default value to use, iff conversion of s fails.
  -     * @return                Integer        converted value originating from s, or default_value
  -     * @since
  -     */
  -    private Integer createInteger(String s, int default_value) {
  -        Integer i = new Integer(default_value);
  -        try {
  -            i = new Integer(s);
  -        } catch (NumberFormatException nfe) {
  -            // ignore it, write only warning
  -            if (getLogger().isWarnEnabled()) {
  -                getLogger().warn("Cannot convert " + s + " to Integer", nfe);
  -            }
  -        }
  -        return i;
  -    }
  -
  -
  -    /**
        * Create an Integer.
        * <p>
        *   Create an Integer from String s, iff conversion fails return null.
  @@ -680,9 +591,8 @@
        * @param  pager                 the LuceneContentPager with the search results
        * @since
        * @throws  SAXException         when there is a problem creating the output SAX events.
  -     * @throws  ProcessingException  when there is a problem obtaining the hits
        */
  -    private void generateHits(LuceneCocoonPager pager) throws SAXException, ProcessingException
{
  +    private void generateHits(LuceneCocoonPager pager) throws SAXException {
           if (pager != null && pager.hasNext()) {
               atts.clear();
               atts.addAttribute(namespace, TOTAL_COUNT_ATTRIBUTE, TOTAL_COUNT_ATTRIBUTE,
  @@ -702,9 +612,8 @@
        * @param  pager                 the LuceneCocoonPager with the search results.
        * @since
        * @throws  SAXException         when there is a problem creating the output SAX events.
  -     * @throws  ProcessingException  when there is a problem obtaining the hits
        */
  -    private void generateHit(LuceneCocoonPager pager) throws SAXException, ProcessingException
{
  +    private void generateHit(LuceneCocoonPager pager) throws SAXException {
           // get the off set to start from
           int counter = pager.getStartIndex();
   
  @@ -726,6 +635,20 @@
                       String.valueOf(uri));
               contentHandler.startElement(namespace, HIT_ELEMENT, HIT_ELEMENT, atts);
               // fix me, add here a summary of this hit
  +            for (Enumeration e = doc.fields(); e.hasMoreElements(); ) {
  +                Field field = (Field)e.nextElement();
  +                if (field.isStored()) {
  +                    if (LuceneXMLIndexer.URL_FIELD.equals(field.name()))
  +                        continue;
  +                    atts.clear();
  +                    atts.addAttribute(namespace, "name", "name", CDATA, field.name());
  +                    contentHandler.startElement(namespace, FIELD_ELEMENT, FIELD_ELEMENT,
atts);
  +                    String value = field.stringValue();
  +                    contentHandler.characters(value.toCharArray(), 0, value.length());
  +                    contentHandler.endElement(namespace, FIELD_ELEMENT, FIELD_ELEMENT);
  +                }
  +            }
  +
               contentHandler.endElement(namespace, HIT_ELEMENT, HIT_ELEMENT);
           }
       }
  @@ -736,10 +659,9 @@
        *
        * @param  pager                    Description of Parameter
        * @exception  SAXException         Description of Exception
  -     * @exception  ProcessingException  Description of Exception
        * @since
        */
  -    private void generateNavigation(LuceneCocoonPager pager) throws SAXException, ProcessingException
{
  +    private void generateNavigation(LuceneCocoonPager pager) throws SAXException {
   
           if (pager != null) {
               // generate navigation element
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message