summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorreger <reger18@arcor.de>2016-03-14 02:22:06 +0100
committerreger <reger18@arcor.de>2016-03-14 02:22:06 +0100
commit6783ef5540d630fc8c7543531c6ca32f1e47db79 (patch)
treea67f38e5c575733c6ff2f5dd0de091cc564e5f75
parent6a8f3f3ebaf3fae8e082fc3ee6188ae1917fa937 (diff)
move example code SearchClient out of yacycore package
to example directory
-rw-r--r--examples/SimpleSearchClient/pom.xml20
-rw-r--r--examples/SimpleSearchClient/src/YaCySearchClient.java (renamed from source/net/yacy/YaCySearchClient.java)32
2 files changed, 40 insertions, 12 deletions
diff --git a/examples/SimpleSearchClient/pom.xml b/examples/SimpleSearchClient/pom.xml
new file mode 100644
index 000000000..87b8c08b3
--- /dev/null
+++ b/examples/SimpleSearchClient/pom.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>net.yacy</groupId>
+ <artifactId>SimpleSearchClient</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+ <description>Simple search client example to query YaCy and receive search results as RSS feed</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>1.7</maven.compiler.source>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ </properties>
+
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ </build>
+
+</project> \ No newline at end of file
diff --git a/source/net/yacy/YaCySearchClient.java b/examples/SimpleSearchClient/src/YaCySearchClient.java
index 77db5a4cf..0c2a6f535 100644
--- a/source/net/yacy/YaCySearchClient.java
+++ b/examples/SimpleSearchClient/src/YaCySearchClient.java
@@ -23,18 +23,17 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
-package net.yacy;
+package net.yacy.simplesearchclient;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.regex.Pattern;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import net.yacy.cora.util.CommonPattern;
-
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -55,6 +54,7 @@ public class YaCySearchClient {
private final String host, query;
private final int port;
private int offset;
+ private final static Pattern SPACE = Pattern.compile(" ");
public YaCySearchClient(final String host, final int port, final String query) {
this.host = host;
@@ -80,7 +80,7 @@ public class YaCySearchClient {
.append("/yacysearch.rss?verify=false&startRecord=")
.append(YaCySearchClient.this.offset)
.append("&maximumRecords=10&resource=local&query=")
- .append(CommonPattern.SPACE.matcher(YaCySearchClient.this.query).replaceAll("+")).toString();
+ .append(SPACE.matcher(YaCySearchClient.this.query).replaceAll("+")).toString();
try { url = new URL(u); } catch (final MalformedURLException e) { throw new IOException (e); }
try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url.openStream()); }
catch (final ParserConfigurationException e) { throw new IOException (e); }
@@ -131,14 +131,22 @@ public class YaCySearchClient {
* Use this method as stub for an integration in your own programs
*/
public static void main(String[] args) {
- for (String query: args) try {
- long t = System.currentTimeMillis();
- YaCySearchClient search = new YaCySearchClient("localhost", 8090, query);
- System.out.println("Search result for '" + query + "':");
- System.out.print(search.next().toString()); // get 10 results; you may repeat this for next 10
- System.out.println("Search Time: " + (System.currentTimeMillis() - t) + " milliseconds\n");
- } catch (final IOException e) {
- e.printStackTrace();
+ if (args.length < 1) {
+ System.out.println("No query string as argument found.");
+ System.out.println("Call the main method with one argument, the query string,");
+ System.out.println("while YaCy is running on localhost.");
+ } else {
+ for (String query : args) {
+ try {
+ long t = System.currentTimeMillis();
+ YaCySearchClient search = new YaCySearchClient("localhost", 8090, query);
+ System.out.println("Search result for '" + query + "':");
+ System.out.print(search.next().toString()); // get 10 results; you may repeat this for next 10
+ System.out.println("Search Time: " + (System.currentTimeMillis() - t) + " milliseconds\n");
+ } catch (final IOException e) {
+ e.printStackTrace();
+ }
+ }
}
}
}