Example usage for org.apache.solr.client.solrj.response QueryResponse getMoreLikeThis

List of usage examples for org.apache.solr.client.solrj.response QueryResponse getMoreLikeThis

Introduction

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

Prototype

public NamedList<SolrDocumentList> getMoreLikeThis() 

Source Link

Usage

From source file:com.nridge.ds.solr.SolrResponseBuilder.java

License:Open Source License

private void populateMoreLikeThis(QueryResponse aQueryResponse) {
    String docName;/*  w w  w.j  av  a 2 s. com*/
    Document mltDocument;
    DataField docNameField;
    SolrDocumentList solrDocumentList;
    Logger appLogger = mAppMgr.getLogger(this, "populateMoreLikeThis");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    NamedList<SolrDocumentList> mltDocuments = aQueryResponse.getMoreLikeThis();
    if (mltDocuments != null) {
        mDocument.addRelationship(Solr.RESPONSE_MORE_LIKE_THIS, createMLTBag());
        Relationship mltRelationship = mDocument.getFirstRelationship(Solr.RESPONSE_MORE_LIKE_THIS);
        if (mltRelationship != null) {
            int mltCount = mltDocuments.size();
            DataBag mltBag = mltRelationship.getBag();
            docNameField = mltBag.getFieldByName("mlt_name");
            mltBag.setValueByName("mlt_total", mltCount);
            for (int i = 0; i < mltCount; i++) {
                docName = mltDocuments.getName(i);
                docNameField.addValue(docName);
                solrDocumentList = mltDocuments.getVal(i);
                if (solrDocumentList.getNumFound() > 0L) {
                    mltDocument = new Document(Solr.RESPONSE_MLT_DOCUMENT, createDocumentTable());
                    populateDocument(mltDocument, solrDocumentList);
                    mltRelationship.add(mltDocument);
                }
            }
        }
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}