1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| package org.apache.xindice.tools.command; |
21 |
| |
22 |
| import org.apache.xindice.tools.XMLTools; |
23 |
| import org.apache.xindice.client.TextQueryService; |
24 |
| import org.xmldb.api.base.Collection; |
25 |
| import org.xmldb.api.base.ResourceIterator; |
26 |
| import org.xmldb.api.base.ResourceSet; |
27 |
| import org.xmldb.api.modules.XMLResource; |
28 |
| import org.xmldb.api.DatabaseManager; |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| public class TextQuery extends Command { |
37 |
| |
38 |
0
| public boolean execute(XMLTools.Config table) throws Exception {
|
39 |
0
| if (table.getString(XMLTools.COLLECTION) == null) {
|
40 |
0
| System.out.println("ERROR : Collection name and switch required");
|
41 |
0
| return false;
|
42 |
| } |
43 |
| |
44 |
0
| if ("".equals(table.getString(XMLTools.QUERY))) {
|
45 |
0
| System.out.println("ERROR : Query and switch required");
|
46 |
0
| return false;
|
47 |
| } |
48 |
| |
49 |
0
| Collection col = null;
|
50 |
0
| try {
|
51 |
0
| String colstring = normalizeCollectionURI(table.getString(XMLTools.COLLECTION),
|
52 |
| table.getBoolean(XMLTools.LOCAL)); |
53 |
0
| String querystring = table.getString(XMLTools.QUERY);
|
54 |
| |
55 |
0
| col = DatabaseManager.getCollection(colstring);
|
56 |
| |
57 |
0
| if (col == null) {
|
58 |
0
| System.out.println("ERROR : Collection not found!");
|
59 |
0
| return false;
|
60 |
| } |
61 |
| |
62 |
0
| TextQueryService service = (TextQueryService) col.getService("TextQueryService", "1.0");
|
63 |
| |
64 |
0
| ResourceSet resultSet = service.query(querystring);
|
65 |
0
| ResourceIterator results = resultSet.getIterator();
|
66 |
| |
67 |
0
| while (results.hasMoreResources()) {
|
68 |
0
| XMLResource resource = (XMLResource) results.nextResource();
|
69 |
0
| String documentstr = (String) resource.getContent();
|
70 |
0
| System.out.println(documentstr);
|
71 |
| } |
72 |
| } finally { |
73 |
0
| if (col != null) {
|
74 |
0
| col.close();
|
75 |
| } |
76 |
| } |
77 |
| |
78 |
0
| return true;
|
79 |
| } |
80 |
| |
81 |
0
| public void usage() {
|
82 |
0
| System.out.println("Format: xindice text -c <context> [-l [-d <path>]] [-v] [parameters...]");
|
83 |
0
| System.out.println();
|
84 |
0
| System.out.println("Searches collection for documents matching given text query");
|
85 |
0
| System.out.println();
|
86 |
0
| System.out.println("Command-specific switches:");
|
87 |
0
| System.out.println(" -q|--query <query>");
|
88 |
0
| System.out.println(" Lucene text query");
|
89 |
0
| System.out.println();
|
90 |
| } |
91 |
| } |