use of de.ids_mannheim.korap.response.MatchCollector in project Krill by KorAP.
the class Resource method collect.
/**
* Collect matches and aggregate the UIDs plus matchcount in the
* database.
*
* @param text_id
*/
@PUT
@Path("/collect/{resultID}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String collect(String json, @PathParam("resultID") String resultID, @Context UriInfo uri) {
Response kresp = _initResponse();
if (kresp.hasErrors())
return kresp.toJsonString();
// Get the database
try {
final MatchCollectorDB mc = new MatchCollectorDB(1000, "Res_" + resultID);
final ComboPooledDataSource pool = Node.getDBPool();
mc.setDBPool("mysql", pool, pool.getConnection());
// TODO: Only search in self documents (REPLICATION FTW!)
final Krill ks = new Krill(json);
// TODO: Reuse response!
final MatchCollector result = Node.getIndex().collect(ks, mc);
result.setNode(Node.getName());
return result.toJsonString();
} catch (SQLException e) {
log.error(e.getLocalizedMessage());
}
;
kresp.addError(604, "Unable to connect to database");
return kresp.toJsonString();
}
use of de.ids_mannheim.korap.response.MatchCollector in project Krill by KorAP.
the class TestMatchCollector method indexExample1.
@Test
public void indexExample1() throws IOException {
KrillIndex ki = new KrillIndex();
// abcabcabac
FieldDocument fd = new FieldDocument();
fd.addString("ID", "doc-1");
fd.addString("UID", "1");
fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:c|i:c|_2$<i>2<i>3]" + "[(3-4)s:a|i:a|_3$<i>3<i>4]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]" + "[(6-7)s:a|i:a|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:a|i:a|_8$<i>8<i>9]" + "[(9-10)s:c|i:c|_9$<i>9<i>10]");
ki.addDoc(fd);
fd = new FieldDocument();
fd.addString("ID", "doc-2");
fd.addString("UID", "2");
fd.addTV("base", "bcbabd", "[(0-1)s:b|i:b|_1$<i>0<i>1]" + "[(1-2)s:c|i:c|s:b|_2$<i>1<i>2]" + "[(2-3)s:b|i:b|_3$<i>2<i>3|<>:e#2-4$<i>4]" + "[(3-4)s:a|i:a|_4$<i>3<i>4|<>:e#3-5$<i>5|<>:e2#3-5$<i>5]" + "[(4-5)s:b|i:b|s:c|_5$<i>4<i>5]" + "[(5-6)s:d|i:d|_6$<i>5<i>6|<>:e2#5-6$<i>6]");
ki.addDoc(fd);
ki.commit();
SpanQuery sq;
sq = new SpanTermQuery(new Term("base", "s:b"));
Krill krill = new Krill(sq);
krill.getMeta().setCount((short) 10);
MatchCollector mc = ki.collect(krill, new MatchCollector());
assertEquals(mc.getTotalResults(), 5);
assertEquals(mc.getTotalResultDocs(), 2);
}
use of de.ids_mannheim.korap.response.MatchCollector in project Krill by KorAP.
the class TestDatabase method TestMatchCollectorDB.
@Test
public void TestMatchCollectorDB() throws Exception {
MatchCollector mc = new MatchCollectorDB(2000, "matchXYZ");
mc.add(5, 7);
mc.add(8, 2);
mc.add(9, 10);
mc.add(16, 90);
mc.commit();
assertEquals(mc.getTotalResults(), 109);
assertEquals(mc.getTotalResultDocs(), 4);
}
Aggregations