Example usage for org.apache.solr.common SolrDocumentList SolrDocumentList

List of usage examples for org.apache.solr.common SolrDocumentList SolrDocumentList

Introduction

In this page you can find the example usage for org.apache.solr.common SolrDocumentList SolrDocumentList.

Prototype

SolrDocumentList

Source Link

Usage

From source file:com.idealista.solrmeter.BaseTestCase.java

License:Apache License

/**
 * Creates a query response// ww w . j  a  v a2  s  . c  om
 * @param qTime
 * @return
 */
protected QueryResponse createQueryResponse(int qTime) {
    QueryResponse response = new QueryResponse();
    NamedList<Object> headerNamedList = new NamedList<Object>();
    headerNamedList.add("QTime", qTime);
    NamedList<Object> responseNamedList = new NamedList<Object>();
    responseNamedList.add("responseHeader", headerNamedList);

    SolrDocumentList resultsNamedList = new SolrDocumentList();
    resultsNamedList.add(new SolrDocument());
    resultsNamedList.add(new SolrDocument());
    resultsNamedList.add(new SolrDocument());
    resultsNamedList.setNumFound(10);
    responseNamedList.add("response", resultsNamedList);
    response.setResponse(responseNamedList);
    return response;
}

From source file:com.lucidworks.fusion.support.tests.DocumentLevelACP.java

public ArrayList<SolrDocument> run() {
    ArrayList<SolrDocument> list = new SolrDocumentList();
    try {/*ww w . j  av  a  2s. c  o m*/
        SolrClient client = getSolrClient();

        SolrQuery query = new SolrQuery();
        query.setQuery("*");
        query.setRows(10);

        QueryResponse resp = client.query(DEFAULT_COLLECTION, query);
        SolrDocumentList results = resp.getResults();
        SolrDocument doc;
        for (int i = 0; i < results.size(); ++i) {
            System.out.println(results.get(i));
            doc = results.get(i);
            if (hasACP(doc)) {
                list.add(doc);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return list;
}

From source file:com.sn.solr.plugin.common.SolrHelper.java

License:Apache License

/**
 * Constructs {@link SolrDocumentList} from the current {@link SolrQueryRequest}
 * and {@link SolrQueryResponse}./*  ww w .ja va  2s.  c  o  m*/
 * 
 * @param req {@link SolrQueryRequest}
 * @param res {@link SolrQueryResponse}
 * @return
 * @throws CorruptIndexException
 * @throws IOException
 */
public static SolrDocumentList getSolrDocList(SolrQueryRequest req, SolrQueryResponse res)
        throws CorruptIndexException, IOException {
    DocSlice slice = (DocSlice) res.getValues().get(RESP_EL_TAG);
    Set<String> returnFields = SolrHelper.getReturnFields(req);
    SolrDocumentList docList = new SolrDocumentList();
    for (DocIterator it = slice.iterator(); it.hasNext();) {
        int docId = it.nextDoc();
        Document doc = req.getSearcher().getReader().document(docId);
        SolrDocument sdoc = new SolrDocument();
        for (Fieldable f : doc.getFields()) {
            String fn = f.name();
            if (returnFields.contains(fn)) {
                sdoc.addField(fn, doc.get(fn));
            }
        }
        docList.add(sdoc);
    }
    docList.setMaxScore(slice.maxScore());
    docList.setNumFound(slice.matches());
    docList.setStart(slice.offset());
    return docList;
}

From source file:com.sn.solr.utils.common.SolrHelper.java

License:Apache License

/**
 * Constructs {@link SolrDocumentList} from the current {@link SolrQueryRequest}
 * and {@link SolrQueryResponse}.//from  www.  j a  v a 2 s  . c  om
 * 
 * @param req {@link SolrQueryRequest}
 * @param res {@link SolrQueryResponse}
 * @return
 * @throws CorruptIndexException
 * @throws IOException
 */
public static SolrDocumentList getSolrDocList(SolrQueryRequest req, SolrQueryResponse res)
        throws CorruptIndexException, IOException {
    DocSlice slice = (DocSlice) res.getValues().get(RESP_EL_TAG);
    Set<String> returnFields = SolrHelper.getReturnFields(req);
    SolrDocumentList docList = new SolrDocumentList();
    for (DocIterator it = slice.iterator(); it.hasNext();) {
        int docId = it.nextDoc();
        Document doc = req.getSearcher().getReader().document(docId);
        SolrDocument sdoc = new SolrDocument();
        for (Fieldable f : doc.getFields()) {
            String fn = f.name();
            if (returnFields.contains(fn)) {
                sdoc.addField(fn, doc.get(fn));
            }
        }
        docList.add(sdoc);
    }
    docList.setMaxScore(slice.maxScore());
    docList.setNumFound(slice.matches());
    return docList;
}

From source file:com.sp.Daemon.QueryHandler.java

License:Open Source License

public void run() {

    try {//  ww  w .  jav a2 s  . co m

        String UserInput = ReicvUserInput();

        LOG.info("Connection from IP : " + ClientSocket.getRemoteSocketAddress());

        if (!UserInput.isEmpty()) { //virtualizing query string

            LOG.info("Received data : " + UserInput);

            if (Query.Parse(UserInput, ClientSocket, this.getId()) == null) {
                ClientSocket.close();
                return;
            }

            Query.parseKeywords(UserInput);

            Query.Decide();

            if (Query.call_stack.isEmpty()) {
                return;
            }
            QueryResponse Response = Gatherer.Gather(Query);

            SolrDocumentList docs = new SolrDocumentList();
            if (!Response.getResults().isEmpty()) {

                docs = Sorter.sort(Response, Query.sort_stack);

                LOG.info("Match Count : " + docs.size());
            }

            ForgeAndSend(docs);

        }

    } finally {
        LOG.info(Thread.currentThread().getName() + " Request Managed");
        try {
            this.Query.clear();
            this.Gatherer.clear();
            this.pending = true;

            ClientSocket.close();
            //Clearing call_stack and more

        } catch (IOException ex) {
            new ExceptionHandler(ex);
        }
        return;
    }

}

From source file:com.sp.Parser.JsonParser.java

License:Open Source License

public static String getEmpty() {
    SolrDocumentList list = new SolrDocumentList();
    return JSONUtil.toJSON(list);
}

From source file:com.sp.Parser.Sorter.java

License:Open Source License

public SolrDocumentList sort(QueryResponse Response, HashMap<Object, Arguments> pSort_stack) {

    SolrDocumentList invoke_ret_docs;/*w  w  w .  j  a va 2s  .  com*/
    SolrDocumentList ret_docs = new SolrDocumentList();

    try {
        for (Map.Entry<Object, Arguments> entry : pSort_stack.entrySet()) {
            String method_name = (String) entry.getKey();
            Arguments arguments = entry.getValue();

            while (!arguments.isEmpty()) {
                Object object = arguments.pop();
                Method method = this.getClass().getDeclaredMethod(method_name,
                        new Class[] { Object[].class, QueryResponse.class });
                invoke_ret_docs = (SolrDocumentList) method.invoke(this, (Object) object, Response);

                ret_docs.addAll(invoke_ret_docs);
            }
        }

    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
            | NoSuchMethodException | SecurityException ex) {
        LOG.error("mmh ", ex);
    }
    ret_docs = Utils.DedupByBookId(ret_docs);
    return ret_docs;
}

From source file:com.sp.Parser.Sorter.java

License:Open Source License

private SolrDocumentList Dedup_Relate_Double(List<Entry<String, Double>> entries, SolrDocumentList docs) {

    for (Iterator<Entry<String, Double>> it = entries.iterator(); it.hasNext();) {
        Entry<String, Double> entry = it.next();
        if (entry.getValue() == 0) {
            entries.remove(entry);/*from  ww  w. jav a 2  s .  c  o m*/
        }
    }

    SolrDocumentList return_docs = new SolrDocumentList();
    ArrayList<String> product_ids = new ArrayList<>();
    ArrayList<String> book_ids = new ArrayList<>();

    for (Iterator<Entry<String, Double>> it = entries.iterator(); it.hasNext();) {
        Entry<String, Double> entry = it.next();
        String product_id = entry.getKey();

        for (Iterator<SolrDocument> it1 = docs.iterator(); it1.hasNext();) {
            SolrDocument solrDocument = it1.next();
            String solr_product_id = solrDocument.getFieldValue("product_id").toString();
            String solr_book_id = solrDocument.getFieldValue("book_id").toString();

            if (!product_ids.contains(solr_product_id) && product_id.equals(solr_product_id)
                    && !book_ids.contains(solr_book_id)) {
                book_ids.add(solr_book_id);
                product_ids.add(solr_product_id);
                return_docs.add(solrDocument);
            }
        }
    }
    return return_docs;
}

From source file:com.sp.Parser.Sorter.java

License:Open Source License

private SolrDocumentList Dedup_Relate_Integer(List<Entry<String, Integer>> entries, SolrDocumentList docs) {

    for (Iterator<Entry<String, Integer>> it = entries.iterator(); it.hasNext();) {
        Entry<String, Integer> entry = it.next();
        if (entry.getValue() == 0) {
            entries.remove(entry);/*from ww  w  . ja v a 2 s .c om*/
        }
    }

    SolrDocumentList return_docs = new SolrDocumentList();
    ArrayList<String> product_ids = new ArrayList<>();
    ArrayList<String> book_ids = new ArrayList<>();

    for (Iterator<Entry<String, Integer>> it = entries.iterator(); it.hasNext();) {
        Entry<String, Integer> entry = it.next();
        String product_id = entry.getKey();

        for (Iterator<SolrDocument> it1 = docs.iterator(); it1.hasNext();) {
            SolrDocument solrDocument = it1.next();

            String solr_product_id = solrDocument.getFieldValue("product_id").toString();
            String solr_book_id = solrDocument.getFieldValue("book_id").toString();

            if (!product_ids.contains(solr_product_id) && product_id.equals(solr_product_id)
                    && !book_ids.contains(solr_book_id)) {
                book_ids.add(solr_book_id);
                product_ids.add(solr_product_id);
                return_docs.add(solrDocument);
            }
        }
    }

    return return_docs;
}

From source file:com.sp.Parser.Utils.java

License:Open Source License

public static SolrDocumentList SortListByProductId(ArrayList<String> TempQuery, SolrDocumentList list) {

    SolrDocumentList TempList = new SolrDocumentList();

    String doc_product_id;/*w w w .  ja  v a 2 s . co m*/
    for (String product_id : TempQuery) {

        for (SolrDocument doc : list) {
            doc_product_id = doc.getFieldValue("product_id").toString();

            if (doc_product_id.equalsIgnoreCase(product_id)) {
                TempList.add(doc);
                break;
            }
        }
    }

    return TempList;
}