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

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

Introduction

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

Prototype

public ModifiableSolrParams set(String name, String... val) 

Source Link

Document

Replace any existing parameter with the given name.

Usage

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   www.  j a  v a 2  s. 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.OncoTree.java

License:Open Source License

/**
 * Adds dynamic solr query parameters to {@code query}, based on the received {@code rawQuery raw query string},
 * {@code rows the maximum number of results to return}, {@code sort the sorting order}, and {@code customFilter a
 * custom filter}.// w w w.j av a 2 s.c  om
 *
 * @param rawQuery unprocessed query string
 * @param rows the maximum number of search items to return
 * @param sort the optional sort parameter
 * @param customFilter custom filter for the results
 * @param query a {@link SolrQuery solr query} object
 * @return the updated {@link SolrQuery solr query} object
 */
@Nonnull
private SolrQuery addDynamicQueryParam(@Nonnull final String rawQuery, @Nonnull final Integer rows,
        @Nullable final String sort, @Nullable final String customFilter, @Nonnull SolrQuery query) {
    final String queryString = rawQuery.trim();
    final String escapedQuery = ClientUtils.escapeQueryChars(queryString);
    if (StringUtils.isNotBlank(customFilter)) {
        query.setFilterQueries(customFilter);
    }
    query.setQuery(escapedQuery);
    query.set(SpellingParams.SPELLCHECK_Q, queryString);
    final String lastWord = StringUtils.defaultIfBlank(
            StringUtils.substringAfterLast(escapedQuery, StringUtils.SPACE), escapedQuery) + "*";
    query.set(DisMaxParams.BQ, String.format("nameSpell:%1$s^20 text:%1$s^1 textSpell:%1$s^2", lastWord));
    query.setRows(rows);
    if (StringUtils.isNotBlank(sort)) {
        for (final String sortItem : sort.split("\\s*,\\s*")) {
            query.addSort(StringUtils.substringBefore(sortItem, StringUtils.SPACE),
                    sortItem.endsWith(" desc") || sortItem.startsWith("-") ? SolrQuery.ORDER.desc
                            : SolrQuery.ORDER.asc);
        }
    }
    return query;
}

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

License:Open Source License

/**
 * Given a {@code query} object, adds global query parameters.
 *
 * @param query a {@link SolrQuery solr query} object
 *//*ww  w.  java 2s . com*/
private void addGlobalQueryParam(@Nonnull final SolrQuery query) {
    // Add global query parameters.
    query.set("spellcheck", Boolean.toString(true));
    query.set(SpellingParams.SPELLCHECK_COLLATE, Boolean.toString(true));
    query.set(SpellingParams.SPELLCHECK_COUNT, "100");
    query.set(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "3");
    query.set("lowercaseOperators", Boolean.toString(false));
    query.set("defType", "edismax");
}

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

License:Open Source License

/**
 * Given a {@code query} object, adds field query parameters.
 *
 * @param query a {@link SolrQuery solr query} object
 *//* w  ww  .  ja  v a  2s . co m*/
private void addFieldQueryParam(@Nonnull final SolrQuery query) {
    query.set(DisMaxParams.PF, "name^20 nameSpell^36 nameExact^100 namePrefix^30 text^3 textSpell^5");
    query.set(DisMaxParams.QF, "id^100 name^10 nameSpell^18 nameStub^5 text^1 textSpell^2 textStub^0.5");
}

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

License:Open Source License

/**
 * Adds dynamic solr query parameters to {@code query}, based on the received {@code rawQuery raw query string},
 * {@code rows the maximum number of results to return}, {@code sort the sorting order}, and {@code customFilter a
 * custom filter}./*from ww w . j  a  va2s .c  o  m*/
 *
 * @param rawQuery unprocessed query string
 * @param rows the maximum number of search items to return
 * @param sort the optional sort parameter
 * @param customFilter custom filter for the results
 * @param query a {@link SolrQuery solr query} object
 * @return the updated {@link SolrQuery solr query} object
 */
private SolrQuery addDynamicQueryParam(@Nonnull final String rawQuery, final Integer rows,
        @Nullable final String sort, @Nullable final String customFilter, @Nonnull SolrQuery query) {
    final String queryString = rawQuery.trim();
    final String escapedQuery = ClientUtils.escapeQueryChars(queryString);
    if (StringUtils.isNotBlank(customFilter)) {
        query.setFilterQueries(customFilter);
    }
    query.setQuery(escapedQuery);
    query.set(SpellingParams.SPELLCHECK_Q, queryString);
    final String lastWord = StringUtils.defaultIfBlank(StringUtils.substringAfterLast(escapedQuery, " "),
            escapedQuery) + "*";
    query.set(DisMaxParams.BQ,
            String.format("nameSpell:%1$s^20 defSpell:%1$s^3 text:%1$s^1 textSpell:%1$s^2", lastWord));
    query.setRows(rows);
    if (StringUtils.isNotBlank(sort)) {
        for (final String sortItem : sort.split("\\s*,\\s*")) {
            query.addSort(StringUtils.substringBefore(sortItem, " "),
                    sortItem.endsWith(" desc") || sortItem.startsWith("-") ? ORDER.desc : ORDER.asc);
        }
    }
    return query;
}

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

License:Open Source License

/**
 * Given a {@code query} object, adds global query parameters.
 *
 * @param query a {@link SolrQuery solr query} object
 * @return the {@code query} with global query parameters added
 *///w w w.j  a va 2s  . c o  m
private SolrQuery addGlobalQueryParam(@Nonnull final SolrQuery query) {
    // Add global query parameters.
    query.set("spellcheck", Boolean.toString(true));
    query.set(SpellingParams.SPELLCHECK_COLLATE, Boolean.toString(true));
    query.set(SpellingParams.SPELLCHECK_COUNT, "100");
    query.set(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "3");
    query.set("lowercaseOperators", Boolean.toString(false));
    query.set("defType", "edismax");
    return query;
}

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

License:Open Source License

/**
 * Given a {@code query} object, adds field query parameters.
 *
 * @param query a {@link SolrQuery solr query} object
 * @return the {@code query} with field parameters added
 *///from  w w  w .j  av a  2  s.c o  m
private SolrQuery addFieldQueryParam(@Nonnull final SolrQuery query) {
    query.set(DisMaxParams.PF,
            "name^20 nameSpell^36 nameExact^100 namePrefix^30 "
                    + "synonym^15 synonymSpell^25 synonymExact^70 synonymPrefix^20 "
                    + "def^7 defSpell^14 text^3 textSpell^5");
    query.set(DisMaxParams.QF, "id^100 name^10 nameSpell^18 nameStub^5 "
            + "synonym^6 synonymSpell^10 synonymStub^4 " + "def^3 defSpell^5 text^1 textSpell^2 textStub^0.5");
    return query;
}

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

License:Open Source License

@Test
public void queriesAreExtendedToIncludeRussianFieldsWhenLocaleIsRu() {
    SolrQuery query = new SolrQuery("seizures");
    query.set(DisMaxParams.QF, "name");
    query.set(DisMaxParams.PF, "name");
    this.component.extendQuery(query, this.vocabulary);
    Assert.assertEquals("name name_ru^60 synonym_ru^45 def_ru^12 ", query.get(DisMaxParams.PF));
    Assert.assertEquals("name name_ru^30 synonym_ru^21 def_ru^6 ", query.get(DisMaxParams.QF));
}

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

License:Open Source License

@Test
public void queriesAreExtendedToIncludeRussianFieldsWhenLocaleIsRuRU() {
    when(this.localizationContext.getCurrentLocale()).thenReturn(new Locale("ru", "RU"));
    SolrQuery query = new SolrQuery("seizures");
    query.set(DisMaxParams.QF, "name");
    query.set(DisMaxParams.PF, "name");
    this.component.extendQuery(query, this.vocabulary);
    Assert.assertEquals("name name_ru^60 synonym_ru^45 def_ru^12 ", query.get(DisMaxParams.PF));
    Assert.assertEquals("name name_ru^30 synonym_ru^21 def_ru^6 ", query.get(DisMaxParams.QF));
}

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

License:Open Source License

@Test
public void queriesAreExtendedToIncludeSpanishFieldsWhenLocaleIsEs() {
    SolrQuery query = new SolrQuery("seizures");
    query.set(DisMaxParams.QF, "name");
    query.set(DisMaxParams.PF, "name");
    this.component.extendQuery(query, this.vocabulary);
    Assert.assertEquals("name name_es^60 synonym_es^45 def_es^12 ", query.get(DisMaxParams.PF));
    Assert.assertEquals("name name_es^30 synonym_es^21 def_es^6 ", query.get(DisMaxParams.QF));
}