Example usage for org.apache.solr.common.params CommonParams ROWS

List of usage examples for org.apache.solr.common.params CommonParams ROWS

Introduction

In this page you can find the example usage for org.apache.solr.common.params CommonParams ROWS.

Prototype

String ROWS

To view the source code for org.apache.solr.common.params CommonParams ROWS.

Click Source Link

Document

number of documents to return starting at "start"

Usage

From source file:org.phenotips.vocabulary.internal.solr.AbstractCSVSolrVocabulary.java

License:Open Source License

@Override
public String getVersion() {
    QueryResponse response;//from  w ww .ja  v  a 2  s .  c o m
    SolrQuery query = new SolrQuery();
    SolrDocumentList termList;
    SolrDocument firstDoc;

    query.setQuery("version:*");
    query.set(CommonParams.ROWS, "1");
    try {
        response = this.externalServicesAccess.getSolrConnection().query(query);
        termList = response.getResults();

        if (!termList.isEmpty()) {
            firstDoc = termList.get(0);
            return firstDoc.getFieldValue(VERSION_FIELD_NAME).toString();
        }
    } catch (SolrServerException | SolrException ex) {
        this.logger.warn("Failed to query ontology version: {}", ex.getMessage());
    } catch (IOException ex) {
        this.logger.error("IOException while getting ontology version", ex);
    }
    return null;
}

From source file:org.phenotips.vocabulary.internal.solr.AbstractOWLSolrVocabulary.java

License:Open Source License

@Override
public String getVersion() {
    final SolrQuery query = new SolrQuery();
    query.setQuery("version:*");
    query.set(CommonParams.ROWS, "1");
    try {/*  ww w . j  a va  2  s.c o m*/
        final QueryResponse response = this.externalServicesAccess.getSolrConnection(getCoreName())
                .query(query);
        final SolrDocumentList termList = response.getResults();

        if (!termList.isEmpty()) {
            final SolrDocument firstDoc = termList.get(0);
            return firstDoc.getFieldValue(VERSION_FIELD_NAME).toString();
        }
    } catch (SolrServerException | SolrException | IOException ex) {
        this.logger.warn("Failed to query ontology version: {}", ex.getMessage());
    }
    return null;
}

From source file:org.phenotips.vocabulary.internal.solr.AbstractSolrVocabulary.java

License:Open Source License

/**
 * Get the number of entries that match a specific Lucene query.
 *
 * @param query a valid the Lucene query as string
 * @return the number of entries matching the query
 *//*from ww w  .  j  a  va2s . co  m*/
protected long count(String query) {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CommonParams.Q, query);
    params.set(CommonParams.START, "0");
    params.set(CommonParams.ROWS, "0");
    SolrDocumentList results;
    try {
        this.logger.debug("Counting terms matching [{}] in [{}]", query, getCoreName());
        results = this.externalServicesAccess.getSolrConnection().query(params).getResults();
        return results.getNumFound();
    } catch (Exception ex) {
        this.logger.error("Failed to count ontology terms: {}", ex.getMessage(), ex);
        return -1;
    }
}

From source file:org.phenotips.vocabulary.internal.solr.EthnicityOntology.java

License:Open Source License

@Override
public List<VocabularyTerm> search(String input, int maxResults, String sort, String customFilter) {
    Map<String, String> searchMap = new HashMap<>();
    Map<String, String> optionsMap = new HashMap<>();
    searchMap.put("nameGram", input);

    // Order by population size:
    if (StringUtils.isBlank(sort)) {
        searchMap.put("_val_", "popsize");
    } else {/*  w  ww  . j  a  va2 s  .com*/
        optionsMap.put(CommonParams.SORT, sort);
    }

    optionsMap.put(CommonParams.ROWS, Integer.toString(maxResults));

    return search(searchMap, optionsMap);
}

From source file:org.phenotips.vocabulary.internal.solr.HumanPhenotypeOntology.java

License:Open Source License

private SolrParams produceDynamicSolrParams(String originalQuery, Integer rows, String sort, String customFq,
        boolean isId) {
    String query = originalQuery.trim();
    ModifiableSolrParams params = new ModifiableSolrParams();
    String escapedQuery = ClientUtils.escapeQueryChars(query);
    if (isId) {/*from ww  w . j  av  a2  s  .c  o  m*/
        params.add(CommonParams.FQ, StringUtils.defaultIfBlank(customFq,
                new MessageFormat("id:{0} alt_id:{0}").format(new String[] { escapedQuery })));
    } else {
        params.add(CommonParams.FQ, StringUtils.defaultIfBlank(customFq, "term_category:HP\\:0000118"));
    }
    params.add(CommonParams.Q, escapedQuery);
    params.add(SpellingParams.SPELLCHECK_Q, query);
    params.add(CommonParams.ROWS, rows.toString());
    if (StringUtils.isNotBlank(sort)) {
        params.add(CommonParams.SORT, sort);
    }
    return params;
}

From source file:org.phenotips.vocabulary.internal.solr.MendelianInheritanceInMan.java

License:Open Source License

private SolrParams produceDynamicSolrParams(String originalQuery, Integer rows, String sort, String customFq) {
    String query = originalQuery.trim();
    ModifiableSolrParams params = new ModifiableSolrParams();
    String escapedQuery = ClientUtils.escapeQueryChars(query);
    params.add(CommonParams.FQ,//from  ww w. ja v  a 2s  .  co m
            StringUtils.defaultIfBlank(customFq, "-(nameSort:\\** nameSort:\\+* nameSort:\\^*)"));
    params.add(CommonParams.Q, escapedQuery);
    params.add(SpellingParams.SPELLCHECK_Q, query);
    String lastWord = StringUtils.substringAfterLast(escapedQuery, " ");
    if (StringUtils.isBlank(lastWord)) {
        lastWord = escapedQuery;
    }
    lastWord += "*";
    params.add(DisMaxParams.BQ,
            String.format("nameSpell:%1$s^20 keywords:%1$s^2 text:%1$s^1 textSpell:%1$s^2", lastWord));
    params.add(CommonParams.ROWS, rows.toString());
    if (StringUtils.isNotBlank(sort)) {
        params.add(CommonParams.SORT, sort);
    }
    return params;
}

From source file:org.phenotips.vocabulary.internal.solr.MendelianInheritanceInMan.java

License:Open Source License

@Override
public String getVersion() {
    SolrQuery query = new SolrQuery();
    query.setQuery("version:*");
    query.set(CommonParams.ROWS, "1");
    try {//from  w w  w.  j a va 2s. c o  m
        QueryResponse response = this.externalServicesAccess.getSolrConnection().query(query);
        SolrDocumentList termList = response.getResults();
        if (!termList.isEmpty()) {
            return termList.get(0).getFieldValue("version").toString();
        }
    } catch (SolrServerException | SolrException ex) {
        this.logger.warn("Failed to query vocabulary version: {}", ex.getMessage());
    } catch (IOException ex) {
        this.logger.error("IOException while getting vocabulary version", ex);
    }
    return null;
}

From source file:org.phenotips.vocabulary.internal.solr.SolrQueryUtils.java

License:Open Source License

/**
 * Adds extra parameters to a Solr query for better term searches, including custom options. More specifically, adds
 * parameters for requesting the score to be included in the results, for requesting a spellcheck result, and sets
 * the {@code start} and {@code rows} parameters when missing.
 *
 * @param originalParams the original Solr parameters to enhance
 * @param queryOptions extra options to include in the query; these override the default values, but don't override
 *            values already set in the query
 * @return the enhanced parameters/*from  w  w  w.  jav  a2  s .  com*/
 */
public static SolrParams enhanceParams(SolrParams originalParams, Map<String, String> queryOptions) {
    if (originalParams == null) {
        return null;
    }
    ModifiableSolrParams newParams = new ModifiableSolrParams();
    newParams.set(CommonParams.START, "0");
    newParams.set(CommonParams.ROWS, "1000");
    newParams.set(CommonParams.FL, "* score");
    if (queryOptions != null) {
        for (Map.Entry<String, String> item : queryOptions.entrySet()) {
            newParams.set(item.getKey(), item.getValue());
        }
    }
    for (Map.Entry<String, Object> item : originalParams.toNamedList()) {
        if (item.getValue() != null && item.getValue() instanceof String[]) {
            newParams.set(item.getKey(), (String[]) item.getValue());
        } else {
            newParams.set(item.getKey(), String.valueOf(item.getValue()));
        }
    }
    if (newParams.get(SPELLCHECK) == null) {
        newParams.set(SPELLCHECK, Boolean.toString(true));
        newParams.set(SpellingParams.SPELLCHECK_COLLATE, Boolean.toString(true));
    }
    return newParams;
}

From source file:sk.dob.search.solr.handler.component.PagerComponent.java

License:GNU General Public License

@Override
@SuppressWarnings("unchecked")
public void process(ResponseBuilder rb) throws IOException {
    /* get request params */
    SolrParams par = rb.req.getParams();
    int rows = par.getInt(CommonParams.ROWS, 0);
    int start = par.getInt(CommonParams.START, 0);
    int pages = par.getInt(PARAM_PAGER, 0);
    int pages_pre = par.getInt(PARAM_PAGER_PRE, 2);

    /* neet to work ? */
    if (pages == 0 || rows == 0 || rb == null || rb.getResults() == null)
        return;/*from  w  ww.j  a v a2 s.  co m*/

    /* select result list */
    int doc_count = 0;

    if (rb.getResults().docSet != null)
        doc_count = rb.getResults().docSet.size();
    else
        return;

    /* pager list */
    NamedList lst = new SimpleOrderedMap<Object>();
    NamedList lst2 = new SimpleOrderedMap<Object>();

    /* paging pages */
    int page_count = doc_count / rows;
    int page_actual = start / rows;
    int page_pre = pages_pre;
    int page_post = pages - page_pre - 1;

    /* last page */
    if (doc_count % rows != 0)
        page_count++;

    /* page range */
    if (page_actual - page_pre < 0) {
        page_post += -(page_actual - page_pre);
        page_pre -= -(page_actual - page_pre);
    } else if (page_actual + page_post > page_count) {
        page_post = pages - page_pre;
        page_pre = page_actual + pages - page_count;
    }

    /* sanity */
    if (page_pre < 0)
        page_pre = 0;
    if (page_post < 0)
        page_post = 0;

    /* next pages list */
    int i = (page_actual - page_pre);
    for (i = (i <= 0 ? 0 : i); i < page_count && i <= (page_actual + page_post); i++)
        lst2.add(Integer.toString(i + 1), i * rows);
    lst.add("pages", lst2);

    /* navi */
    if (page_actual > 0)
        lst.add("prev", (page_actual - 1) * rows);
    if (page_actual - page_pre > 0)
        lst.add("first", 0);
    if (page_actual < (page_count - 1))
        lst.add("next", (page_actual + 1) * rows);
    if (page_actual + page_post < (page_count - 1))
        lst.add("last", (page_count - 1) * rows);
    lst.add("actual", page_actual + 1);
    lst.add("count", page_count);

    /* finish */
    rb.rsp.add("pager", lst);
}