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

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

Introduction

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

Prototype

String Q

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

Click Source Link

Document

query string

Usage

From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java

License:Open Source License

@Test
public void testEnhanceParamsDoesntReplaceExistingValues() {
    ModifiableSolrParams input = new ModifiableSolrParams();
    input.set(CommonParams.Q, "field:value");
    input.set(CommonParams.FL, "id");
    input.set(CommonParams.START, 30);//from   www.  j  av  a 2 s  . c o m
    input.set(CommonParams.ROWS, 10);
    SolrParams output = SolrQueryUtils.enhanceParams(input);
    Assert.assertEquals("field:value", output.get(CommonParams.Q));
    Assert.assertEquals("id", output.get(CommonParams.FL));
    Assert.assertEquals(true, output.getBool(SpellingParams.SPELLCHECK_COLLATE));
    Assert.assertEquals(30, (int) output.getInt(CommonParams.START));
    Assert.assertEquals(10, (int) output.getInt(CommonParams.ROWS));
}

From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java

License:Open Source License

@Test
public void testApplySpellcheckSuggestions() {
    ModifiableSolrParams input = new ModifiableSolrParams();
    input.set(CommonParams.Q, "original");
    SolrParams output = SolrQueryUtils.applySpellcheckSuggestion(input, "fixed");
    Assert.assertNotNull(output);//w w  w .ja v  a2s .  c om
    Assert.assertEquals("fixed", output.get(CommonParams.Q));
}

From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java

License:Open Source License

@Test
public void testApplySpellcheckSuggestionsWithBoostQuery() {
    ModifiableSolrParams input = new ModifiableSolrParams();
    input.set(CommonParams.Q, "original with text:stab*");
    input.set(DisMaxParams.BQ, "text:stab* name:stab*^5");
    SolrParams output = SolrQueryUtils.applySpellcheckSuggestion(input, "fixed with text:stub*");
    Assert.assertNotNull(output);/*  w  w w.  j a  v a  2  s.  co  m*/
    Assert.assertEquals("fixed with text:stub* text:stab*^1.5", output.get(CommonParams.Q));
    Assert.assertArrayEquals(new String[] { "text:stab* name:stab*^5", "text:stub* name:stub*^5" },
            output.getParams(DisMaxParams.BQ));
}

From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java

License:Open Source License

@Test
public void testApplySpellcheckSuggestionsWithNull() {
    SolrParams output = SolrQueryUtils.applySpellcheckSuggestion(null, null);
    Assert.assertNull(output);//from   w  w  w.  j  av  a2s  .c o m

    ModifiableSolrParams input = new ModifiableSolrParams();
    input.set(CommonParams.Q, "original");
    output = SolrQueryUtils.applySpellcheckSuggestion(input, null);
    Assert.assertNotNull(output);
    Assert.assertEquals("original", output.get(CommonParams.Q));

    output = SolrQueryUtils.applySpellcheckSuggestion(null, "fixed");
    Assert.assertNull(output);
}

From source file:org.phenotips.ontology.internal.solr.SolrQueryUtilsTest.java

License:Open Source License

@Test
public void testGetCacheKey() {
    ModifiableSolrParams input = new ModifiableSolrParams();
    input.set(CommonParams.Q, "some value");
    input.add(DisMaxParams.BQ, "text:stub*");
    input.add(DisMaxParams.BQ, "stub*");
    input.set(CommonParams.FQ, "is_a:HP\\:0000108");
    String output = SolrQueryUtils.getCacheKey(input);
    Assert.assertEquals("{q:[some value]\nbq:[text:stub*, stub*]\nfq:[is_a:HP\\:0000108]\n}", output);
}

From source file:org.phenotips.similarity.internal.SolrSimilarPatientsFinder.java

License:Open Source License

/**
 * Generates a Solr query that tries to match patients similar to the reference.
 *
 * @param referencePatient the reference patient
 * @return a query populated with terms from the patient phenotype
 *///from  ww w.  ja  va2s  .  c  o  m
private SolrQuery generateQuery(Patient referencePatient, boolean prototypes) {
    SolrQuery query = new SolrQuery();
    StringBuilder q = new StringBuilder();
    // FIXME This is a very basic implementation, to be revisited
    for (Feature phenotype : referencePatient.getFeatures()) {
        if (StringUtils.isNotBlank(phenotype.getId())) {
            q.append(phenotype.getType() + ":" + ClientUtils.escapeQueryChars(phenotype.getId()) + " ");
        }
    }
    // Ignore the reference patient itself (unless reference patient is a temporary in-memory only
    // patient, e.g. a RemoteMatchingPatient created from remote patient data obtained via remote-matching API)
    if (referencePatient.getDocument() != null) {
        q.append("-document:" + ClientUtils.escapeQueryChars(referencePatient.getDocument().toString()));
    }
    q.append(prototypes ? " +" : " -").append("document:xwiki\\:data.MIM*");
    query.add(CommonParams.Q, q.toString());
    //logger.error("SOLRQUERY generated: {}", query.toString());
    return query;
}

From source file:org.phenotips.solr.OmimScriptService.java

License:Open Source License

/**
 * Prepare the map of parameters that can be passed to a Solr query, in order to get a list of diseases matching the
 * selected positive and negative phenotypes.
 *
 * @param phenotypes the list of already selected phenotypes
 * @param nphenotypes phenotypes that are not observed in the patient
 * @return the computed Solr query parameters
 *//* www.j ava  2 s. c om*/
private MapSolrParams prepareParams(Collection<String> phenotypes, Collection<String> nphenotypes) {
    Map<String, String> params = new HashMap<String, String>();
    String q = "symptom:" + StringUtils.join(phenotypes, " symptom:");
    if (nphenotypes.size() > 0) {
        q += "  not_symptom:" + StringUtils.join(nphenotypes, " not_symptom:");
    }
    q += " -nameSort:\\** -nameSort:\\+* -nameSort:\\^*";
    params.put(CommonParams.Q, q.replaceAll("HP:", "HP\\\\:"));
    params.put(CommonParams.ROWS, "100");
    params.put(CommonParams.START, "0");
    params.put(CommonParams.DEBUG_QUERY, Boolean.toString(true));
    params.put(CommonParams.EXPLAIN_STRUCT, Boolean.toString(true));

    return new MapSolrParams(params);
}

From source file:org.phenotips.termrequester.db.solr.SolrDatabaseService.java

License:Open Source License

@Override
public List<Phenotype> searchPhenotypes(String text) throws IOException {
    checkUp();/*from w  ww.j  a  va  2  s .  c o m*/
    try {
        SolrQuery q = new SolrQuery();
        String escaped = ClientUtils.escapeQueryChars(text);
        q.add(CommonParams.Q, escaped);
        q.add(SpellingParams.SPELLCHECK_Q, text);
        q.add(DisMaxParams.PF,
                String.format("%s^20 %s^36 %s^100 %s^30 %s^15 %s^25 %s^70 %s^20 %s^3 %s^5", Schema.NAME,
                        Schema.NAME_SPELL, Schema.NAME_EXACT, Schema.NAME_PREFIX, Schema.SYNONYM,
                        Schema.SYNONYM_SPELL, Schema.SYNONYM_EXACT, Schema.SYNONYM_PREFIX, Schema.TEXT,
                        Schema.TEXT_SPELL));
        String qstring = String.format("%s^10 %s^18 %s^5 %s^6 %s^10 %s^3 %s^1 %s^2 %s^0.5", Schema.NAME,
                Schema.NAME_SPELL, Schema.NAME_STUB, Schema.SYNONYM, Schema.SYNONYM_SPELL, Schema.SYNONYM_STUB,
                Schema.TEXT, Schema.TEXT, Schema.TEXT_SPELL, Schema.TEXT_STUB);
        qstring = addStatusFilter(qstring, Phenotype.Status.SYNONYM);
        q.add(DisMaxParams.QF, qstring);
        q.add("spellcheck", Boolean.toString(true));
        q.add(SpellingParams.SPELLCHECK_COLLATE, Boolean.toString(true));
        q.add(SpellingParams.SPELLCHECK_COUNT, "100");
        q.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "3");
        q.add("lowercaseOperators", Boolean.toString(false));
        q.add("defType", "edismax");
        QueryResponse resp = server.query(q);
        List<SolrDocument> results = resp.getResults();
        List<Phenotype> retval = new ArrayList<>(results.size());
        for (SolrDocument doc : results) {
            retval.add(mapper.fromDoc(doc));
        }
        return retval;
    } catch (SolrServerException e) {
        throw new IOException(e);
    }
}

From source file:org.phenotips.vocabulary.internal.GeneNomenclature.java

License:Open Source License

private SolrParams produceDynamicSolrParams(String originalQuery, Integer rows, String sort,
        String customFilter) {/*w w  w  .  j a v  a  2 s  .  c o m*/
    String escapedQuery = ClientUtils.escapeQueryChars(originalQuery.trim());

    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(CommonParams.Q, escapedQuery);
    params.add(CommonParams.ROWS, rows.toString());
    if (StringUtils.isNotBlank(sort)) {
        params.add(CommonParams.SORT, sort);
    }
    params.add(CommonParams.FQ, StringUtils.defaultIfBlank(customFilter, "status:Approved"));
    return params;
}

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

License:Open Source License

@Override
public VocabularyTerm getTerm(String id) {
    VocabularyTerm result = this.externalServicesAccess.getTermCache().get(id);
    if (result == null) {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set(CommonParams.Q, ID_FIELD_NAME + ':' + ClientUtils.escapeQueryChars(id));
        SolrDocumentList allResults = this.search(params);
        if (allResults != null && !allResults.isEmpty()) {
            result = new SolrVocabularyTerm(allResults.get(0), this);
            this.externalServicesAccess.getTermCache().set(id, result);
        } else {// www.  j a  v  a2  s  .  c  o  m
            this.externalServicesAccess.getTermCache().set(id, EMPTY_MARKER);
        }
    }
    return (result == EMPTY_MARKER) ? null : result;
}