-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSampleQueryIntegrationTest.java
More file actions
83 lines (70 loc) · 2.51 KB
/
SampleQueryIntegrationTest.java
File metadata and controls
83 lines (70 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package voyager.quickstart.query;
import java.net.URL;
import org.apache.abdera.Abdera;
import org.apache.abdera.ext.geo.GeoHelper;
import org.apache.abdera.ext.geo.Position;
import org.apache.abdera.model.Document;
import org.apache.abdera.model.Entry;
import org.apache.abdera.model.Feed;
import org.apache.abdera.model.Link;
import org.apache.abdera.parser.Parser;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.junit.Test;
import voyager.api.domain.model.entry.DexField;
import voyager.quickstart.IntegrationBase;
/**
* TODO: theses tests need to make sure something is in the index
* so we can assert that the queries work. For now they simply
* show the plumbing
*/
public class SampleQueryIntegrationTest extends IntegrationBase {
/**
* A simple sample using solrj
*/
@Test
public void simpleQueryWithSolrj() throws Exception {
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
QueryResponse rsp = solr.query(query);
SolrDocumentList docs = rsp.getResults();
System.out.println( "Found: "+docs.getNumFound() );
for(SolrDocument doc : docs) {
System.out.println( "Doc: "+doc.get("id")
+ "\t: " + doc.get(DexField.NAME.name)
+ "\t: " + doc.get(DexField.BBOX.name));
}
}
/**
* A simple example using Abdera
*/
@Test
public void simpleOpensearchQuery() throws Exception {
String feedURL = baseURL + "feed/atom.xml";
Abdera abdera = new Abdera();
Parser parser = abdera.getParser();
URL url = new URL(feedURL);
Document<Feed> doc = parser.parse(url.openStream(), url.toString());
Feed feed = doc.getRoot();
// Get the feed title
System.out.println("Feed Title: " + feed.getTitle());
// Get the entry items...
for (Entry entry : feed.getEntries()) {
System.out.println("------");
System.out.println("Title: " + entry.getTitle());
System.out.println("Unique Identifier: " + entry.getId().toString());
System.out.println("Updated Date: " + entry.getUpdated().toString());
System.out.println("Published Date: " + entry.getPublished());
// Get the links
for (Link link : entry.getLinks()) {
System.out.println("Link: " + link.getHref());
}
// Read the position
for(Position p : GeoHelper.getPositions(entry)) {
System.out.println( "Position: "+p);
}
}
}
}