1    /*
2     * Copyright 2008 :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 java.util.Locale;
21   
22   import org.apache.lucene.document.Document;
23   import org.hibernate.search.bridge.FieldBridge;
24   import org.hibernate.search.bridge.LuceneOptions;
25   
26   /**
27    * a {@code FieldBridge} for indexing {@code Locale}.
28    * 
29    * @author Thomas Weber
30    * @version $Revision: 1792 $
31    */
32   public class LocaleFieldBridge implements FieldBridge {
33   
34       /**
35        * maps a {@code Locale} to a string.
36        * 
37        * @param name
38        *            the name of the field
39        * @param value
40        *            the value to be translated
41        * @param doc
42        *            the document to add the field to
43        * @param options
44        *            the Lucene options
45        */
46       public final void set(final String name, final Object value,
47               final Document doc, final LuceneOptions options) {
48           Locale locale = (Locale) value;
49           if (locale != null) {
50               options.addFieldToDocument(name, locale.toString(), doc);
51           }
52       }
53   
54   }
55