Search in sources :

Example 1 with MatchCollector

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();
}
Also used : Response(de.ids_mannheim.korap.response.Response) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) MatchCollectorDB(de.ids_mannheim.korap.response.collector.MatchCollectorDB) Krill(de.ids_mannheim.korap.Krill) SQLException(java.sql.SQLException) MatchCollector(de.ids_mannheim.korap.response.MatchCollector) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 2 with MatchCollector

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);
}
Also used : Krill(de.ids_mannheim.korap.Krill) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) MatchCollector(de.ids_mannheim.korap.response.MatchCollector) Test(org.junit.Test)

Example 3 with MatchCollector

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);
}
Also used : MatchCollectorDB(de.ids_mannheim.korap.response.collector.MatchCollectorDB) MatchCollector(de.ids_mannheim.korap.response.MatchCollector) Test(org.junit.Test)

Aggregations

MatchCollector (de.ids_mannheim.korap.response.MatchCollector)3 Krill (de.ids_mannheim.korap.Krill)2 MatchCollectorDB (de.ids_mannheim.korap.response.collector.MatchCollectorDB)2 Test (org.junit.Test)2 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 KrillIndex (de.ids_mannheim.korap.KrillIndex)1 Response (de.ids_mannheim.korap.response.Response)1 SQLException (java.sql.SQLException)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Term (org.apache.lucene.index.Term)1 SpanQuery (org.apache.lucene.search.spans.SpanQuery)1 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)1