📄 searchlocale.java
字号:
/* -*- mode:java; indent-tabs-mode:nil; c-basic-offset:2 -*- * * $RCSFile$ $Revision: 1.7 $ $Date: 2006/02/01 00:20:29 $ * * 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.io.IOException;import java.util.Collection;import java.util.Iterator;import java.util.NoSuchElementException;import java.util.Locale;import com.ultraseek.xpa.search.LocaleSearchable;import com.ultraseek.xpa.search.Query;import com.ultraseek.xpa.search.SearchResult;import com.ultraseek.xpa.search.SearchResultList;import com.ultraseek.xpa.search.SearchServer;import com.ultraseek.xpa.search.SearchTopic;import com.ultraseek.xpa.search.Searchable;import com.ultraseek.xpa.server.UltraseekServer;/** * A simple demo application that searches * two running Ultraseek instances, and * chooses which instance to search based on the Locale of * the query. */public class SearchLocale { SearchLocale() { } /** * Number of results to print as part of the sample output. */ static final int MAX_RESULTS = 2; public static Locale inputLocale(BufferedReader in, String prompt) throws IOException { System.out.println(prompt); System.out.print("Enter locale language: "); String lang = in.readLine().trim(); System.out.print("Enter locale country: "); String country = in.readLine().trim(); System.out.print("Enter locale variant: "); String variant = in.readLine().trim(); return new Locale(lang,country,variant); } 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 searches"); System.out.println("two running Ultraseek instances."); System.out.println(); System.out.println("Enter the hostname and TCP port of your"); System.out.println("first running Ultraseek instance."); System.out.print("hostname: "); String host1 = bufferedReader.readLine(); System.out.print("TCP port: "); int port1 = Integer.parseInt(bufferedReader.readLine()); SearchServer searchServer1 = new UltraseekServer(host1,port1); Locale locale1 = inputLocale(bufferedReader,"Enter search Locale for server1"); System.out.println(); System.out.println("Here is the SearchServer object:"); System.out.println(searchServer1); System.out.println(); System.out.println("Enter the hostname and TCP port of your"); System.out.println("second running Ultraseek instance."); System.out.print("hostname: "); String host2 = bufferedReader.readLine(); System.out.print("TCP port: "); int port2 = Integer.parseInt(bufferedReader.readLine()); SearchServer searchServer2 = new UltraseekServer(host2,port2); Locale locale2 = inputLocale(bufferedReader,"Enter search Locale for server1"); System.out.println(); System.out.println("Here is the SearchServer object:"); System.out.println(searchServer2); LocaleSearchable searchable = new LocaleSearchable(); searchable.put(locale1,(Searchable)searchServer1); searchable.put(locale2,(Searchable)searchServer2); System.out.println(); System.out.println("Here is the Searchable object:"); System.out.println(searchable); for (;;) { System.out.println(); System.out.println("Enter a query."); System.out.print("search: "); String line = bufferedReader.readLine(); if (line==null) break; Locale queryLocale = inputLocale(bufferedReader, "Input Locale for this query"); Query query = Query.parse(line,queryLocale); System.out.println(); System.out.println("Here is the Query object:"); System.out.println(query); SearchResultList searchResultList = searchable.search(query); System.out.println(); System.out.println("Here is the SearchResultList object:"); System.out.println(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 " + searchResultList.getResultCount() + " search results."); System.out.println("Here are the SearchResult objects:"); Iterator iterator = searchResultList.iterator(); int counter = 0; try { while (iterator.hasNext() && counter++ < MAX_RESULTS) { SearchResult searchResult = (SearchResult)iterator.next(); System.out.println(); System.out.println(searchResult); } } 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 + -