Example usage for org.apache.solr.client.solrj SolrQuery setParam

List of usage examples for org.apache.solr.client.solrj SolrQuery setParam

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrQuery setParam.

Prototype

public SolrQuery setParam(String name, boolean value) 

Source Link

Usage

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Check that nested array are properly flattened.
 *//*from   w ww.  j av a2  s.co  m*/
@Test
public void testNestedArray() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : null, \"bbb\" :  [\"ccc\", [ \"ddd\", [\"eee\"] ] ] }";

    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb:ccc");
    query.setRequestHandler("tree");
    long found = this.search(query).getNumFound();
    assertEquals(1, found);

    query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb:ddd");
    query.setRequestHandler("tree");
    found = this.search(query).getNumFound();
    assertEquals(1, found);
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Check that nested objects are properly flattened.
 *//*from  w w  w . ja  v  a2 s.  c  om*/
@Test
public void testNestedObject() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : null, \"bbb\" :  { \"ccc\" : { \"ddd\" : \"eee\" }, \"fff\" : \"ggg\" } }";

    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb.ccc.ddd:eee");
    query.setRequestHandler("tree");
    long found = this.search(query).getNumFound();
    assertEquals(1, found);

    query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb.fff:ggg");
    query.setRequestHandler("tree");
    found = this.search(query).getNumFound();
    assertEquals(1, found);
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Check that nested objects in a mixed array are properly flattened.
 *///from  w w w  .  j a va 2s  .co m
@Test
public void testNestedObjectInArray() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : null, \"bbb\" :  [ \"ccc\", { \"ddd\" : \"eee\" }, \"ggg\" ] }";

    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb:ccc");
    query.setRequestHandler("tree");
    long found = this.search(query).getNumFound();
    assertEquals(1, found);

    query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb.ddd:eee");
    query.setRequestHandler("tree");
    found = this.search(query).getNumFound();
    assertEquals(1, found);
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Check that the special SIREn's object for datatype is properly flattened.
 *///from  w w w  .  j ava2s  .  c o m
@Test
public void testDatatypeObject() throws QueryNodeException, IOException, SolrServerException {
    String input = "{ \"id\" : \"1\", \"aaa\" : null, \"bbb\" :  { \"_datatype_\" : \"uri\", \"_value_\" : \"ccc\" } }";

    this.sendUpdateRequest(input);
    this.commit();

    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} bbb:ccc");
    query.setRequestHandler("tree");
    long found = this.search(query).getNumFound();
    assertEquals(1, found);
}

From source file:com.sindicetech.siren.solr.handler.TestSirenUpdateRequestHandler.java

License:Open Source License

/**
 * Check that the nested query and the main query are intersected, i.e., that each one is assigned a MUST operator.
 * See issue #60./*  w ww  . ja  va2s .  c  o m*/
 */
@Test
public void testNestedQuery() throws IOException, SolrServerException, QueryNodeException {
    String input = "{ \"aaa\" : null, \"ChargeDeviceRef\" : \"CM765\", \"ChargeDeviceLocation\" : { \"Address\" : { \"PostTown\" : \"Peterborough\" } } }";
    this.sendUpdateRequest(input);
    input = "{ \"aaa\" : null, \"ChargeDeviceRef\" : \"CM556\", \"ChargeDeviceLocation\" : { \"Address\" : { \"PostTown\" : \"Peterborough\" } } }";
    this.sendUpdateRequest(input);
    input = "{ \"aaa\" : null, \"ChargeDeviceRef\" : \"CM779\", \"ChargeDeviceLocation\" : { \"Address\" : { \"PostTown\" : \"Peterborough\" } } }";
    this.sendUpdateRequest(input);

    this.commit();

    SolrQuery query = new SolrQuery();
    final ConciseQueryBuilder b = new ConciseQueryBuilder();
    query.setQuery(b.newNode("CM765").setAttribute("ChargeDeviceRef").toString());
    query.setParam("nested", "ChargeDeviceLocation.Address.PostTown:Peterborough");
    query.setRequestHandler("tree");

    long found = this.search(query).getNumFound();
    assertEquals(1, found);
}

From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java

License:Open Source License

/**
 * When no local parameters are defined, then it should rely on the default
 * solr parser (i.e., lucene)./*w  w w .  ja v a 2s.  c om*/
 */
@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);
}

From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java

License:Open Source License

@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);/*www . j  a v  a  2  s  . c om*/

    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);
}

From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java

License:Open Source License

@Test
public void testEmptyMainQueryWithNestedMatchAll() throws IOException, SolrServerException {
    this.addJsonString("1", "{ \"aaa\" : \"bbb\" }");
    SolrQuery query = new SolrQuery();
    query.setParam("nested", "{!lucene} *:*");
    query.setRequestHandler("keyword");
    String[] results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);/*from  w  w w  .  j  a va  2s .  c o  m*/
}

From source file:com.sindicetech.siren.solr.qparser.TestNestedQuery.java

License:Open Source License

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

    query = new SolrQuery();
    query.setParam("nested", "{!tree} { \"node\" : { \"query\" : \"ccc\" } }");
    query.setRequestHandler("keyword");
    results = this.search(query, ID_FIELD);
    assertEquals(1, results.length);
}

From source file:com.sp.Parser.Utils.java

License:Open Source License

public static SolrDocumentList getTop(SolrDocumentList docs, ArrayList<String> prices,
        ArrayList<String> filters) {
    SolrDocumentList SolrDocList = null;
    try {/*from ww w .j ava 2 s .  c  o  m*/

        SolrDocument PivotDoc = docs.get(0); //store pId book to put it in the index 0 of the final SolrDocList

        Collection<Object> Top20Product_ids = PivotDoc.getFieldValues("top20"); //store pId book to put it in the index 0 of the final SolrDocList

        PivotDoc.removeFields("top20"); // get current book top20 with products ids
        PivotDoc.removeFields("keywords");

        Collection<Object> BackupTop20Product_ids = Top20Product_ids;

        String QueryString = "product_id:(";
        ArrayList<String> TempQuery = new ArrayList<>();

        for (Object product_id : BackupTop20Product_ids) {
            QueryString += product_id.toString() + " ";
            TempQuery.add(product_id.toString());
        }
        QueryString += ")";

        String prices_fields = "";
        for (String string : prices) {
            prices_fields += string + " ";

        }

        SolrQuery Query = new SolrQuery(QueryString);
        Query.setRows(101);
        for (String filter : filters) {
            LOG.info("Top20 Filtering : " + filter);
            Query.addFilterQuery(filter);
        }
        Query.setParam("fl",
                "product_id book_id author_searchable author_id format_name description title author_firstname"
                        + " file_size publishing_date author_lastname author_rank publisher_id publisher_name"
                        + " permalink nb_pages isbn " + prices_fields);

        SolrServer solr = new HttpSolrServer(SearchHandler.solr_url);

        QueryResponse response = solr.query(Query);

        SolrDocList = response.getResults();

        if (!SolrDocList.isEmpty()) {

            SolrDocList = Utils.SortListByProductId(TempQuery, SolrDocList);

            if (!SolrDocList.isEmpty()) {
                SolrDocument temp = SolrDocList.get(0);

                SolrDocList.set(0, PivotDoc);
                SolrDocList.add(1, temp);
            }
        } else {
            SolrDocList.add(0, PivotDoc);
        }
    } catch (SolrServerException ex) {
        LOG.info("mmh : ", ex);
    }
    LOG.info("SolrDocList Size int getTop : " + SolrDocList.size());
    return SolrDocList;
}