Package org.apache.solr.client.solrj

Examples of org.apache.solr.client.solrj.SolrQuery


        // Add a node
        r.getTree("/").addChild("testRemoveNode").setProperty("foo", "bar");
        r.commit();

        // check the node is not in Solr anymore
        SolrQuery query = new SolrQuery();
        query.setQuery("path_exact:\\/testRemoveNode\\/");
        assertTrue("item with id:testRemoveNode was not found in the index",
                server.query(query).getResults().size() > 0);

        // remove the node in oak
        r.getTree("/").getChild("testRemoveNode").remove();
View Full Code Here


    }
    return "";
  }

  public Boolean verifyIngest(String layerId) throws Exception {
    SolrQuery query = new SolrQuery();
      query.setQuery("LayerId:" + layerId);
    QueryResponse queryResponse = solrServer.query(query);
    int numFound = Integer.getInteger(queryResponse.getResponseHeader().get("numFound").toString());
    if (numFound == 1){
      return true;
    } else {
View Full Code Here

        if(null == queryString || "".equals(queryString)){
            logger.debug("The solr params is empty!");
            throw new IllegalArgumentException("The solr params is empty!");
        }
       
        SolrParams params = new SolrQuery(queryString);
        response = this.query(params);

        return response;
    }
View Full Code Here

        return getQuery(filter).toString();
    }

    private SolrQuery getQuery(Filter filter) {

        SolrQuery solrQuery = new SolrQuery();
        setDefaults(solrQuery);

        StringBuilder queryBuilder = new StringBuilder();

        for (String pt : filter.getPrimaryTypes()) {
            queryBuilder.append("jcr\\:primaryType").append(':').append(partialEscape(pt));
        }

        Filter.PathRestriction pathRestriction = filter.getPathRestriction();
        if (pathRestriction != null) {
            String path = purgePath(filter);
            String fieldName = configuration.getFieldForPathRestriction(pathRestriction);
            if (fieldName != null) {
                queryBuilder.append(fieldName);
                queryBuilder.append(':');
                queryBuilder.append(path);
                if (!path.equals("\\/")) {
                    queryBuilder.append("\\/");
                }
                // TODO: Also handle other path restriction types
                if (pathRestriction.equals(Filter.PathRestriction.ALL_CHILDREN)) {
                    queryBuilder.append("*");
                }
                queryBuilder.append(" ");
            }
        }
        Collection<Filter.PropertyRestriction> propertyRestrictions = filter.getPropertyRestrictions();
        if (propertyRestrictions != null && !propertyRestrictions.isEmpty()) {
            for (Filter.PropertyRestriction pr : propertyRestrictions) {
                if (pr.propertyName.contains("/")) {
                    // cannot handle child-level property restrictions
                    continue;
                }
                String first = null;
                if (pr.first != null) {
                    first = partialEscape(String.valueOf(pr.first.getValue(pr.first.getType()))).toString();
                }
                String last = null;
                if (pr.last != null) {
                    last = partialEscape(String.valueOf(pr.last.getValue(pr.last.getType()))).toString();
                }

                String prField = configuration.getFieldForPropertyRestriction(pr);
                CharSequence fieldName = partialEscape(prField != null ?
                        prField : pr.propertyName);
                if ("jcr\\:path".equals(fieldName.toString())) {
                    queryBuilder.append(configuration.getPathField());
                    queryBuilder.append(':');
                    queryBuilder.append(first);
                    if (first!= null && !"\\/".equals(first)) {
                        queryBuilder.append("\\/");
                    }
                } else {
                    queryBuilder.append(fieldName).append(':');
                    if (pr.first != null && pr.last != null && pr.first.equals(pr.last)) {
                        queryBuilder.append(first);
                    } else if (pr.first == null && pr.last == null) {
                        queryBuilder.append('*');
                    } else if ((pr.first != null && pr.last == null) || (pr.last != null && pr.first == null) || (!pr.first.equals(pr.last))) {
                        // TODO : need to check if this works for all field types (most likely not!)
                        queryBuilder.append(createRangeQuery(first, last, pr.firstIncluding, pr.lastIncluding));
                    } else if (pr.isLike) {
                        // TODO : the current parameter substitution is not expected to work well
                        queryBuilder.append(partialEscape(String.valueOf(pr.first.getValue(pr.first.getType())).replace('%', '*').replace('_', '?')));
                    } else {
                        throw new RuntimeException("[unexpected!] not handled case");
                    }
                }
                queryBuilder.append(" ");
            }
        }

        Collection<String> fulltextConditions = filter.getFulltextConditions();
        for (String fulltextCondition : fulltextConditions) {
            queryBuilder.append(fulltextCondition).append(" ");
        }
        if(queryBuilder.length() == 0) {
            queryBuilder.append("*:*");
        }
        String escapedQuery = queryBuilder.toString();
        solrQuery.setQuery(escapedQuery);

        if (log.isDebugEnabled()) {
            log.debug("JCR query {} has been converted to Solr query {}",
                    filter.getQueryStatement(), solrQuery.toString());
        }

        return solrQuery;
    }
View Full Code Here

    @Override
    public Cursor query(Filter filter, NodeState root) {
        Cursor cursor;
        try {
            SolrQuery query = getQuery(filter);
            if (log.isDebugEnabled()) {
                log.info("sending query {}", query);
            }
            QueryResponse queryResponse = solrServer.query(query);
            cursor = new SolrCursor(queryResponse);
View Full Code Here

    SolrInputDocument doc = new SolrInputDocument();
    doc.addField( "id", "aaaa" );
    solr.add( doc );
    solr.commit();
   
    assertEquals( 1, solr.query( new SolrQuery( "*:*" ) ).getResults().getNumFound() );
  }
View Full Code Here

    SolrInputDocument doc = new SolrInputDocument();
    doc.addField( "id", "bbbb" );
    solr.add( doc );
    solr.commit();
   
    assertEquals( 1, solr.query( new SolrQuery( "*:*" ) ).getResults().getNumFound() );
  }
View Full Code Here

    contentEntity.setText(html);
   
    handler.handle(new URI("http://localhost/"), contentEntity);
    solr.commit();
   
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.setFields(field);
    QueryResponse response = solr.query(query);
   
    SolrDocument doc = response.getResults().iterator().next();
    String value = (String)doc.getFieldValue(field);
   
View Full Code Here

    schema.refreshAnalyzers();
   
    assertU(adoc("id", "10", "title", "test", fieldName, "aaa"));
    assertU(commit());

    SolrQuery query = new SolrQuery( fieldName+":aaa" );
    query.set( "indent", "true" );
    SolrQueryRequest req = new LocalSolrQueryRequest( core, query );
   
    assertQ("Make sure they got in", req
            ,"//*[@numFound='1']"
            ,"//result/doc[1]/int[@name='id'][.='10']"
            );
   
    // Check to see if our copy field made it out safely
    query.setQuery( "dynamic_runtime:aaa" );
    assertQ("Make sure they got in", req
            ,"//*[@numFound='1']"
            ,"//result/doc[1]/int[@name='id'][.='10']"
            );
    clearIndex();
View Full Code Here

    doc.addField("data", buf);
    server.add(doc);

    server.commit();

    QueryResponse resp = server.query(new SolrQuery("*:*"));
    SolrDocumentList res = resp.getResults();
    List<Bean> beans = resp.getBeans(Bean.class);
    assertEquals(3, res.size());
    assertEquals(3, beans.size());
    for (SolrDocument d : res) {
View Full Code Here

TOP

Related Classes of org.apache.solr.client.solrj.SolrQuery

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.