KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > search > ItemDocument


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: ItemDocument.java,v 1.6 2003/06/25 22:52:42 niko_schmuck Exp $
28

29 package de.nava.informa.search;
30
31 import de.nava.informa.core.ItemIF;
32
33 import org.apache.lucene.document.Document;
34 import org.apache.lucene.document.Field;
35 import org.apache.lucene.document.DateField;
36
37 /**
38  * A utility class for making a Lucene Document from a news Item
39  * object.
40  *
41  * @author Niko Schmuck (niko@nava.de)
42  */

43 public class ItemDocument implements ItemFieldConstants {
44
45   private ItemDocument() {
46   }
47
48   /**
49    * Makes a document for a ItemIF object.
50    * <p>
51    * The document has five fields:
52    * <ul>
53    * <li><code>title</code>--containing the title of the item,
54    * as a stored, tokenized field;
55    * <li><code>description</code>--containing the description of the
56    * item, as a stored, tokenized field;
57    * <li><code>titledesc</code>--containing the combination of the
58    * title and the description of the item, as a stored, tokenized
59    * field;
60    * <li><code>found</code>--containing the last modified date of
61    * the item as a keyword field as encoded by DateField;
62    * <li><code>id</code>--containing the identifier of
63    * the item as a unindexed field (for later retrieval).
64    * </ul>
65    */

66   public static Document makeDocument(ItemIF item) {
67     Document doc = new Document();
68     doc.add(Field.Text(TITLE, item.getTitle()));
69     doc.add(Field.Text(DESCRIPTION, item.getDescription()));
70     doc.add(Field.Text(TITLE_AND_DESC, item.getTitle() + " " +
71                        item.getDescription()));
72     // Keyword field is not tokenized for not breaking the date
73
if (item.getFound() != null) {
74       doc.add(Field.Keyword(DATE_FOUND,
75                             DateField.dateToString(item.getFound())));
76     }
77     // Unindexed field for later retrieval of the item
78
doc.add(Field.UnIndexed(ITEM_ID, Long.toString(item.getId())));
79     // Unindexed field for later retrieval of the channel
80
if (item.getChannel() != null) {
81       doc.add(Field.UnIndexed(CHANNEL_ID,
82                               Long.toString(item.getChannel().getId())));
83     }
84     return doc;
85   }
86   
87 }
88
Popular Tags