1    /*
2     * Copyright 2007 :torweg free software group
3     * 
4     * This program is free software: you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation, either version 3 of the License, or
7     * (at your option) any later version.
8     * 
9     * This program is distributed in the hope that it will be useful,
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    * GNU General Public License for more details.
13    * 
14    * You should have received a copy of the GNU General Public License
15    * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16    *
17    */
18   package org.torweg.pulse.util.search;
19   
20   import org.apache.log4j.Logger;
21   import org.apache.lucene.document.Document;
22   import org.hibernate.search.bridge.FieldBridge;
23   import org.hibernate.search.bridge.LuceneOptions;
24   import org.torweg.pulse.site.View;
25   import org.torweg.pulse.site.content.Content;
26   
27   /**
28    * a {@code FieldBridge} to map {@code Content} for the site's full text search.
29    * 
30    * @author Thomas Weber
31    * @version $Revision: 1792 $
32    */
33   public class ViewFieldBridge implements FieldBridge {
34   
35       /**
36        * the logger.
37        */
38       private static final Logger LOGGER = Logger
39               .getLogger(ViewFieldBridge.class);
40   
41       /**
42        * maps a {@code Content} to the site's full text search index.
43        * 
44        * @param name
45        *            the name of the field
46        * @param value
47        *            the value to be translated
48        * @param doc
49        *            the document to add the field to
50        * @param options
51        *            the store
52        */
53       public final void set(final String name, final Object value,
54               final Document doc, final LuceneOptions options) {
55           View view = (View) value;
56           if (view != null) {
57               Content content = view.getContent();
58               String fullText = content.getFullTextValue().toString();
59               if (LOGGER.isTraceEnabled()) {
60                   LOGGER.trace("Fulltext value:"
61                           + System.getProperty("line.separator") + fullText);
62               }
63               options.addFieldToDocument(name, fullText, doc);
64               options.addFieldToDocument("title", content.getName(), doc);
65           }
66       }
67   
68   }
69