1
1
/*************************************************************************************************
2
2
* Pure Java interface of Hyper Estraier
3
* Copyright (C) 2004-2005 Mikio Hirabayashi
3
* Copyright (C) 2004-2006 Mikio Hirabayashi
4
4
* All rights reserved.
5
5
* This file is part of Hyper Estraier.
6
6
* Redistribution and use in source and binary forms, with or without modification, are
67
67
sb.append(URLEncoder.encode((String)it.next(), "UTF-8"));
69
69
String order = cond.order();
70
if(order != null && order.length() > 0){
71
71
sb.append("&order=");
72
72
sb.append(URLEncoder.encode(order, "UTF-8"));
79
79
sb.append("&max=");
80
sb.append(Integer.MAX_VALUE);
80
sb.append(Integer.MAX_VALUE / 2);
82
82
int options = cond.options();
84
84
sb.append("&options=");
85
85
sb.append(options);
87
int auxiliary = cond.auxiliary();
88
sb.append("&auxiliary=");
90
String distinct = cond.distinct();
91
if(distinct != null && distinct.length() > 0){
92
sb.append("&distinct=");
93
sb.append(URLEncoder.encode(distinct, "UTF-8"));
88
96
sb.append("&depth=");
201
* Synchronize updating contents of the database.
202
* @return true if success, else it is false.
204
public boolean sync(){
206
if(url == null) return false;
208
URL purl = new URL(url);
209
URL eurl = new URL("http://" + purl.getHost() + ":" + purl.getPort() +
210
purl.getPath() + "/sync");
211
List reqheads = new ArrayList(2);
213
reqheads.add("Authorization: Basic " + Utility.base_encode(auth.getBytes()));
214
reqheads.add("Content-Type: application/x-www-form-urlencoded");
215
byte[] reqbody = new byte[0];
216
status = Utility.shuttle_url(eurl.toString(), pxhost, pxport, timeout,
217
reqheads, reqbody, null, null);
218
if(status != 200) return false;
220
} catch(Exception e){
225
* Optimize the database.
226
* @return true if success, else it is false.
228
public boolean optimize(){
230
if(url == null) return false;
232
URL purl = new URL(url);
233
URL eurl = new URL("http://" + purl.getHost() + ":" + purl.getPort() +
234
purl.getPath() + "/optimize");
235
List reqheads = new ArrayList(2);
237
reqheads.add("Authorization: Basic " + Utility.base_encode(auth.getBytes()));
238
reqheads.add("Content-Type: application/x-www-form-urlencoded");
239
byte[] reqbody = new byte[0];
240
status = Utility.shuttle_url(eurl.toString(), pxhost, pxport, timeout,
241
reqheads, reqbody, null, null);
242
if(status != 200) return false;
244
} catch(Exception e){
183
249
* Add a document.
184
250
* @param doc a document object to register.
185
251
* @return true if success, else it is false.
520
* Get the size of the datbase of a node.
521
* @return the size of the datbase of the node. On error, -1.0 is returned.
586
* Get the size of the datbase.
587
* @return the size of the datbase. On error, -1.0 is returned.
523
589
public double size(){
524
590
if(size < 0.0) set_info();
528
* Search documents corresponding a condition.
594
* Get the usage ratio of the cache.
595
* @return the usage ratio of the cache. On error, -1.0 is returned.
597
public double cache_usage(){
599
if(url == null) return -1.0;
601
URL purl = new URL(url);
602
URL eurl = new URL("http://" + purl.getHost() + ":" + purl.getPort() +
603
purl.getPath() + "/cacheusage");
604
List reqheads = new ArrayList(2);
606
reqheads.add("Authorization: Basic " + Utility.base_encode(auth.getBytes()));
607
ByteArrayOutputStream resbody = new ByteArrayOutputStream();
608
status = Utility.shuttle_url(eurl.toString(), pxhost, pxport, timeout,
609
reqheads, null, null, resbody);
610
if(status != 200) return -1.0;
611
return Double.parseDouble(resbody.toString("UTF-8").trim());
612
} catch(Exception e){
617
* Get a list of names of administrators.
618
* @return a list object of names of administrators. On error, `null' is returned.
620
public List admins(){
621
if(admins == null) set_info();
625
* Get a list of names of users.
626
* @return a list object of names of users. On error, `null' is returned.
629
if(users == null) set_info();
633
* Get a list of expressions of links.
634
* @return a list object of expressions of links. Each element is a TSV string and has three
635
* fields of the URL, the label, and the score. On error, `null' is returned.
638
if(links == null) set_info();
642
* Search for documents corresponding a condition.
529
643
* @param cond a condition object.
530
644
* @param depth the depth of meta search.
531
645
* @return a node result object. On error, `null' is returned.
838
if(lines.length < 2) return;
840
if(lnum < lines.length && lines[lnum].length() < 1) lnum++;
841
admins = new ArrayList();
842
while(lnum < lines.length){
843
String line = lines[lnum];
844
if(line.length() < 1) break;
848
if(lnum < lines.length && lines[lnum].length() < 1) lnum++;
849
users = new ArrayList();
850
while(lnum < lines.length){
851
String line = lines[lnum];
852
if(line.length() < 1) break;
856
if(lnum < lines.length && lines[lnum].length() < 1) lnum++;
857
links = new ArrayList();
858
while(lnum < lines.length){
859
String line = lines[lnum];
860
if(line.length() < 1) break;
861
if(Utility.split_fields(line).length == 3) links.add(line);
724
864
} catch(Exception e){