Search in sources :

Example 1 with TestAtomQueryFactory

use of won.matcher.solr.query.factory.TestAtomQueryFactory in project webofneeds by researchstudio-sat.

the class SolrMatcherQueryTest method main.

public static void main(String[] args) throws IOException, InterruptedException, JsonLdError, SolrServerException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SolrTestAppConfiguration.class);
    HintBuilder hintBuilder = ctx.getBean(HintBuilder.class);
    // DefaultMatcherQueryExecuter queryExecutor =
    // ctx.getBean(DefaultMatcherQueryExecuter.class);
    TestMatcherQueryExecutor queryExecutor = ctx.getBean(TestMatcherQueryExecutor.class);
    // set the options of the atom producer (e.g. if it should exhaust) in the
    // SolrAtomIndexerAppConfiguration file
    AtomProducer atomProducer = ctx.getBean(RoundRobinCompositeAtomProducer.class);
    while (!atomProducer.isExhausted()) {
        // && atoms < 20) {
        Dataset ds = atomProducer.create();
        try {
            TestAtomQueryFactory atomQuery = new TestAtomQueryFactory(ds);
            String query = atomQuery.createQuery();
            System.out.println("execute query: " + query);
            SolrDocumentList docs = queryExecutor.executeAtomQuery(query, 20, null, new BasicAtomQueryFactory(ds).createQuery());
            SolrDocumentList matchedDocs = hintBuilder.calculateMatchingResults(docs);
            System.out.println("Found docs: " + ((docs != null) ? docs.size() : 0) + ", keep docs: " + ((matchedDocs != null) ? matchedDocs.size() : 0));
            if (docs == null) {
                continue;
            }
            System.out.println("Keep docs: ");
            System.out.println("======================");
            for (SolrDocument doc : matchedDocs) {
                String score = doc.getFieldValue("score").toString();
                String matchedAtomId = doc.getFieldValue("id").toString();
                System.out.println("Score: " + score + ", Id: " + matchedAtomId);
            }
            System.out.println("All docs: ");
            System.out.println("======================");
            for (SolrDocument doc : docs) {
                String score = doc.getFieldValue("score").toString();
                String matchedAtomId = doc.getFieldValue("id").toString();
                System.out.println("Score: " + score + ", Id: " + matchedAtomId);
            }
        } catch (SolrException e) {
            System.err.println(e);
        }
    }
    System.exit(0);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SolrDocument(org.apache.solr.common.SolrDocument) Dataset(org.apache.jena.query.Dataset) TestAtomQueryFactory(won.matcher.solr.query.factory.TestAtomQueryFactory) TestMatcherQueryExecutor(won.matcher.solr.query.TestMatcherQueryExecutor) HintBuilder(won.matcher.solr.hints.HintBuilder) BasicAtomQueryFactory(won.matcher.solr.query.factory.BasicAtomQueryFactory) SolrDocumentList(org.apache.solr.common.SolrDocumentList) AtomProducer(won.bot.framework.component.atomproducer.AtomProducer) RoundRobinCompositeAtomProducer(won.bot.framework.component.atomproducer.impl.RoundRobinCompositeAtomProducer) SolrException(org.apache.solr.common.SolrException)

Example 2 with TestAtomQueryFactory

use of won.matcher.solr.query.factory.TestAtomQueryFactory in project webofneeds by researchstudio-sat.

the class SolrMatcherEvaluation method computeMatchingAtoms.

private List<String> computeMatchingAtoms(Dataset atom) throws IOException, SolrServerException {
    TestAtomQueryFactory atomQuery = new TestAtomQueryFactory(atom);
    SolrDocumentList docs = queryExecutor.executeAtomQuery(atomQuery.createQuery(), 20, null, new BasicAtomQueryFactory(atom).createQuery());
    SolrDocumentList matchedDocs = hintBuilder.calculateMatchingResults(docs);
    List<String> matchedAtoms = new LinkedList<>();
    for (SolrDocument doc : matchedDocs) {
        String matchedAtomId = doc.getFieldValue("id").toString();
        matchedAtoms.add(matchedAtomId);
    }
    return matchedAtoms;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) TestAtomQueryFactory(won.matcher.solr.query.factory.TestAtomQueryFactory) BasicAtomQueryFactory(won.matcher.solr.query.factory.BasicAtomQueryFactory) SolrDocumentList(org.apache.solr.common.SolrDocumentList) LinkedList(java.util.LinkedList)

Aggregations

SolrDocument (org.apache.solr.common.SolrDocument)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2 BasicAtomQueryFactory (won.matcher.solr.query.factory.BasicAtomQueryFactory)2 TestAtomQueryFactory (won.matcher.solr.query.factory.TestAtomQueryFactory)2 LinkedList (java.util.LinkedList)1 Dataset (org.apache.jena.query.Dataset)1 SolrException (org.apache.solr.common.SolrException)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 AtomProducer (won.bot.framework.component.atomproducer.AtomProducer)1 RoundRobinCompositeAtomProducer (won.bot.framework.component.atomproducer.impl.RoundRobinCompositeAtomProducer)1 HintBuilder (won.matcher.solr.hints.HintBuilder)1 TestMatcherQueryExecutor (won.matcher.solr.query.TestMatcherQueryExecutor)1