Package org.apache.stanbol.entityhub.servicesapi.query

Examples of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery


    public Collection<Entity> getMappingsByTarget(String targetId) throws YardException{
        if(targetId == null){
            log.warn("NULL parsed as Reference -> call to getMappingsBySymbol ignored (return null)");
            return null;
        }
        FieldQuery fieldQuery = getQueryFactory().createFieldQuery();
        fieldQuery.setConstraint(RdfResourceEnum.mappingTarget.getUri(), new ReferenceConstraint(targetId));
        Yard enttiyhubYard = lookupYard();
        QueryResultList<Representation> resultList = enttiyhubYard.findRepresentation(fieldQuery);
        Collection<Entity> mappings = new HashSet<Entity>();
        for(Representation rep : resultList){
            mappings.add(loadEntity(enttiyhubYard, rep));
View Full Code Here


        test1.add(field, "This is the text content of a field with value1.");
        test2.add(field, "This is the text content of a field with value2.");
        Iterable<Representation> updatedIterable = yard.update(Arrays.asList(test1, test2));
        assertNotNull(updatedIterable);

        FieldQuery query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(field, new TextConstraint(Arrays.asList("text content")));
        QueryResultList<Representation> results = yard.find(query);
        assertEquals(2, results.size());

        // fetch the light / minimal representation
        query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(field, new TextConstraint(Arrays.asList("value2")));
        results = yard.find(query);
        assertEquals(1, results.size());
        Representation result = results.iterator().next();
        assertEquals("urn:yard.test.testFieldQuery:representation.id2", result.getId());
        assertEquals(null, result.getFirst(field));
View Full Code Here

        Iterable<Representation> updatedIterable = yard.update(Arrays.asList(test1, test2, test3));
        assertNotNull(updatedIterable);

        // Perform a first similarity query that looks a lot like the first document
        FieldQuery query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(similarityfield, new SimilarityConstraint("aaaa aaaa aaaa aaaa zzzz yyyy"));
        QueryResultList<Representation> results = yard.find(query);
        assertEquals(2, results.size());
        Iterator<Representation> it = results.iterator();
        Representation first = it.next();
        assertEquals("urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id1", first.getId());
        // assertEquals(0.99, first.getFirst("http://www.iks-project.eu/ontology/rick/query/score"));

        Representation second = it.next();
        assertEquals("urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id2",
            second.getId());
        // assertEquals(0.80, first.getFirst("http://www.iks-project.eu/ontology/rick/query/score"));

        // combine similarity with traditional filtering
        query = yard.getQueryFactory().createFieldQuery();
        query.setConstraint(similarityfield, new SimilarityConstraint("aaaa aaaa aaaa aaaa zzzz yyyy"));
        query.setConstraint(filterfield, new TextConstraint(Arrays.asList("other")));
        results = yard.find(query);
        assertEquals(1, results.size());
        it = results.iterator();
        first = it.next();
        assertEquals("urn:yard.test.testFieldQueryWithSimilarityConstraint:representation.id2", first.getId());
View Full Code Here

    public static void main(String[] args) {
        SolrQueryFactory factory = new SolrQueryFactory(
            InMemoryValueFactory.getInstance(),
            IndexValueFactory.getInstance(),
            new SolrFieldMapper(null));
        FieldQuery query = DefaultQueryFactory.getInstance().createFieldQuery();
//        query.setConstraint("urn:field2", new TextConstraint("test","en","de"));
        query.setConstraint("urn:field3", new TextConstraint(Arrays.asList(
            "text value","anothertest","some more values"),"en","de",null));
        query.addSelectedField("urn:field2a");
        query.addSelectedField("urn:field3");
        query.setLimit(5);
        query.setOffset(5);
        SolrQuery solrQuery = factory.parseFieldQuery(query, SELECT.QUERY);
        System.out.println(solrQuery.getQuery());
    }
View Full Code Here

            if (field == null || field.trim().isEmpty()) {
                field = DEFAULT_FIND_FIELD;
            } else {
                field = field.trim();
            }
            FieldQuery query = JerseyUtils.createFieldQueryForFindRequest(name, field, language,
                limit == null || limit < 1 ? DEFAULT_FIND_RESULT_LIMIT : limit, offset,ldpath);
           
            // For the Entityhub we support to select additional fields for results
            // of find requests. For the Sites and {site} endpoint this is currently
            // deactivated because of very bad performance with OPTIONAL graph patterns
            // in SPARQL queries.
            Collection<String> additionalSelectedFields = new ArrayList<String>();
            if (select != null && !select.isEmpty()) {
                for (String selected : select.trim().split(" ")) {
                    if (selected != null && !selected.isEmpty()) {
                        additionalSelectedFields.add(selected);
                    }
                }
            }
            query.addSelectedFields(additionalSelectedFields);
            return executeQuery(query, headers, acceptedMediaType);
        }
    }
View Full Code Here

    }

    private QueryResultList<Representation> find(final FieldMapper fieldMapper,final FieldQuery parsedQuery, SELECT select) throws YardException {
        //create a clone of the query, because we need to refine it because the
        //query (as executed) needs to be included in the result set
        FieldQuery fieldQuery = parsedQuery.clone();
        log.debug("find " + fieldQuery);
        long start = System.currentTimeMillis();
        final Set<String> selected;
        if (select == SELECT.QUERY) {
            // if query set the fields to add to the result Representations
            selected = new HashSet<String>(fieldQuery.getSelectedFields());
            // add the score to query results!
            selected.add(RdfResourceEnum.resultScore.getUri());
        } else {
            // otherwise add all fields
            selected = null;
View Full Code Here

    @Override
    public final QueryResultList<String> findReferences(FieldQuery parsedQuery) throws YardException {
        //create a clone of the query, because we need to refine it because the
        //query (as executed) needs to be included in the result set
        FieldQuery fieldQuery = parsedQuery.clone();
        SolrQuery query = getSolrQueryFactory().parseFieldQuery(fieldQuery, SELECT.ID);
        QueryResponse respone;
        try {
            respone = getServer().query(query, METHOD.POST);
        } catch (SolrServerException e) {
View Full Code Here

        //TODO: The QueryResultList expects that the query as executed is added
        //to the response. However when executing queries on multiple site they
        //might support a different set of features and therefore execute
        //different variants. For now I return simple the query as executed by
        //the first Site that contributes results
        FieldQuery processedQuery = null;
        FieldQuery queryWithResults = null;
        for(ReferencedSite site : referencedSites){
            if(site.supportsSearch()){
                log.debug(" > query site {}",site.getId());
                try {
                    QueryResultList<String> results = site.findReferences(query);
View Full Code Here

        //TODO: The QueryResultList expects that the query as executed is added
        //to the response. However when executing queries on multiple site they
        //might support a different set of features and therefore execute
        //different variants. For now I return simple the query as executed by
        //the first Site that contributes results
        FieldQuery processedQuery = null;
        FieldQuery queryWithResults = null;
        for(ReferencedSite site : referencedSites){
            if(site.supportsSearch()){
                log.debug(" > query site {}",site.getId());
                try {
                    QueryResultList<Representation> results = site.find(query);
View Full Code Here

        //TODO: The QueryResultList expects that the query as executed is added
        //to the response. However when executing queries on multiple site they
        //might support a different set of features and therefore execute
        //different variants. For now I return simple the query as executed by
        //the first Site that contributes results
        FieldQuery processedQuery = null;
        FieldQuery queryWithResults = null;
        Set<Entity> entities = new HashSet<Entity>();
        for(ReferencedSite site : referencedSites){
            if(site.supportsSearch()){ //do not search on sites that do not support it
                log.debug(" > query site {}",site.getId());
                try {
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.servicesapi.query.FieldQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.