summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwjoe <joe@lc8n.com>2013-09-24 15:16:24 +0100
committerwjoe <joe@lc8n.com>2013-09-24 15:16:24 +0100
commit8744dee4f21263c4da72116aa3920e850abd0366 (patch)
treec3a0e58bfdb9bc384b555d0439db4f11597da515
parent9b2b57aab41337005912a0003e5c8700556bc607 (diff)
Added options to get more results with -n
-rwxr-xr-xblasearch.java34
1 files changed, 29 insertions, 5 deletions
diff --git a/blasearch.java b/blasearch.java
index 6ca2295..74ce079 100755
--- a/blasearch.java
+++ b/blasearch.java
@@ -32,7 +32,7 @@ public class blasearch {
{
String query = "";
- String version = "v1.2.1";
+ String version = "v1.5.0";
/* Build query from query or arguments, depending on whether
arguments were given. */
@@ -54,12 +54,36 @@ public class blasearch {
System.out.println(version);
System.exit(0);
}
+ String[] qParts = query.split(" ");
+ int offset = 0;
+ int start = 0;
+ query = "";
+ for (int i = 0; i < qParts.length; i++) {
+ if (qParts[i].equals("-n") && i < qParts.length-1) {
+ try {
+ if(Integer.parseInt(qParts[i+1]) > 0) {
+ offset = Integer.parseInt(qParts[i+1])-1;
+ start = (offset / 2)*4;
+ offset = (offset %2)*2;
+ i++;
+ } else {
+ start = 0;
+ offset = 0;
+ i++;
+ }
+ } catch (NumberFormatException e) {
+ start = 0;
+ offset = 0;
+ }
+ } else {
+ query += qParts[i]+"+";
+ }
+ }
// Change all ' ' to '+'
query = query.replaceAll(" ", "+");
-
String[] parts = null;
//URL which provides XML response
- URL url = new URL("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="+ query);
+ URL url = new URL("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="+ query+"&start="+start);
URLConnection urlc = url.openConnection();
@@ -98,12 +122,12 @@ public class blasearch {
}
// Print results
if(results.size() > 0){
- for(int i=0; i<2; i++){
+ for(int i=(offset); i<(offset+2); i++){
if (i != 0) {
System.out.print(" | ");
}
int count = i + 1;
- System.out.print("Result " + count + ": " + results.get(i));
+ System.out.print("Result " + (count+start) + ": " + results.get(i));
}
} else {
System.out.print("Error: no results.\n");