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

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

Introduction

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

Prototype

public SolrQuery setQuery(String query) 

Source Link

Usage

From source file:edu.cmu.lti.oaqa.bio.index.medline.annotated.query.SolrServerWrapper.java

License:Apache License

/**
 * Executes a query, additionally allows to specify result fields.
 * //from  w ww . j  av  a2  s.  c om
 * @param q           a query string.
 * @param fieldList   a list of field names.
 * @param results     the maximum number of entries to return.
 * 
 * @return a list of documents, which is an object of the type {@link org.apache.solr.common.SolrDocumentList}.
 * @throws SolrServerException
 * @throws IOException 
 */
public SolrDocumentList runQuery(String q, List<String> fieldList, int results)
        throws SolrServerException, IOException {
    SolrQuery query = new SolrQuery();
    query.setQuery(q);
    query.setRows(results);
    query.setFields(fieldList.toArray(new String[1]));
    QueryResponse rsp = mServer.query(query, METHOD.POST);
    return rsp.getResults();
}

From source file:edu.cmu.lti.oaqa.bio.index.medline.annotated.query.SolrServerWrapper.java

License:Apache License

/**
 * Executes a query, additionally allows to specify the default field, the filter query, AND result fields.
 * //from  ww w.  j ava 2  s. c om
 * @param q               a query string.
 * @param defaultField    a default field name (or null).
 * @param fieldList       a list of field names.
 * @param filterQuery     a name of the filter query that can be applied without changing scores (or null).
 * @param results         the maximum number of entries to return.
 * 
 * @return a list of documents, which is an object of the type {@link org.apache.solr.common.SolrDocumentList}.
 * @throws SolrServerException
 * @throws IOException 
 */
public SolrDocumentList runQuery(String q, String defaultField, List<String> fieldList, String filterQuery,
        int results) throws SolrServerException, IOException {
    SolrQuery query = new SolrQuery();
    query.setQuery(q);
    if (filterQuery != null)
        query.setParam("fq", filterQuery);
    if (defaultField != null)
        query.setParam("df", defaultField);
    query.setRows(results);
    query.setFields(fieldList.toArray(new String[1]));
    QueryResponse rsp = mServer.query(query, METHOD.POST);
    return rsp.getResults();
}

From source file:edu.cmu.lti.oaqa.bio.index.medline.annotated.query.SolrServerWrapper.java

License:Apache License

/**
 * Reads a value of a single- or multi-value text field from a SOLR server. 
 * /*www  .ja va2s.com*/
 * @param docId         a document ID.
 * @param idField       a name of the ID field.
 * @param textFieldName a name of the text field whose value we need to obtain.
 * @return an array of field values, if the field is single-value, the array
 *         contains only one entry.
 * @throws SolrServerException
 * @throws IOException 
 */
public ArrayList<String> getFieldText(String docId, String idField, String textFieldName)
        throws SolrServerException, IOException {
    String q = idField + ":" + docId;
    SolrQuery query = new SolrQuery();
    query.setQuery(q);
    query.setFields(textFieldName);
    QueryResponse rsp = mServer.query(query);

    ArrayList<String> docText = null;
    if (rsp.getResults().getNumFound() > 0) {
        Object o = rsp.getResults().get(0).getFieldValues(textFieldName);
        if (o instanceof String) {
            docText = new ArrayList<String>();
            docText.add((String) o);
        } else {
            @SuppressWarnings({ "unchecked" })
            ArrayList<String> results = (ArrayList<String>) o;
            docText = results;
        }
    }
    return docText;
}

From source file:edu.cmu.lti.oaqa.core.provider.solr.SolrWrapper.java

License:Apache License

public SolrDocumentList runQuery(String q, int results) throws SolrServerException {
    SolrQuery query = new SolrQuery();
    query.setQuery(escapeQuery(q));
    query.setRows(results);// ww  w .j a v a2  s  .c o  m
    query.setFields("*", "score");
    QueryResponse rsp = server.query(query, METHOD.POST);
    return rsp.getResults();
}

From source file:edu.cmu.lti.oaqa.core.provider.solr.SolrWrapper.java

License:Apache License

/** Added overloaded method for specifying field list**/
public SolrDocumentList runQuery(String q, List<String> fieldList, int results) throws SolrServerException {
    SolrQuery query = new SolrQuery();
    query.setQuery(escapeQuery(q));
    query.setRows(results);//from   w w w  .  j  a  va 2 s  .  c  o m
    query.setFields(fieldList.toArray(new String[1]));
    QueryResponse rsp = server.query(query, METHOD.POST);
    return rsp.getResults();
}

From source file:edu.cmu.lti.oaqa.openqa.test.team18.retrieval.SolrWrapperExtend.java

License:Apache License

public SolrDocumentList runQuery(String q, int results) throws SolrServerException {
    SolrQuery query = new SolrQuery();
    query.setQuery(escapeQuery(q));
    query.setRows(results);/*from w w  w  . j  a  v a  2s  .  co  m*/
    //query.setFields(fields)
    query.setFields("*", "score");
    QueryResponse rsp = server.query(query);
    return rsp.getResults();
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.accounts.admin.ajax.ProfileAutoCompleter.java

License:Open Source License

private SolrQuery buildSolrQuery() {
    SolrQuery q = new SolrQuery();
    q.setFields(NAME_RAW, URI);/*from w  w  w  . j ava 2  s  .c  o m*/
    q.setSortField(NAME_LOWERCASE_SINGLE_VALUED, ORDER.asc);
    q.setFilterQueries(SolrQueryUtils.assembleConjunctiveQuery(RDFTYPE, profileTypes, OR));
    q.setStart(0);
    q.setRows(10000);
    q.setQuery(searchWords.assembleQuery(NAME_UNSTEMMED, AC_NAME_STEMMED));
    return q;
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies.ajax.BasicProfilesGetter.java

License:Open Source License

private SolrQuery buildSolrQuery() {
    SolrQuery q = new SolrQuery();
    q.setFields(NAME_RAW, URI);//from  w  w  w . j a  v  a2s  . com
    q.setSortField(NAME_LOWERCASE_SINGLE_VALUED, ORDER.asc);
    q.setFilterQueries(SolrQueryUtils.assembleConjunctiveQuery(RDFTYPE, profileTypes, OR));
    q.setStart(0);
    q.setRows(30);
    q.setQuery(searchWords.assembleQuery(NAME_UNSTEMMED, AC_NAME_STEMMED));
    return q;
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultObjectPropertyFormGenerator.java

License:Open Source License

private boolean tooManyRangeOptions(VitroRequest vreq, HttpSession session) throws SolrServerException {
    List<String> types = getRangeTypes(vreq);
    SolrServer solrServer = SolrSetup.getSolrServer(session.getServletContext());

    //empty list means the range is not set to anything, force Thing
    if (types.size() == 0) {
        types = new ArrayList<String>();
        types.add(VitroVocabulary.OWL_THING);
    }//from w  w w .  ja v a 2  s. c  om

    long count = 0;
    for (String type : types) {
        //solr query for type count.          
        SolrQuery query = new SolrQuery();
        if (VitroVocabulary.OWL_THING.equals(type)) {
            query.setQuery("*:*");
        } else {
            query.setQuery(VitroSearchTermNames.RDFTYPE + ":" + type);
        }
        query.setRows(0);

        QueryResponse rsp = solrServer.query(query);
        SolrDocumentList docs = rsp.getResults();
        long found = docs.getNumFound();
        count = count + found;
        if (count > maxNonACRangeIndividualCount)
            break;
    }

    return count > maxNonACRangeIndividualCount;
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.DefaultObjectPropertyFormGenerator.java

License:Open Source License

private Object rangeIndividualsExist(HttpSession session, List<String> types) throws SolrServerException {
    SolrServer solrServer = SolrSetup.getSolrServer(session.getServletContext());

    boolean rangeIndividualsFound = false;
    for (String type : types) {
        //solr for type count.
        SolrQuery query = new SolrQuery();
        query.setQuery(VitroSearchTermNames.RDFTYPE + ":" + type);
        query.setRows(0);//  ww w . j  av  a  2s. co  m

        QueryResponse rsp = solrServer.query(query);
        SolrDocumentList docs = rsp.getResults();
        if (docs.getNumFound() > 0) {
            rangeIndividualsFound = true;
            break;
        }
    }

    return rangeIndividualsFound;
}