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

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

Introduction

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

Prototype

public SolrQuery() 

Source Link

Usage

From source file:edu.cmu.lti.f12.hw2.hw2_team01.retrieval.SimpleSolrWrapper.java

License:Apache License

public SolrDocumentList runQuery(String q, int results, String type, String mm, String Geneboost,
        String Diseboost, String Verbboost) throws SolrServerException {
    SolrQuery query = new SolrQuery();
    if (type.equals("dismax")) {
        query.setParam("defType", "edismax");
        query.setParam("qf", "text");
        query.setParam("mm", mm);
        query.setParam("pf", "text^100");
    }//from  ww w  . ja  v a  2s. c  o m

    query.setQuery(getBoosts(escapeQuery(q), Geneboost, Diseboost, Verbboost));
    query.setRows(results);
    query.setFields("*", "score");
    //can also try nested query for different boosts of phrase in text
    //q=revised+AND+book+AND+_query_:"{!dismax qf=title pf=title^10 v=$qq}"&qq=revised+book

    System.out.println(query.toString());

    QueryResponse rsp = server.query(query);
    return rsp.getResults();
}

From source file:edu.cmu.lti.f12.hw2.hw2_team01.retrieval.SimpleSolrWrapper.java

License:Apache License

public SolrDocumentList runQuery(String q, int results, String type, String Geneboost, String Diseboost,
        String Verbboost) throws SolrServerException {
    SolrQuery query = new SolrQuery();
    if (type.equals("dismax")) {
        query.setParam("defType", "edismax");
        query.setParam("qf", "text");
        query.setParam("pf", "text^100");
    }//from ww w .j ava 2  s.  c  om
    query.setQuery(getBoosts(escapeQuery(q), Geneboost, Diseboost, Verbboost));
    query.setRows(results);
    query.setFields("*", "score");
    //can also try nested query for different boosts of phrase in text
    //q=revised+AND+book+AND+_query_:"{!dismax qf=title pf=title^10 v=$qq}"&qq=revised+book

    System.out.println(query.toString());

    QueryResponse rsp = server.query(query);
    return rsp.getResults();
}

From source file:edu.cmu.lti.f12.hw2.hw2_team01.retrieval.SimpleSolrWrapper.java

License:Apache License

public String getDocText(String id) throws SolrServerException {
    String q = "id:" + id;
    SolrQuery query = new SolrQuery();
    query.setQuery(q);//from w  ww  .  j  av a  2s.  co  m
    query.setFields("text");
    QueryResponse rsp = server.query(query);

    String docText = "";
    if (rsp.getResults().getNumFound() > 0) {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        ArrayList<String> results = (ArrayList) rsp.getResults().get(0).getFieldValues("text");
        docText = results.get(0);
    }
    return docText;
}

From source file:edu.cmu.lti.oaqa.annographix.solr.SolrServerWrapper.java

License:Apache License

/**
 * Executes a string query.// ww  w. jav  a2 s  .c o  m
 * 
 * @param q        a query string.
 * @param numRet   the maximum number of entries to return.  
 * @return a list of documents, an object of the type {@link org.apache.solr.common.SolrDocumentList}. 
 * @throws SolrServerException
 */
public SolrDocumentList runQuery(String q, int numRet) throws SolrServerException {
    SolrQuery query = new SolrQuery();
    query.setQuery(q);
    query.setRows(numRet);
    query.setFields("*", "score");
    QueryResponse rsp = mServer.query(query, METHOD.POST);
    return rsp.getResults();
}

From source file:edu.cmu.lti.oaqa.annographix.solr.SolrServerWrapper.java

License:Apache License

/**
 * Executes a query, additionally allows to specify result fields.
 * /*from w  w  w .j  a v  a  2  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
 */
public SolrDocumentList runQuery(String q, List<String> fieldList, int results) throws SolrServerException {
    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.annographix.solr.SolrServerWrapper.java

License:Apache License

/**
 * Executes a query, additionally allows to specify the default field, the filter query, AND result fields.
 * /*from  w  w  w  . j a v  a2 s .  c  o  m*/
 * @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
 */
public SolrDocumentList runQuery(String q, String defaultField, List<String> fieldList, String filterQuery,
        int results) throws SolrServerException {
    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.annographix.solr.SolrServerWrapper.java

License:Apache License

/**
 * Reads a value of a single- or multi-value text field from a SOLR server. 
 * /*from   w  w  w. j  a v  a2  s  .  co  m*/
 * @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
 */
public ArrayList<String> getFieldText(String docId, String idField, String textFieldName)
        throws SolrServerException {
    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.bio.index.medline.annotated.query.SolrServerWrapper.java

License:Apache License

/**
 * Executes a string query./*from ww  w.j  a  v a2 s. c  o m*/
 * 
 * @param q        a query string.
 * @param numRet   the maximum number of entries to return.  
 * @return a list of documents, an object of the type {@link org.apache.solr.common.SolrDocumentList}. 
 * @throws SolrServerException
 * @throws IOException 
 */
public SolrDocumentList runQuery(String q, int numRet) throws SolrServerException, IOException {
    SolrQuery query = new SolrQuery();
    query.setQuery(q);
    query.setRows(numRet);
    query.setFields("*", "score");
    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 result fields.
 * /*from  www.  java2  s.  c o  m*/
 * @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  w  w  w .j  a va 2s  .  co m*/
 * @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();
}