Examples of SolrQuery


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

  /**
   * A query that shows how to combine range and textual queries
   */
  private SolrQuery getAccessible24Hours() {
    final SolrQuery query = new SolrQuery();
    query.setQuery("(ChargeDeviceLocation : { " +
        "Latitude : xsd:double([52 TO 53]), " +
        "Longitude : xsd:double([-2 TO 2]) " +
        "}) " +
        "AND " +
        "(Connector : [ { RatedOutputCurrent : xsd:long([32 TO *]) } ]) " +
View Full Code Here

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

  /**
   * A query that shows how to combine SIREn query with the Solr's facet feature
   * on a Solr field.
   */
  private SolrQuery getDeviceControllerFacet() {
    final SolrQuery query = new SolrQuery();
    query.setQuery("Connector : [ { RatedOutputCurrent : xsd:long([32 TO *]) } ]");
    query.addFacetField("DeviceController_facet");
    return query;
  }
View Full Code Here

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

  /**
   * A query that shows how to use the nested query parameter to use Solr's
   * query parsers on Solr's fields.
   */
  private SolrQuery getNestedQuery() {
    final SolrQuery query = new SolrQuery();
    query.setQuery("DeviceOwner : { Website : uri(www.sourcelondon.net) }");
    query.setParam("nested", "{!lucene} name:university");
    return query;
  }
View Full Code Here

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

  /**
   * A query that shows how to build programatically a query for the JSON
   * query parser.
   */
  private SolrQuery getJsonQuery() throws QueryNodeException {
    final SolrQuery query = new SolrQuery();
    query.setRequestHandler("json");

    // Use the SIREn core API for building query expressions.
    final NodeTermQuery uri = new NodeTermQuery(new Term("", "www.sourcelondon.net"));
    uri.setDatatype("uri");

    final NodeTermQuery website = new NodeTermQuery(new Term("", "Website"));
    website.setDatatype("json:field");

    final NodeTermQuery owner = new NodeTermQuery(new Term("", "DeviceOwner"));
    owner.setDatatype("json:field");

    // Use the query builder to create twig query using the JSON query syntax.
    final QueryBuilder builder = new QueryBuilder();
    final TwigQuery twq = builder.newTwig(owner.toString("json"))
                           .with(
                             builder.newTwig(website.toString("json"))
                                    .with(builder.newNode(uri.toString("json"))),
                             2);

    query.setQuery(twq.toString());
    return query;
  }
View Full Code Here

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

    return response.getResults().getNumFound();
  }

  public String[] search(final String q, final String retrievedField, final String qt)
  throws SolrServerException, IOException {
    final SolrQuery query = new SolrQuery();
    query.setRequestHandler(qt);
    query.setQuery(q);
    return this.search(query, retrievedField);
  }
View Full Code Here

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

   * solr parser (i.e., lucene).
   */
  @Test
  public void testNoLocalParamater() throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : \"bbb\" }");
    final SolrQuery query = new SolrQuery();
    query.setQuery("aaa : bbb");
    query.setParam("nested", URL_FIELD + ":1");
    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

  }

  @Test
  public void testSimpleNestedLuceneQuery() throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : \"bbb\" }");
    SolrQuery query = new SolrQuery();
    query.setQuery("aaa : bbb");
    query.setParam("nested", "{!lucene}" + URL_FIELD + ":1");
    query.setRequestHandler("keyword");
    String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);

    query = new SolrQuery();
    query.setQuery("aaa : bbb");
    // non existing document id
    query.setParam("nested", "{!lucene}" + URL_FIELD + ":2");
    query.setRequestHandler("keyword");
    results = this.search(query, ID_FIELD);
    assertEquals(0, results.length);
  }
View Full Code Here

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

  }

  @Test
  public void testMultipleNestedQuery() throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : [\"bbb\", \"ccc\"] }");
    SolrQuery query = new SolrQuery();
    query.setQuery("aaa : bbb");
    query.setParam("nested", "{!lucene}" + URL_FIELD + ":1", "{!keyword} aaa : ccc");
    query.setRequestHandler("keyword");
    String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);

    query = new SolrQuery();
    query.setQuery("aaa : bbb");
    query.setParam("nested", "{!lucene}" + URL_FIELD + ":1", "{!keyword} aaa : ddd");
    query.setRequestHandler("keyword");
    results = this.search(query, ID_FIELD);
    assertEquals(0, results.length);
  }
View Full Code Here

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

  }

  @Test
  public void testCurlyBracketInNestedQuery() throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : { \"bbb\" : \"ccc\" } }");
    SolrQuery query = new SolrQuery();
    query.setQuery("aaa : bbb");
    query.setParam("nested", "{!keyword} aaa : { bbb : ccc } ");
    query.setRequestHandler("keyword");
    String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);

    query = new SolrQuery();
    query.setQuery("aaa : bbb");
    query.setParam("nested", "{!json} { \"node\" : { \"query\" : \"ccc\" } }");
    query.setRequestHandler("keyword");
    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 testASCIIFoldingExpansion() throws IOException, SolrServerException {
    this.addJsonString("1", " { \"value\" : \"cafe\" } ");
    this.addJsonString("2", " { \"value\" : \"café\" } ");
    SolrQuery query = new SolrQuery();
    query.setQuery("cafe");
    query.setRequestHandler("keyword");
    query.setIncludeScore(true);

    // should match the two documents, with same score
    QueryResponse response = getWrapper().getServer().query(query);
    SolrDocumentList docList = response.getResults();
    assertEquals(2, docList.getNumFound());
    float score1 = (Float) docList.get(0).getFieldValue("score");
    float score2 = (Float) docList.get(1).getFieldValue("score");
    Assert.assertTrue("Score should be identical", score1 == score2);

    // should match the two documents, but should assign different score
    // id2 should receive better score than id1
    query = new SolrQuery();
    query.setQuery("café");
    query.setRequestHandler("keyword");
    query.setIncludeScore(true);

    response = getWrapper().getServer().query(query);
    docList = response.getResults();
    assertEquals(2, docList.getNumFound());
    if (docList.get(0).getFieldValue("url").equals("id1")) {
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.