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:lux.solr.LuxSolrTest.java

License:Mozilla Public License

@Test
public void testCreateCore() throws Exception {
    SolrQuery q = new SolrQuery();
    q.setRequestHandler(coreContainer.getAdminPath());
    q.setParam("action", "CREATE");
    q.setParam("name", "core3");
    q.setParam("instanceDir", "core3");
    solr.query(q);/*ww  w .  j a  v  a  2  s  . com*/
    SolrServer core3 = new EmbeddedSolrServer(coreContainer, "core3");
    core3.deleteByQuery("*:*");
    core3.commit();
    assertSolrQueryCount(0, "*:*", core3);
    // main core still works
    assertQueryCount(1, 102, "xs:integer", "102", "count(collection())", solr);
    // new core working too
    assertQueryCount(1, 0, "xs:integer", "0", "count(collection())", core3);
}

From source file:lux.solr.LuxSolrTest.java

License:Mozilla Public License

@Test
public void testAppServer() throws Exception {
    SolrQuery q = new SolrQuery();
    q.setRequestHandler("/testapp");
    q.setParam("test-param", "test-value");
    q.setParam("wt", "lux");
    q.setParam("lux.contentType", "text/xml");
    QueryResponse resp = solr.query(q);//w  w w. j a va2 s . co  m
    assertEquals("query was blank", resp.getResponse().get("xpath-error"));
    q.setParam("lux.xquery", "lux/solr/echo.xqy");
    resp = solr.query(q);
    NamedList<?> xpathResults = (NamedList<?>) resp.getResponse().get("xpath-results");
    assertEquals(
            "<http><params>" + "<param name=\"wt\"><value>lux</value></param>"
                    + "<param name=\"qt\"><value>/testapp</value></param>"
                    + "<param name=\"test-param\"><value>test-value</value></param>"
                    + "<param name=\"wt\"><value>lux</value></param></params><context-path/></http>",
            xpathResults.get("document").toString());
    assertTrue(resp.getResults().isEmpty());
}

From source file:net.hydromatic.optiq.impl.solr.SolrSchema.java

License:Apache License

@Override
protected Map<String, Table> getTableMap() {
    final ImmutableMap.Builder<String, Table> builder = ImmutableMap.builder();

    server = new HttpSolrServer(host);

    final List<SolrFieldType> fieldTypes = new ArrayList<SolrFieldType>();
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.setFacetLimit(100000);/*from w w  w. jav a 2 s .com*/
    query.setParam("rows", "10000");

    SolrDocumentList res = null;
    try {
        res = server.query(query).getResults();
    } catch (SolrServerException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }
    assert res != null;

    final SolrTable table;

    table = new SolrTable(this, core, res, server);

    builder.put(core, table);

    return builder.build();
}

From source file:net.yacy.cora.federate.solr.connector.AbstractSolrConnector.java

License:Open Source License

public static SolrQuery getSolrQuery(final String querystring, final String sort, final int offset,
        final int count, final String... fields) {
    // construct query
    final SolrQuery params = new SolrQuery();
    //if (count < 2 && querystring.startsWith("{!raw f=")) {
    //    params.setQuery("*:*");
    //    params.addFilterQuery(querystring);
    //} else {//w ww  .j a v a2s .c  o m
    params.setQuery(querystring);
    //}
    params.clearSorts();
    if (sort != null) {
        params.set(CommonParams.SORT, sort);
    }
    params.setRows(count);
    params.setStart(offset);
    params.setFacet(false);
    if (fields != null && fields.length > 0)
        params.setFields(fields);
    params.setIncludeScore(false);
    params.setParam("defType", "edismax");
    params.setParam(DisMaxParams.QF, CollectionSchema.text_t.getSolrFieldName() + "^1.0");
    return params;
}

From source file:net.yacy.cora.federate.solr.connector.AbstractSolrConnector.java

License:Open Source License

/**
 * get facets of the index: a list of lists with values that are most common in a specific field
 * @param query a query which is performed to get the facets
 * @param fields the field names which are selected as facet
 * @param maxresults the maximum size of the resulting maps
 * @return a map with key = facet field name, value = an ordered map of field values for that field
 * @throws IOException//from  ww w .  j av a  2  s  .co m
 */
@Override
public LinkedHashMap<String, ReversibleScoreMap<String>> getFacets(String query, int maxresults,
        final String... fields) throws IOException {
    // construct query
    assert fields.length > 0;
    final SolrQuery params = new SolrQuery();
    params.setQuery(query);
    params.setRows(0);
    params.setStart(0);
    params.setFacet(true);
    params.setFacetMinCount(1); // there are many 0-count facets in the uninverted index cache
    params.setFacetLimit(maxresults);
    params.setFacetSort(FacetParams.FACET_SORT_COUNT);
    params.setParam(FacetParams.FACET_METHOD, FacetParams.FACET_METHOD_fc /*FACET_METHOD_fcs*/);
    params.setFields(fields);
    params.clearSorts();
    params.setIncludeScore(false);
    for (String field : fields)
        params.addFacetField(field);

    // query the server
    QueryResponse rsp = getResponseByParams(params);
    LinkedHashMap<String, ReversibleScoreMap<String>> facets = new LinkedHashMap<String, ReversibleScoreMap<String>>(
            fields.length);
    for (String field : fields) {
        FacetField facet = rsp.getFacetField(field);
        ReversibleScoreMap<String> result = new ClusteredScoreMap<String>(UTF8.insensitiveUTF8Comparator);
        List<Count> values = facet.getValues();
        if (values == null)
            continue;
        for (Count ff : values)
            if (ff.getCount() > 0)
                result.set(ff.getName(), (int) ff.getCount());
        facets.put(field, result);
    }
    return facets;
}

From source file:net.yacy.search.index.ErrorCache.java

License:Open Source License

public ErrorCache(final Fulltext fulltext) {
    this.fulltext = fulltext;
    this.cache = new LinkedHashMap<String, CollectionConfiguration.FailDoc>();
    // concurrently fill stack with latest values
    new Thread() {
        @Override//from ww w . j  ava 2 s  . c o  m
        public void run() {
            final SolrQuery params = new SolrQuery();
            params.setParam("defType", "edismax");
            params.setStart(0);
            params.setRows(1000);
            params.setFacet(false);
            params.setSort(
                    new SortClause(CollectionSchema.last_modified.getSolrFieldName(), SolrQuery.ORDER.desc));
            params.setFields(CollectionSchema.id.getSolrFieldName());
            params.setQuery(
                    CollectionSchema.failreason_s.getSolrFieldName() + AbstractSolrConnector.CATCHALL_DTERM);
            params.set(CommonParams.DF, CollectionSchema.id.getSolrFieldName()); // DisMaxParams.QF or CommonParams.DF must be given
            SolrDocumentList docList;
            try {
                docList = fulltext.getDefaultConnector().getDocumentListByParams(params);
                if (docList != null)
                    for (int i = docList.size() - 1; i >= 0; i--) {
                        SolrDocument doc = docList.get(i);
                        String hash = (String) doc.getFieldValue(CollectionSchema.id.getSolrFieldName());
                        cache.put(hash, null);
                    }
            } catch (IOException e) {
                ConcurrentLog.logException(e);
            }
        }
    }.start();
}

From source file:net.yacy.search.index.ErrorCacheFiller.java

License:Open Source License

/**
 * Fills the error cache with recently failed document hashes found in the index
 *///  w w w  .  ja v a2 s  .  com
@Override
public void run() {
    final SolrQuery params = new SolrQuery();
    params.setParam("defType", "edismax");
    params.setStart(0);
    params.setRows(1000);
    params.setFacet(false);
    params.setSort(new SortClause(CollectionSchema.load_date_dt.getSolrFieldName(), SolrQuery.ORDER.desc)); // load_date_dt = faildate
    params.setFields(CollectionSchema.id.getSolrFieldName());
    params.setQuery(CollectionSchema.failreason_s.getSolrFieldName() + AbstractSolrConnector.CATCHALL_DTERM);
    params.set(CommonParams.DF, CollectionSchema.id.getSolrFieldName()); // DisMaxParams.QF or CommonParams.DF must be given
    SolrDocumentList docList;
    try {
        docList = this.sb.index.fulltext().getDefaultConnector().getDocumentListByParams(params);
        if (docList != null)
            for (int i = docList.size() - 1; i >= 0; i--) {
                SolrDocument doc = docList.get(i);
                String hash = (String) doc.getFieldValue(CollectionSchema.id.getSolrFieldName());
                cache.putHashOnly(hash);
            }
    } catch (IOException e) {
        ConcurrentLog.logException(e);
    }
}

From source file:net.yacy.search.index.SingleDocumentMatcher.java

License:Open Source License

/**
 * @param query a Solr query string to parse
 * @param targetCore an open Solr index core that is the target of the query
 * @return a lucene Query instance parsed from the given Solr query string on the provided Solr core.
 * @throws SyntaxError when the query syntax is not valid
 * @throws SolrException when a query required element is missing, or when a problem occurred when accessing the target core
 *//*from   w w  w.jav a2s .  c om*/
public static Query toLuceneQuery(final String query, final SolrCore targetCore)
        throws SyntaxError, SolrException {
    if (query == null || targetCore == null) {
        throw new IllegalArgumentException("All parameters must be non null");
    }

    final SolrQuery solrQuery = new SolrQuery(query);
    solrQuery.setParam(CommonParams.DF, CollectionSchema.text_t.getSolrFieldName());

    final SolrQueryRequestBase solrRequest = new SolrQueryRequestBase(targetCore, solrQuery) {
    };

    final LuceneQParserPlugin luceneParserPlugin = new LuceneQParserPlugin();
    final QParser solrParser = luceneParserPlugin.createParser(query, null, solrRequest.getParams(),
            solrRequest);
    return solrParser.parse();
}

From source file:net.yacy.search.query.QueryParams.java

License:Open Source License

private SolrQuery solrTextQuery(final boolean getFacets, final boolean excludeintext_image) {
    if (this.cachedQuery != null) {
        this.cachedQuery.setStart(this.offset);
        if (!getFacets)
            this.cachedQuery.setFacet(false);
        return this.cachedQuery;
    }//from  w  ww. j a va  2s .  c  o  m

    // construct query
    final SolrQuery params = getBasicParams(getFacets,
            this.queryGoal.collectionTextFilterQuery(excludeintext_image));
    int rankingProfile = this.ranking.coeff_date == RankingProfile.COEFF_MAX ? 1
            : (this.modifier.sitehash != null || this.modifier.sitehost != null) ? 2 : 0;
    params.setQuery(this.queryGoal.collectionTextQuery().toString());
    Ranking actRanking = indexSegment.fulltext().getDefaultConfiguration().getRanking(rankingProfile); // for a by-date ranking select different ranking profile

    String fq = actRanking.getFilterQuery();
    String bq = actRanking.getBoostQuery();
    String bf = actRanking.getBoostFunction();
    final String qf = actRanking.getQueryFields();
    if (!qf.isEmpty())
        params.setParam(DisMaxParams.QF, qf);
    if (this.queryGoal.getIncludeSize() > 1) {
        // add boost on combined words
        if (bq.length() > 0)
            bq += " ";
        bq += CollectionSchema.text_t.getSolrFieldName() + ":\"" + this.queryGoal.getIncludeString() + "\"^10";
    }
    if (fq.length() > 0) {
        String[] oldfq = params.getFilterQueries();
        ArrayList<String> newfq = new ArrayList<>(oldfq.length + 1);
        for (String x : oldfq)
            newfq.add(x);
        newfq.add(fq);
        params.setFilterQueries(newfq.toArray(new String[newfq.size()]));
    }
    if (bq.length() > 0)
        params.setParam(DisMaxParams.BQ, bq);
    if (bf.length() > 0)
        params.setParam("boost", bf); // a boost function extension, see http://wiki.apache.org/solr/ExtendedDisMax#bf_.28Boost_Function.2C_additive.29

    // prepare result
    ConcurrentLog.info("Protocol", "SOLR QUERY: " + params.toString());
    this.cachedQuery = params;
    return params;
}

From source file:net.yacy.search.query.QueryParams.java

License:Open Source License

private SolrQuery solrImageQuery(boolean getFacets) {
    if (this.cachedQuery != null) {
        this.cachedQuery.setStart(this.offset);
        if (!getFacets)
            this.cachedQuery.setFacet(false);
        return this.cachedQuery;
    }/*from   w  w w . ja  v a2s. com*/

    // construct query
    final SolrQuery params = getBasicParams(getFacets, this.queryGoal.collectionImageFilterQuery());
    params.setQuery(this.queryGoal.collectionImageQuery(this.modifier).toString());

    // set boosts
    StringBuilder bq = new StringBuilder();
    bq.append(CollectionSchema.url_file_ext_s.getSolrFieldName()).append(":\"jpg\"");
    bq.append(" OR ").append(CollectionSchema.url_file_ext_s.getSolrFieldName()).append(":\"tif\"");
    bq.append(" OR ").append(CollectionSchema.url_file_ext_s.getSolrFieldName()).append(":\"tiff\"");
    bq.append(" OR ").append(CollectionSchema.url_file_ext_s.getSolrFieldName()).append(":\"png\"");
    params.setParam(DisMaxParams.BQ, bq.toString());

    // prepare result
    ConcurrentLog.info("Protocol", "SOLR QUERY: " + params.toString());
    this.cachedQuery = params;
    return params;
}