KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > search > ParsedObjectImpl


1 package org.jahia.services.search;
2
3 import java.util.*;
4
5 /**
6  * <p>Title: Contains information returned by the search result as a map
7  * of fieldname/values pair.</p>
8  * <p>Description: </p>
9  * <p>Copyright: Copyright (c) 2004</p>
10  * <p>Company: </p>
11  *
12  * @author Khue Nguyen
13  * @version 1.0
14  */

15 public class ParsedObjectImpl implements ParsedObject {
16
17     private float score;
18     private Hashtable fields;
19
20     public ParsedObjectImpl(){
21         fields = new Hashtable();
22     }
23
24     public ParsedObjectImpl(float score, Hashtable fields){
25         this.score = score;
26         this.fields = fields;
27         if ( this.fields == null ){
28             fields = new Hashtable();
29         }
30     }
31
32     /**
33      * Returns the score
34      *
35      * @return float
36      */

37     public float getScore(){
38         return this.score;
39     }
40
41     /**
42      * Set the score
43      *
44      * @param score float
45      */

46     public void setScore(float score){
47         this.score = score;
48     }
49
50     /**
51      * Return an hastable of fieldname/values pair of information as they were
52      * stored through the use of a JahiaIndexableDocument by the search engine
53      *
54      * the key is the field name and the values is an array of string values
55      *
56      * @return
57      */

58     public Hashtable getFields (){
59         if ( this.fields == null ){
60             this.fields = new Hashtable();
61         }
62         return this.fields;
63     }
64
65     public void setFields (Hashtable fields){
66         this.fields = fields;
67     }
68
69     /**
70      * Return an array of value for the given field
71      * @param fieldName String
72      * @return String[]
73      */

74     public String JavaDoc[] getValues(String JavaDoc fieldName){
75         String JavaDoc[] values = new String JavaDoc[0];
76         if ( fieldName != null ){
77             values = (String JavaDoc[])getFields().get(fieldName);
78         }
79         if ( values == null ){
80             values = new String JavaDoc[0];
81         }
82         return values;
83     }
84
85     /**
86      * Return the first value available for the given field
87      * @return String
88      */

89     public String JavaDoc getValue(String JavaDoc fieldName){
90         String JavaDoc[] values = getValues(fieldName);
91         if ( values.length == 0 ){
92             return null;
93         }
94         return values[0];
95     }
96
97 }
98
Popular Tags