Examples of SolrQuery


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

    this.addJsonString("1", "{ \"uri\" : { " +
        "\"_value_\" : \"http://xmlns.com/foaf/0.1/Person\", " +
        "\"_datatype_\" : \"uri\" " +
        "} }");

    final SolrQuery query = new SolrQuery();
    final QueryBuilder b = new QueryBuilder();
    query.setQuery(b.newTwig("uri").with(b.newNode("'foaf:Person'")).toString());
    query.setRequestHandler("json");
    final String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);
  }
View Full Code Here

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

  throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : \"bbb ccc\" }");
    this.addJsonString("2", "{ \"aaa\" : \"bbb\" }");
    this.addJsonString("3", "{ \"aaa\" : \"ccc\" }");

    SolrQuery query = new SolrQuery();
    query.setQuery("bbb ccc");
    query.setRequestHandler("keyword");
    String[] results = this.search(query, URL_FIELD);
    // Default Operator = AND : Only one document should match
    assertEquals(1, results.length);

    query = new SolrQuery();
    query.setQuery("{ \"node\" : { \"query\" : \"bbb ccc\" } }");
    query.setRequestHandler("json");
    results = this.search(query, URL_FIELD);
    // Default Operator = AND : Only one document should match
    assertEquals(1, results.length);
  }
View Full Code Here

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

  throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : \"bbb ccc\" }");
    this.addJsonString("2", "{ \"aaa\" : \"bbb\" }");
    this.addJsonString("3", "{ \"aaa\" : \"ccc\" }");

    SolrQuery query = new SolrQuery();
    query.setQuery("bbb ccc");
    query.setRequestHandler("keyword");
    query.set(QueryParsing.OP, "OR");
    String[] results = this.search(query, URL_FIELD);
    // Default Operator = OR : all the documents should match
    assertEquals(3, results.length);

    query = new SolrQuery();
    query.setQuery("{ \"node\" : { \"query\" : \"bbb ccc\" } }");
    query.setRequestHandler("json");
    query.set(QueryParsing.OP, "OR");
    results = this.search(query, URL_FIELD);
    // Default Operator = OR : all the documents should match
    assertEquals(3, results.length);
  }
View Full Code Here

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

      this.addJsonStringWoCommit("id"+i, "{ \"numeric\" : " + i + " }");
    }

    this.commit();

    final SolrQuery query = new SolrQuery();
    // by default, the json tokenizer index numeric value as long
    query.setQuery("numeric : xsd:long([501 TO *])");
    query.setRequestHandler("keyword");
    assertEquals(499, this.search(query));
  }
View Full Code Here

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

          "} }");
    }

    this.commit();

    final SolrQuery query = new SolrQuery();
    // by default, the json tokenizer index numeric value as long
    query.setQuery("date : xsd:date([1995-12-31T00:00:00Z TO 1995-12-31T00:00:00Z+5YEARS])");
    query.setRequestHandler("keyword");
    assertEquals(5, this.search(query));
  }
View Full Code Here

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

    this.addJsonString("1", "{ \"uri\" : { " +
        "\"_value_\" : \"http://xmlns.com/foaf/0.1/Person\", " +
        "\"_datatype_\" : \"uri\" " +
        "} }");

    final SolrQuery query = new SolrQuery();
    final QueryBuilder b = new QueryBuilder();
    query.setQuery(b.newTwig("uri").with(b.newNode("uri('http://xmlns.com/foaf/0.1/Person')")).toString());
    query.setRequestHandler("json");
    final String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);
  }
View Full Code Here

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

  @Test
  public void testBooleanDatatypeQuery()
  throws SolrServerException, IOException, QueryNodeException {
    this.addJsonString("1", "{ \"boolean\" : true }");

    final SolrQuery query = new SolrQuery();
    query.setQuery("true");
    query.setRequestHandler("keyword");
    final String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);
  }
View Full Code Here

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

        return getQuery(filter).toString();
    }

    private SolrQuery getQuery(Filter filter) {

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

        StringBuilder queryBuilder = new StringBuilder();

        // TODO : handle node type restriction
        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("/")) {
                    // lucene 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(new StringBuilder("JCR query: \n" + filter.getQueryStatement() + " \nhas been converted to Solr query: \n").
                    append(solrQuery.toString()).toString());
        }

        return solrQuery;
    }
View Full Code Here

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

    @Override
    public Cursor query(Filter filter, NodeState root) {
        Cursor cursor;
        try {
            SolrQuery query = getQuery(filter);
            QueryResponse queryResponse = solrServer.query(query);
            cursor = new SolrCursor(queryResponse);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
View Full Code Here

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

    protected void solrCommit() {
        template.sendBodyAndHeader("direct:start", null, SolrConstants.OPERATION, SolrConstants.OPERATION_COMMIT);
    }

    protected QueryResponse executeSolrQuery(String query) throws SolrServerException {
        SolrQuery solrQuery = new SolrQuery();
        solrQuery.setQuery(query);
        return solrServer.query(solrQuery);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.