001: /*
002: * WebSphinx web-crawling toolkit
003: *
004: * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
005: * reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
020: * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
021: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
022: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
023: * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
024: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
025: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
029: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030: *
031: */
032:
033: package websphinx.searchengine;
034:
035: import websphinx.*;
036:
037: /**
038: * Result returned by a search engine query, identifying a Web page that matches the query.
039: */
040: public class SearchEngineResult extends Region {
041: /**
042: * Relevancy rank of page in search engine's ordering. In other words, rank=1
043: * is the first result the search engine returned. If search engine
044: * results are not explicitly numbered, then rank may be 0.
045: */
046: public int rank = 0;
047:
048: /**
049: * Relevancy score of page, by search engine's scale. If search engine
050: * does not provide a score, the score defaults to 0.0.
051: *
052: */
053: public double score = 0.0;
054:
055: /**
056: * Title of page as reported by search engine, or null if not provided
057: */
058: public String title;
059:
060: /**
061: * Short description of page as reported by search engine. Typically the first few words
062: * of the page. If not provided, description is null.
063: */
064: public String description;
065:
066: /**
067: * Link to the actual page.
068: */
069: public Link link;
070:
071: /**
072: * Search engine that produced this hit.
073: */
074: public SearchEngine searchengine;
075:
076: /**
077: * Make a SearchEngineResult.
078: * @param result Region of a search engine's results page. Should be annotated with rank, title,
079: * description, and link fields.
080: */
081: public SearchEngineResult(Region result) {
082: super (result);
083: rank = result.getNumericLabel("rank", new Integer(0))
084: .intValue();
085: score = result.getNumericLabel("score", new Double(0))
086: .doubleValue();
087: title = result.getLabel("title");
088: description = result.getLabel("description");
089:
090: try {
091: link = (Link) result.getField("link");
092: } catch (ClassCastException e) {
093: }
094: searchengine = (SearchEngine) result.getSource()
095: .getObjectLabel("searchengine.source");
096: }
097:
098: public String toString() {
099: return rank + ". " + title + " ["
100: + (link != null ? link.getURL().toString() : "(null)")
101: + "]" + " " + score + "\n" + " " + description;
102: }
103: }
|