Package org.apache.solr.client.solrj

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


      SolrServer solr = new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL));
      SolrInputSplit solrSplit = (SolrInputSplit) split;
      final int numDocs = solrSplit.getNumDocs();
     
      SolrQuery solrQuery = new SolrQuery(SOLR_GET_ALL_QUERY);
      solrQuery.setFields(SolrConstants.ID_FIELD, SolrConstants.BOOST_FIELD,
                          SolrConstants.TIMESTAMP_FIELD,
                          SolrConstants.DIGEST_FIELD);
      solrQuery.setStart(solrSplit.getDocBegin());
      solrQuery.setRows(numDocs);

      QueryResponse response;
      try {
        response = solr.query(solrQuery);
      } catch (final SolrServerException e) {
View Full Code Here


 
  public Hits search(Query query) throws IOException {
    // filter query string
    final BooleanQuery bQuery = filters.filter(query);

    final SolrQuery solrQuery = new SolrQuery(stringify(bQuery));

    solrQuery.setRows(query.getParams().getNumHits());

    if (query.getParams().getSortField() == null) {
      solrQuery.setFields(query.getParams().getDedupField(), "score", searchUID);
      query.getParams().setSortField("score");
    } else {
      solrQuery.setFields(query.getParams().getDedupField(), query
          .getParams().getSortField(), searchUID);
      solrQuery.setSortField(query.getParams().getSortField(), query
          .getParams().isReverse() ? ORDER.asc : ORDER.desc);
    }

    QueryResponse response;
    try {
View Full Code Here

  }

  public HitDetails getDetails(Hit hit) throws IOException {
    QueryResponse response;
    try {
      response = solr.query(new SolrQuery(searchUID + ":\"" + hit.getUniqueKey() + "\""));
    } catch (final SolrServerException e) {
      throw SolrWriter.makeIOException(e);
    }

    final SolrDocumentList docList = response.getResults();
View Full Code Here

    }
    buf.append(")");

    QueryResponse response;
    try {
      response = solr.query(new SolrQuery(buf.toString()));
    } catch (final SolrServerException e) {
      throw SolrWriter.makeIOException(e);
    }

    final SolrDocumentList docList = response.getResults();
View Full Code Here

        return getQuery(filter).toString();
    }

    private SolrQuery getQuery(Filter filter) {

        SolrQuery solrQuery = new SolrQuery();
        solrQuery.setParam("q.op", "AND");

        // TODO : change this to be not hard coded
        solrQuery.setParam("df", "catch_all");

        // TODO : can we handle this better?
        solrQuery.setParam("rows", String.valueOf(Integer.MAX_VALUE));

        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.equals("\\/")) {
                        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

    @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

                setProperty("text", "tattoos hate hot hits");
        r.getTree("/").getChild("a").getChild("b").addChild("doc4").
                setProperty("text", "hats tattoos hit hot");
        r.commit();

        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");
        QueryResponse queryResponse = server.query(query);
        assertTrue("no documents were indexed", queryResponse.getResults().size() > 0);
    }
View Full Code Here

        // 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

        solrServer.deleteByQuery("*:*");
        solrServer.commit();
    }

    private QueryResponse executeSolrQuery(String query) throws SolrServerException {
        SolrQuery solrQuery = new SolrQuery();
        solrQuery.setQuery(query);
        return solrServer.query(solrQuery);
    }
View Full Code Here

                setProperty("text", "tattoos hate hot hits");
        r.getTree("/").getChild("a").getChild("b").addChild("doc4").
                setProperty("text", "hats tattoos hit hot");
        r.commit();

        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");
        QueryResponse queryResponse = server.query(query);
        assertTrue("no documents were indexed", queryResponse.getResults().size() > 0);
    }
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.