KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > websphinx > searchengine > SearchEngineResult


1 /*
2  * WebSphinx web-crawling toolkit
3  *
4  * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
20  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
23  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  */

32
33 package websphinx.searchengine;
34
35 import websphinx.*;
36
37 /**
38  * Result returned by a search engine query, identifying a Web page that matches the query.
39  */

40 public class SearchEngineResult extends Region {
41     /**
42      * Relevancy rank of page in search engine's ordering. In other words, rank=1
43      * is the first result the search engine returned. If search engine
44      * results are not explicitly numbered, then rank may be 0.
45      */

46     public int rank = 0;
47
48     /**
49      * Relevancy score of page, by search engine's scale. If search engine
50      * does not provide a score, the score defaults to 0.0.
51      *
52      */

53     public double score = 0.0;
54
55     /**
56      * Title of page as reported by search engine, or null if not provided
57      */

58     public String JavaDoc title;
59
60     /**
61      * Short description of page as reported by search engine. Typically the first few words
62      * of the page. If not provided, description is null.
63      */

64     public String JavaDoc description;
65
66     /**
67      * Link to the actual page.
68      */

69     public Link link;
70
71     /**
72      * Search engine that produced this hit.
73      */

74     public SearchEngine searchengine;
75
76     /**
77      * Make a SearchEngineResult.
78      * @param result Region of a search engine's results page. Should be annotated with rank, title,
79      * description, and link fields.
80      */

81     public SearchEngineResult (Region result) {
82         super (result);
83         rank = result.getNumericLabel ("rank", new Integer JavaDoc(0)).intValue();
84         score = result.getNumericLabel ("score", new Double JavaDoc(0)).doubleValue();
85         title = result.getLabel ("title");
86         description = result.getLabel ("description");
87         
88         try {
89             link = (Link)result.getField ("link");
90         } catch (ClassCastException JavaDoc e) {}
91         searchengine = (SearchEngine)result.getSource().getObjectLabel ("searchengine.source");
92     }
93
94     public String JavaDoc toString () {
95         return rank + ". " + title + " [" + (link!=null ? link.getURL ().toString() : "(null)") + "]" + " " + score + "\n"
96                + " " + description;
97     }
98 }
99
Popular Tags