1 32 33 package websphinx.searchengine; 35 import websphinx.*; 36 import java.net.URL ; 37 import java.net.URLEncoder ; 38 import java.net.MalformedURLException ; 39 40 44 public class Excite implements SearchEngine { 45 46 static Pattern patCount = new Regexp ( 47 "<font size=-1 face=\"arial, helvetica\">(?:About )?<b>(\\d+)</b> documents? match your query."); 48 static Pattern patNoHits = new Regexp ( 49 "No documents match the query." 50 ); 51 52 static Pattern patResult = new Tagexp ( 53 "<FONT COLOR=navy><B>(?{score})</B></FONT>" + "<B>(?{link}<a>(?{title})</a>)</B>" + "<BR><B><I></I></B>" + "<BR><B><I></I></B>(?{description})" + "<BR><B><I></I></B><a><p></a>" ); 59 60 static Pattern patMoreLink = new Tagexp ( 61 "<INPUT TYPE=submit NAME=next VALUE=\"Next Results\">" 62 ); 63 64 75 public void classify (Page page) { 76 String title = page.getTitle (); 77 if (title != null && 78 (title.startsWith ("Excite Search Results"))) { 79 page.setObjectLabel ("searchengine.source", this); 80 81 Region count = patCount.oneMatch (page); 82 if (count != null) 83 page.setField ("searchengine.count", count.getField ("0")); 84 85 Region[] results = patResult.allMatches (page); 86 SearchEngineResult[] ser = new SearchEngineResult[results.length]; 87 for (int i=0; i<results.length; ++i) 88 ser[i] = new SearchEngineResult (results[i]); 89 page.setFields ("searchengine.results", ser); 90 91 PatternMatcher m = patMoreLink.match (page); 92 while (m.hasMoreElements ()) { 93 Link link = (Link)m.nextMatch (); 94 link.setLabel ("searchengine.more-results"); 95 link.setLabel ("hyperlink"); 96 } 97 } 98 } 99 100 103 public static final float priority = 0.0F; 104 105 109 public float getPriority () { 110 return priority; 111 } 112 113 118 public URL makeQuery (String keywords) { 119 try { 120 return new URL ("http://www.excite.com/search.gw?trace=a&search=" 121 + URLEncoder.encode(keywords)); 122 } catch (MalformedURLException e) { 123 throw new RuntimeException ("internal error"); 124 } 125 } 126 127 131 public int getResultsPerPage () { 132 return 10; 133 } 134 135 140 public static Search search (String keywords) { 141 return new Search(new Excite(), keywords); 142 } 143 144 151 public static Search search (String keywords, int maxResults) { 152 return new Search (new Excite(), keywords, maxResults); 153 } 154 } 155
| Popular Tags
|