Search in sources :

Example 1 with TestNeedQueryFactory

use of won.matcher.solr.query.factory.TestNeedQueryFactory 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 need producer (e.g. if it should exhaust) in the SolrNeedIndexerAppConfiguration file
    NeedProducer needProducer = ctx.getBean(RoundRobinCompositeNeedProducer.class);
    while (!needProducer.isExhausted()) {
        // && needs < 20) {
        Dataset ds = needProducer.create();
        try {
            TestNeedQueryFactory needQuery = new TestNeedQueryFactory(ds);
            String query = needQuery.createQuery();
            System.out.println("execute query: " + query);
            SolrDocumentList docs = queryExecutor.executeNeedQuery(query, null, new BasicNeedQueryFactory(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 matchedNeedId = doc.getFieldValue("id").toString();
                System.out.println("Score: " + score + ", Id: " + matchedNeedId);
            }
            System.out.println("All docs: ");
            System.out.println("======================");
            for (SolrDocument doc : docs) {
                String score = doc.getFieldValue("score").toString();
                String matchedNeedId = doc.getFieldValue("id").toString();
                System.out.println("Score: " + score + ", Id: " + matchedNeedId);
            }
        } catch (SolrException e) {
            System.err.println(e);
        }
    }
    System.exit(0);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SolrDocument(org.apache.solr.common.SolrDocument) BasicNeedQueryFactory(won.matcher.solr.query.factory.BasicNeedQueryFactory) Dataset(org.apache.jena.query.Dataset) TestMatcherQueryExecutor(won.matcher.solr.query.TestMatcherQueryExecutor) HintBuilder(won.matcher.solr.hints.HintBuilder) SolrDocumentList(org.apache.solr.common.SolrDocumentList) RoundRobinCompositeNeedProducer(won.bot.framework.component.needproducer.impl.RoundRobinCompositeNeedProducer) NeedProducer(won.bot.framework.component.needproducer.NeedProducer) SolrException(org.apache.solr.common.SolrException) TestNeedQueryFactory(won.matcher.solr.query.factory.TestNeedQueryFactory)

Example 2 with TestNeedQueryFactory

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

the class SolrMatcherEvaluation method computeMatchingNeeds.

private List<String> computeMatchingNeeds(Dataset need) throws IOException, SolrServerException {
    TestNeedQueryFactory needQuery = new TestNeedQueryFactory(need);
    SolrDocumentList docs = queryExecutor.executeNeedQuery(needQuery.createQuery(), null, new BasicNeedQueryFactory(need).createQuery());
    SolrDocumentList matchedDocs = hintBuilder.calculateMatchingResults(docs);
    List<String> matchedNeeds = new LinkedList<>();
    for (SolrDocument doc : matchedDocs) {
        String matchedNeedId = doc.getFieldValue("id").toString();
        matchedNeeds.add(matchedNeedId);
    }
    return matchedNeeds;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) BasicNeedQueryFactory(won.matcher.solr.query.factory.BasicNeedQueryFactory) SolrDocumentList(org.apache.solr.common.SolrDocumentList) LinkedList(java.util.LinkedList) TestNeedQueryFactory(won.matcher.solr.query.factory.TestNeedQueryFactory)

Aggregations

SolrDocument (org.apache.solr.common.SolrDocument)2 SolrDocumentList (org.apache.solr.common.SolrDocumentList)2 BasicNeedQueryFactory (won.matcher.solr.query.factory.BasicNeedQueryFactory)2 TestNeedQueryFactory (won.matcher.solr.query.factory.TestNeedQueryFactory)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 NeedProducer (won.bot.framework.component.needproducer.NeedProducer)1 RoundRobinCompositeNeedProducer (won.bot.framework.component.needproducer.impl.RoundRobinCompositeNeedProducer)1 HintBuilder (won.matcher.solr.hints.HintBuilder)1 TestMatcherQueryExecutor (won.matcher.solr.query.TestMatcherQueryExecutor)1