📄 editorialsearchonecollection.java
字号:
/* -*- mode:java; indent-tabs-mode:nil; c-basic-offset:2 -*- * * $RCSFile$ $Revision: 1.12 $ $Date: 2006/02/01 00:20:31 $ * * Copyright (c) 2002 Autonomy Corp. All Rights Reserved. * Permission to use, copy, modify, and distribute this file is hereby * granted without fee, provided that the above copyright notice appear * in all copies. */import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.*;import com.ultraseek.xpa.search.*;import com.ultraseek.xpa.server.UltraseekServer;/** * A simple demo application that demonstrates how the EditorialSearchable * works. It does a preliminary search of the Ultraseek collection * and prepends two of the search results from here to all subsequent * query results. */public class EditorialSearchOneCollection { /** How many Editorial results to collect */ public final static int EDITORIAL_RESULTS = 2; /** How many results to print */ public final static int MAX_RESULTS = EDITORIAL_RESULTS + 2; public final static boolean VERBOSE = false; public EditorialSearchOneCollection() { } /** Utility function to print out verbose messages */ public static void VerbosePrint(String msg) { if (VERBOSE) System.out.println(msg); } public static void main(String[] args) throws Exception { InputStreamReader inputStreamReader = new InputStreamReader(System.in); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); System.out.println(); System.out.println("This is a simple demo application that does an"); System.out.println("initial search of the Ultraseek collection,"); System.out.println("uses the first two results to form an editorial list"); System.out.println("which provides the initial results of later"); System.out.println("searches."); System.out.println(); System.out.println("Enter the hostname and TCP port of your"); System.out.println("running Ultraseek instance."); System.out.print("hostname: "); String host = bufferedReader.readLine(); System.out.print("TCP port: "); int port = Integer.parseInt(bufferedReader.readLine()); SearchServer searchServer = new UltraseekServer(host,port); System.out.println(); VerbosePrint("Here is the SearchServer object:\n" + searchServer); System.out.println(); System.out.println("Enter the internal name of the collection."); System.out.print("collection: "); String id = bufferedReader.readLine(); SearchCollection searchCollection = searchServer.getSearchCollection(id); System.out.println(); VerbosePrint("Here is the SearchCollection object:\n" + searchCollection); System.out.println(); System.out.println("Enter an initial query. The first two results from"); System.out.println("this will be used to form the editorial list"); System.out.print("search: "); String line = bufferedReader.readLine(); FixedSearchable fixedSearchable = new FixedSearchable(); if (line!=null) { Query query = Query.parse(line); SearchResultList searchResultList = searchCollection.search(query); System.out.println("There are about " + searchResultList.getResultCount() + " results." ); FixedSearchResultList fixedList = new FixedSearchResultList(); int count = 0; try { Iterator iterator = searchResultList.iterator(); while (iterator.hasNext() && count++ < EDITORIAL_RESULTS) { SearchResult searchResult = (SearchResult)iterator.next(); fixedList.add(searchResult); } } catch (NoSuchElementException e) { /* No more results from server, not an error. */ } System.out.println("The first " + fixedList.size() + " results will be prepended to each query result." ); fixedSearchable.setResultList(fixedList); } EditorialSearchable edS; edS = new EditorialSearchable(fixedSearchable, searchCollection, DedupingSearchable.URL_CMP); System.out.println(); VerbosePrint("Here is the EditorialSearchable object:\n" + edS); for (;;) { System.out.println(); System.out.println("Enter a query."); System.out.print("search: "); line = bufferedReader.readLine(); if (line==null) break; Query query = Query.parse(line); System.out.println(); VerbosePrint("Here is the Query object:\n" + query); SearchResultList searchResultList = edS.search(query); System.out.println(); VerbosePrint("Here is the SearchResultList object:\n" + searchResultList); Collection relatedTopics = searchResultList.getRelatedTopics(); System.out.println(); if (!relatedTopics.isEmpty()) { System.out.println("Here are the SearchTopic objects:"); Iterator iterator = relatedTopics.iterator(); while (iterator.hasNext()) { SearchTopic searchTopic = (SearchTopic)iterator.next(); System.out.println(searchTopic); } } else { System.out.println("There are no SearchTopic objects."); } System.out.println(); if (!searchResultList.isEmpty()) { System.out.println("There are about " + searchResultList.getResultCount() + " results." ); System.out.println("Here are the SearchResult objects:"); Iterator iterator = searchResultList.iterator(); try { int count = 0; while (iterator.hasNext() && count++ < MAX_RESULTS) { SearchResult searchResult = (SearchResult)iterator.next(); System.out.println(); if (VERBOSE) System.out.println("" + count + " " + searchResult); else System.out.println("" + count + " " + searchResult.getURL() + "\n" + " " + searchResult.getTitle() ); } } catch (NoSuchElementException e) { /* No more results from server, not an error. */ } } else { System.out.println("There are no SearchResult objects."); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -