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

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

Introduction

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

Prototype

public SolrQuery setRows(Integer rows) 

Source Link

Usage

From source file:org.dspace.app.cris.batch.ScriptCrisSubscribe.java

License:Open Source License

/**
 * Sends an email to the given e-person with details of new items in the
 * given dspace object (MUST be a community or a collection), items that
 * appeared yesterday. No e-mail is sent if there aren't any new items in
 * any of the dspace objects.//from  w w  w . ja  va  2 s  .  c  o m
 * 
 * @param context
 *            DSpace context object
 * @param eperson
 *            eperson to send to
 * @param rpkeys
 *            List of DSpace Objects
 * @param test
 * @throws SearchServiceException
 */
public static void sendEmail(Researcher researcher, Context context, EPerson eperson, List<String> rpkeys,
        boolean test, List<String> relationFields)
        throws IOException, MessagingException, SQLException, SearchServiceException {

    CrisSearchService searchService = researcher.getCrisSearchService();

    // Get a resource bundle according to the eperson language preferences
    Locale supportedLocale = I18nUtil.getEPersonLocale(eperson);

    StringBuffer emailText = new StringBuffer();
    boolean isFirst = true;

    for (String rpkey : rpkeys) {
        SolrQuery query = new SolrQuery();
        query.setFields("search.resourceid");
        query.addFilterQuery("{!field f=search.resourcetype}" + Constants.ITEM, "{!field f=inarchive}true");

        for (String tmpRelations : relationFields) {
            String fq = "{!field f=" + tmpRelations + "}" + rpkey;
            query.addFilterQuery(fq);
        }

        query.setRows(Integer.MAX_VALUE);

        if (ConfigurationManager.getBooleanProperty("eperson.subscription.onlynew", false)) {
            // get only the items archived yesterday
            query.setQuery("dateaccessioned:(NOW/DAY-1DAY)");
        } else {
            // get all item modified yesterday but not published the day
            // before
            // and all the item modified today and archived yesterday
            query.setQuery(
                    "(item.lastmodified:(NOW/DAY-1DAY) AND dateaccessioned:(NOW/DAY-1DAY)) OR ((item.lastmodified:(NOW/DAY) AND dateaccessioned:(NOW/DAY-1DAY)))");
        }

        QueryResponse qResponse = searchService.search(query);
        SolrDocumentList results = qResponse.getResults();

        // Only add to buffer if there are new items
        if (results.getNumFound() > 0)

        {
            if (!isFirst) {
                emailText.append("\n---------------------------------------\n");
            } else {
                isFirst = false;
            }

            emailText.append(I18nUtil.getMessage("org.dspace.eperson.Subscribe.new-items", supportedLocale))
                    .append(" ").append(rpkey).append(": ").append(results.getNumFound()).append("\n\n");

            for (SolrDocument solrDoc : results)

            {
                Item item = Item.find(context, (Integer) solrDoc.getFieldValue("search.resourceid"));

                DCValue[] titles = item.getDC("title", null, Item.ANY);
                emailText.append("      ")
                        .append(I18nUtil.getMessage("org.dspace.eperson.Subscribe.title", supportedLocale))
                        .append(" ");

                if (titles.length > 0) {
                    emailText.append(titles[0].value);
                } else {
                    emailText.append(
                            I18nUtil.getMessage("org.dspace.eperson.Subscribe.untitled", supportedLocale));
                }

                DCValue[] authors = item.getDC("contributor", Item.ANY, Item.ANY);

                if (authors.length > 0) {
                    emailText.append("\n    ").append(
                            I18nUtil.getMessage("org.dspace.eperson.Subscribe.authors", supportedLocale))
                            .append(" ").append(authors[0].value);

                    for (int k = 1; k < authors.length; k++) {
                        emailText.append("\n             ").append(authors[k].value);
                    }
                }

                emailText.append("\n         ")
                        .append(I18nUtil.getMessage("org.dspace.eperson.Subscribe.id", supportedLocale))
                        .append(" ").append(HandleManager.getCanonicalForm(item.getHandle())).append("\n\n");
                context.removeCached(item, item.getID());
            }
        }
    }

    // Send an e-mail if there were any new items
    if (emailText.length() > 0) {

        if (test) {
            log.info(LogManager.getHeader(context, "subscription:", "eperson=" + eperson.getEmail()));
            log.info(LogManager.getHeader(context, "subscription:", "text=" + emailText.toString()));

        } else {

            Email email = Email.getEmail(I18nUtil.getEmailFilename(supportedLocale, "subscription"));
            email.addRecipient(eperson.getEmail());
            email.addArgument(emailText.toString());
            email.send();

            log.info(LogManager.getHeader(context, "sent_subscription", "eperson_id=" + eperson.getID()));

        }
    }
}

From source file:org.dspace.app.cris.batch.ScriptIndexNetwork.java

private static boolean checkAvailableData(String connection, VisualizationGraphSolrService service)
        throws SearchServiceException {

    String query = "type:" + connection;

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(query);/*from ww  w .j av a 2  s .  c  o m*/
    solrQuery.setStart(0);
    solrQuery.setRows(0);
    QueryResponse rsp = service.search(solrQuery);
    SolrDocumentList docs = rsp.getResults();
    if (docs != null) {
        if (docs.getNumFound() > 0) {
            return true;
        }
    }
    return false;
}

From source file:org.dspace.app.cris.network.AVisualizationGraph.java

@Override
public JsGraph search(String authority, String name, Integer level, boolean showExternal, boolean showSameDept,
        String dept, Integer modeEntity) throws Exception {

    SolrQuery solrQuery = new SolrQuery();

    String query = buildQuery(authority, name, showSameDept, dept, modeEntity, level);
    String[] fqs = { "type:" + getConnectionName(), "entity:" + modeEntity };
    solrQuery.setQuery(query);//from   w w w  . ja  va2 s.  c  o m
    solrQuery.addFilterQuery(fqs);
    if (!showExternal && authority != null && !authority.isEmpty()) {
        solrQuery.addFilterQuery(new String[] { "a_auth:rp*", "b_auth:rp*" });
    }
    solrQuery.setFacet(true);
    solrQuery.addFacetField(FACET_SEARCH);
    if (modeEntity == ConstantNetwork.ENTITY_RP) {
        solrQuery.setFacetLimit(getLimitLevel(level));
    } else if (modeEntity == ConstantNetwork.ENTITY_DEPT) {
        solrQuery.setFacetLimit(Integer.MAX_VALUE);
    }
    solrQuery.setFacetMinCount(1);
    solrQuery.setRows(0);

    QueryResponse rsp = service.search(solrQuery);

    FacetField facets = rsp.getFacetField(FACET_SEARCH);

    JsGraph rsGraph = null;
    String src = null;
    if (authority != null && !authority.isEmpty()) {
        src = authority;
        rsGraph = new JsGraph();
        rsGraph.setId(authority);
        rsGraph.setName(name);
        JsGraphNodeData dataNode = new JsGraphNodeData();
        dataNode.setColor(getNodeCustomColor());
        dataNode.setType(getType());
        dataNode.setModeStyle("fill");
        rsGraph.setData(dataNode);

    } else {
        src = name;
        rsGraph = new JsGraph();
        rsGraph.setId(name);
        rsGraph.setName(name);
        JsGraphNodeData dataNodeLeaf = new JsGraphNodeData();
        dataNodeLeaf.setColor(getNodeLeafCustomColor());
        dataNodeLeaf.setType(getType());
        dataNodeLeaf.setModeStyle("stroke");
        rsGraph.setData(dataNodeLeaf);

    }
    if (rsGraph != null) {
        if (facets != null && facets.getValueCount() > 0) {
            for (Count facet : facets.getValues()) {
                if (facet.getCount() > 0) {

                    String node2 = (String) facet.getName();
                    String split[] = node2.split("\\|\\|\\|");

                    String srcnode2 = null;
                    String displayValue = "";
                    String authorityValue = null;
                    boolean isAuthority = false;

                    if (split.length > 1) {
                        String[] splitAuthority = split[1].split(splitterAuthority);

                        displayValue = splitAuthority[0];
                        srcnode2 = displayValue;
                        if (splitAuthority.length > 1) {
                            isAuthority = true;
                            authorityValue = splitAuthority[1];
                            srcnode2 = authorityValue;
                        }

                    } else if (split.length == 1) {
                        displayValue = split[0];
                        srcnode2 = displayValue;
                    }

                    if (!(src.equals(srcnode2))) {
                        JsGraphAdjacence adjacence = new JsGraphAdjacence();
                        JsGraphData data = new JsGraphData();

                        adjacence.setSrc(node2);

                        if (isAuthority) {
                            adjacence.setNodeTo(authorityValue);
                        } else {
                            adjacence.setNodeTo(displayValue);
                        }

                        if (authorityValue != null || showExternal) {
                            data.setColor(getEdgeCustomColor());
                            data.setLineWidth(getCustomLineWidth((int) facet.getCount()));
                            data.setCount((int) facet.getCount());
                            data.setType(getType());
                            adjacence.setData(data);

                            rsGraph.getAdjacencies().add(adjacence);

                        }
                    }
                }
            }
        }

    }
    return rsGraph;
}

From source file:org.dspace.app.cris.network.AVisualizationGraph.java

public List<ResearcherPage> loadMetrics(List<String[]> discardedNode, Integer importedNodes, Boolean otherError)
        throws SearchServiceException {
    // load all publications
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("type:" + getType() + " AND entity:" + ConstantNetwork.ENTITY_RP);
    solrQuery.addFacetField(FACET_METRICS);
    solrQuery.setFacetLimit(Integer.MAX_VALUE);
    solrQuery.setFacetMinCount(1);/*from  w ww  . j a  v a  2  s  . com*/
    solrQuery.setRows(0);
    QueryResponse rsp = getService().search(solrQuery);
    FacetField facets = rsp.getFacetField(FACET_METRICS);

    // for each interests get authority's authors
    List<ResearcherPage> result = new LinkedList<ResearcherPage>();
    int counter = 0;
    external: for (Count facetElement : facets.getValues()) {
        counter++;
        log.debug("" + counter + " of " + facets.getValueCount());
        ResearcherPage researcher = null;
        try {
            String facetValue = facetElement.getName();

            Integer realPersistentIdentifier = ResearcherPageUtils.getRealPersistentIdentifier(facetValue,
                    ResearcherPage.class);
            researcher = applicationService.get(ResearcherPage.class, realPersistentIdentifier);
            //researcher.getDynamicField().setAnagraficaLazy(applicationService.getAnagraficaByRP(realPersistentIdentifier));

            solrQuery = new SolrQuery();
            solrQuery.setQuery("type:" + getType() + " AND entity:" + ConstantNetwork.ENTITY_RP + " AND "
                    + FACET_METRICS + ":\"" + facetValue + "\"");
            solrQuery.addFacetField(FACET_SEARCH);
            solrQuery.setFacetMinCount(1);
            solrQuery.setFacetLimit(Integer.MAX_VALUE);
            solrQuery.setRows(0);

            rsp = getService().search(solrQuery);
            FacetField relations = rsp.getFacetField(FACET_SEARCH);
            int i = 0;
            int nConnections = 0;
            int maxStrength = 0;
            int sumStrength = 0;
            List<Long> quadraticVarianceArrays = new ArrayList<Long>();
            nConnections = Integer.valueOf(relations.getValueCount() - 1);
            internal: for (Count relation : relations.getValues()) {

                log.debug("" + counter + " works on " + i + " of " + relations.getValueCount());

                if (i == 0) {
                    i++;
                    continue internal;
                } else {
                    if (i == 1) {
                        // max
                        maxStrength = Integer.valueOf((int) relation.getCount());
                    }

                    sumStrength += Integer.valueOf((int) relation.getCount());

                    quadraticVarianceArrays.add(relation.getCount());
                }

                i++;

            }

            RPAdditionalFieldStorage anagraficaObject = researcher.getDynamicField();

            setMetadata(String.valueOf(nConnections), anagraficaObject,
                    ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_1 + getType());

            setMetadata(String.valueOf(maxStrength), anagraficaObject,
                    ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_2 + getType());

            double averageStrength = ((double) sumStrength / ((double) nConnections));
            setMetadata(String.valueOf(df.format(averageStrength)), anagraficaObject,
                    ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_3 + getType());

            double quadraticVariance = 0;
            double n = quadraticVarianceArrays.size();
            for (Long variance : quadraticVarianceArrays) {
                quadraticVariance += ((variance - averageStrength) * (variance - averageStrength));
            }
            quadraticVariance = Math.sqrt(quadraticVariance / n);
            setMetadata(String.valueOf(df.format(quadraticVariance)), anagraficaObject,
                    ConstantNetwork.PREFIX_METADATA_BIBLIOMETRIC_4 + getType());

            result.add(researcher);
        } catch (Exception e) {
            log.error("Error try to build object to index with ID:" + researcher.getId());
            log.error(e.getMessage(), e);
            otherError = true;
            continue;
        }

    }

    committnode: for (ResearcherPage node : result) {
        //            try
        //            {
        applicationService.saveOrUpdate(ResearcherPage.class, node);
        boolean rr = ((CrisSearchService) getIndexer().getIndexer()).indexCrisObject(node, true); // index node
        if (rr) {
            importedNodes++;
        } else {
            discardedNode.add(new String[] { getConnectionName() + " - " + node.getId() });
        }
        //            }
        //            catch (SolrServerException e)
        //            {
        //                log.error(e.getMessage(), e);
        //                discardedNode.add(new String[] { getConnectionName() + " - " + node.getId()});
        //                continue committnode;
        //            }
        //            catch (IOException e)
        //            {
        //                log.error(e.getMessage(), e);
        //                discardedNode.add(new String[] { getConnectionName() + " - " + node.getId()});
        //                continue committnode;
        //            }
    }

    log.debug("commit " + getType());
    getIndexer().getIndexer().commit();
    return result;

}

From source file:org.dspace.app.cris.network.AVisualizationGraph.java

protected String getDepartmentFromSOLR(String a_authority) throws SearchServiceException {
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("search.resourceid:"
            + ResearcherPageUtils.getRealPersistentIdentifier(a_authority, ResearcherPage.class)
            + " AND search.resourcetype:" + CrisConstants.RP_TYPE_ID);
    solrQuery.setFields("rp_dept");
    solrQuery.setRows(1);
    QueryResponse rsp = getService().getSearcher().search(solrQuery);
    SolrDocumentList publications = rsp.getResults();

    Iterator<SolrDocument> iter = publications.iterator();

    String rp_dept = "";
    while (iter.hasNext()) {
        SolrDocument publication = iter.next();

        rp_dept = (String) publication.getFirstValue("rp_dept");
        break;/*from w w w  .  j  av  a2  s  .c  o m*/
    }

    return rp_dept;
}

From source file:org.dspace.app.cris.network.AVisualizationGraph.java

protected String getStatusFromSOLR(String a_authority) throws SearchServiceException {
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("search.resourceid:"
            + ResearcherPageUtils.getRealPersistentIdentifier(a_authority, ResearcherPage.class)
            + " AND search.resourcetype:" + CrisConstants.RP_TYPE_ID);
    solrQuery.setFields("rp_boolean_status");
    solrQuery.setRows(1);
    QueryResponse rsp = getService().getSearcher().search(solrQuery);
    SolrDocumentList publications = rsp.getResults();

    Iterator<SolrDocument> iter = publications.iterator();

    String rp_status = "";
    while (iter.hasNext()) {
        SolrDocument publication = iter.next();

        rp_status = (String) publication.getFirstValue("rp_boolean_status");
        break;/*from  www.j a v a2s  . com*/
    }

    return rp_status;
}

From source file:org.dspace.app.cris.network.AVisualizationGraphModeFour.java

@Override
public List<VisualizationGraphNode> load(List<String[]> discardedNode, Integer importedNodes,
        Boolean otherError) throws Exception {
    // load all publications
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(getQuery());// ww  w.  j a  v a 2  s  .c  o m
    solrQuery.addFacetField(getFacetFieldQuery());
    // solrQuery.addFilterQuery("authors_fauthority:rp00001");
    solrQuery.setFacetLimit(Integer.MAX_VALUE);
    solrQuery.setFacetMinCount(1);
    solrQuery.setRows(0);
    QueryResponse rsp = getService().getSearcher().search(solrQuery);
    FacetField facets = rsp.getFacetField(getFacetFieldQuery());
    System.out.println(facets.getValueCount());
    // for each interests get authority's authors
    List<VisualizationGraphNode> result = null;
    int counter = 0;
    external: for (Count facetElement : facets.getValues()) {
        counter++;

        log.debug(getConnectionName() + " - " + counter + " of " + facets.getValueCount());
        System.out.println(getConnectionName() + " - " + counter + " of " + facets.getValueCount());
        result = new LinkedList<VisualizationGraphNode>();
        try {
            String facetValue = facetElement.getName();
            List<String> relations = getValues(facetValue);

            int i = 0;
            internal: for (String relation : relations) {

                log.debug("" + counter + " works on " + i + " of " + relations.size());
                System.out.println(getConnectionName() + " - " + counter + " of " + facets.getValueCount()
                        + " works on " + i + " of " + relations.size());
                String aaa = relation;
                String[] split = aaa.split("\\|\\|\\|");

                String a = aaa;
                String a_authority = null;
                String a_dept = null;
                String a_displayValue = "";

                if (split.length > 1) {

                    String[] splitAuthority = split[1].split(splitterAuthority);

                    a_displayValue = splitAuthority[0];
                    if (splitAuthority.length > 1) {
                        a_authority = splitAuthority[1];
                        // a_dept = ResearcherPageUtils
                        // .getDepartment(a_authority);
                        a_dept = getDepartmentFromSOLR(a_authority);
                    }

                }

                internalprivate: for (int j = i; j < relations.size(); j++) {
                    List<String> values = new LinkedList<String>();
                    values.add(facetValue);

                    String bbb = relations.get(j);
                    split = bbb.split("\\|\\|\\|");

                    String b = bbb;
                    String b_authority = null;
                    String b_dept = null;
                    String b_displayValue = "";

                    if (split.length > 1) {
                        String[] splitAuthority = split[1].split(splitterAuthority);

                        b_displayValue = splitAuthority[0];
                        if (splitAuthority.length > 1) {
                            b_authority = splitAuthority[1];
                            // a_dept = ResearcherPageUtils
                            // .getDepartment(a_authority);
                            b_dept = getDepartmentFromSOLR(b_authority);
                        }
                    }

                    if (j == i) {
                        buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue, values,
                                buildExtra(facetValue), a_dept, b_dept, ConstantNetwork.ENTITY_PLACEHOLDER_RP);
                    } else {
                        if (!a.equals(b)) {
                            buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue,
                                    values, buildExtra(facetValue), a_dept, b_dept, ConstantNetwork.ENTITY_RP);
                        }
                    }
                }

                i++;

            }

        } catch (Exception e) {
            log.error("Error try to build object to index with ID:" + "");
            log.error(e.getMessage(), e);
            otherError = true;
            continue;
        }
        importedNodes = indexNode(discardedNode, importedNodes, result);
    }

    log.debug("commit " + getType());
    getIndexer().commit();
    return result;
}

From source file:org.dspace.app.cris.network.AVisualizationGraphModeOne.java

@Override
public List<VisualizationGraphNode> load(List<String[]> discardedNode, Integer importedNodes,
        Boolean otherError) throws Exception {
    // load all publications
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("*:*");

    solrQuery.setFields("search.resourceid", "search.resourcetype", "author_filter", "dc.title", "handle");
    solrQuery.addFilterQuery("search.resourcetype:[2 TO 4]");

    int start = 0;
    int offset = 100;
    if (NOT_PAGINATION) {
        solrQuery.setRows(Integer.MAX_VALUE);
    } else {/*from  w  w w. j a  v a 2  s .co  m*/
        solrQuery.setStart(start);
        solrQuery.setRows(offset);
    }
    QueryResponse rsp = getService().getSearcher().search(solrQuery);
    SolrDocumentList publications = rsp.getResults();
    System.out.println(publications.getNumFound());
    List<VisualizationGraphNode> result = null;
    boolean endwhile = false;
    while (((publications.getNumFound() + offset) > start) && endwhile == false) {
        if (start > 0 && !NOT_PAGINATION) {
            solrQuery.setStart(start);
            solrQuery.setRows(offset);
            rsp = getService().getSearcher().search(solrQuery);
            publications = rsp.getResults();
        }

        start = (start + 1) + offset;
        // for each publication get authority's authors facets
        Iterator<SolrDocument> iter = publications.iterator();
        int counter = 0;
        external: while (iter.hasNext()) {

            counter++;
            log.debug("" + (start == 0 ? counter : (start + counter)) + " of " + publications.getNumFound());
            System.out.println(getConnectionName() + " - " + counter);

            result = new ArrayList<VisualizationGraphNode>();

            Integer pubId = null;
            try {
                SolrDocument publication = iter.next();

                pubId = (Integer) publication.getFieldValue("search.resourceid");
                Object obj = publication.getFieldValue("dc.title");
                String handle = (String) publication.getFieldValue("handle");
                Object auth = publication.getFieldValue("author_filter");

                List<String> values = new ArrayList<String>();
                if (obj instanceof ArrayList) {
                    for (String aaa : (List<String>) obj) {
                        values.add(aaa);
                    }
                } else {
                    String value = (String) obj;
                    values.add(value);
                }

                if (auth instanceof ArrayList) {
                    int i = 0;
                    List<String> authArrays = (List<String>) auth;
                    for (String aaa : authArrays) {

                        String[] split = aaa.split("\\|\\|\\|");

                        String a = aaa;
                        String a_authority = null;
                        String a_dept = null;
                        String a_displayValue = "";

                        if (split.length > 1) {

                            String[] splitAuthority = split[1].split(splitterAuthority);

                            a_displayValue = splitAuthority[0];
                            if (splitAuthority.length > 1) {
                                a_authority = splitAuthority[1];
                                // a_dept = ResearcherPageUtils
                                // .getDepartment(a_authority);
                                a_dept = getDepartmentFromSOLR(a_authority);
                            }

                        }

                        for (int j = i; j < authArrays.size(); j++) {
                            String bbb = authArrays.get(j);
                            String extra = handle;

                            split = bbb.split("\\|\\|\\|");

                            String b = bbb;
                            String b_authority = null;
                            String b_dept = null;
                            String b_displayValue = "";

                            if (split.length > 1) {

                                String[] splitAuthority = split[1].split(splitterAuthority);

                                b_displayValue = splitAuthority[0];
                                if (splitAuthority.length > 1) {
                                    b_authority = splitAuthority[1];
                                    // a_dept = ResearcherPageUtils
                                    // .getDepartment(a_authority);
                                    b_dept = getDepartmentFromSOLR(b_authority);
                                }

                            }

                            if (j == i) {
                                buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue,
                                        values, extra, a_dept, b_dept, ConstantNetwork.ENTITY_PLACEHOLDER_RP);
                            } else {
                                buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue,
                                        values, extra, a_dept, b_dept, ConstantNetwork.ENTITY_RP);
                            }
                        }
                        i++;
                    }
                } else {
                    continue external;
                }

            } catch (Exception e) {
                log.error("Error try to build object to index with publication ID:" + pubId);
                log.error(e.getMessage(), e);
                otherError = true;
                continue;
            }

            importedNodes = indexNode(discardedNode, importedNodes, result);

        }
        if (NOT_PAGINATION) {
            endwhile = true;
        }

        log.debug("commit " + getType());
        getIndexer().commit();
    }
    return result;
}

From source file:org.dspace.app.cris.network.AVisualizationGraphModeThree.java

@Override
public List<VisualizationGraphNode> load(List<String[]> discardedNode, Integer importedNodes,
        Boolean otherError) throws Exception {
    // load all publications
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(getQuery());/*  www  .ja v a  2  s. c  o  m*/

    solrQuery.setFields(getFields());
    solrQuery.addFilterQuery("search.resourcetype:" + getResourceType());

    int start = 0;
    int offset = 100;
    if (NOT_PAGINATION) {
        solrQuery.setRows(Integer.MAX_VALUE);
    } else {
        solrQuery.setStart(start);
        solrQuery.setRows(offset);
    }
    QueryResponse rsp = getService().getSearcher().search(solrQuery);
    SolrDocumentList publications = rsp.getResults();
    System.out.println(publications.getNumFound());
    List<VisualizationGraphNode> result = null;
    boolean endwhile = false;
    while (((publications.getNumFound() + offset) > start) && endwhile == false) {
        if (start > 0 && !NOT_PAGINATION) {
            solrQuery.setStart(start);
            solrQuery.setRows(offset);
            rsp = getService().getSearcher().search(solrQuery);
            publications = rsp.getResults();
        }

        start = (start + 1) + offset;
        // for each publication get authority's authors facets
        Iterator<SolrDocument> iter = publications.iterator();
        int counter = 0;
        external: while (iter.hasNext()) {

            counter++;
            log.debug("" + (start == 0 ? counter : (start + counter)) + " of " + publications.getNumFound());
            System.out.println(getConnectionName() + " - " + counter);

            result = new ArrayList<VisualizationGraphNode>();

            Integer pubId = null;
            try {
                SolrDocument publication = iter.next();

                pubId = (Integer) publication.getFieldValue("search.resourceid");

                Object obj = publication.getFieldValue(getNameFieldValueInFields());
                String handle = (String) publication.getFirstValue(getNameFieldExtraInFields());

                Object auth = publication.getFieldValue(getNameFieldNodeBuilderInFields());

                List<String> values = new ArrayList<String>();
                if (obj instanceof ArrayList) {
                    for (String aaa : (List<String>) obj) {
                        values.add(aaa);
                    }
                } else {
                    String value = (String) obj;
                    values.add(value);
                }

                if (auth instanceof ArrayList) {
                    int i = 0;
                    List<String> authArrays = (List<String>) auth;
                    for (String aaa : authArrays) {

                        String[] split = aaa.split("\\|\\|\\|");

                        String a = aaa;
                        String a_authority = null;
                        String a_dept = null;
                        String a_displayValue = "";

                        if (split.length > 1) {

                            String[] splitAuthority = split[1].split(splitterAuthority);

                            a_displayValue = splitAuthority[0];
                            if (split.length > 1) {
                                a_authority = splitAuthority[1];
                                // a_dept = ResearcherPageUtils
                                // .getDepartment(a_authority);
                                a_dept = getDepartmentFromSOLR(a_authority);
                            }

                        }
                        for (int j = i; j < authArrays.size(); j++) {
                            String bbb = authArrays.get(j);
                            String extra = handle;

                            split = bbb.split("\\|\\|\\|");

                            String b = bbb;
                            String b_authority = null;
                            String b_dept = null;
                            String b_displayValue = "";

                            if (split.length > 1) {

                                String[] splitAuthority = split[1].split(splitterAuthority);

                                b_displayValue = splitAuthority[0];
                                if (split.length > 1) {
                                    b_authority = splitAuthority[1];
                                    // a_dept = ResearcherPageUtils
                                    // .getDepartment(a_authority);
                                    b_dept = getDepartmentFromSOLR(a_authority);
                                }

                            }

                            if (j == i) {
                                buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue,
                                        values, extra, a_dept, b_dept, ConstantNetwork.ENTITY_PLACEHOLDER_RP);
                            } else {
                                buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue,
                                        values, extra, a_dept, b_dept, ConstantNetwork.ENTITY_RP);
                            }
                        }
                        i++;
                    }
                } else {
                    continue external;
                }

            } catch (Exception e) {
                log.error("Error try to build object to index with publication ID:" + pubId);
                log.error(e.getMessage(), e);
                otherError = true;
                continue;
            }

            importedNodes = indexNode(discardedNode, importedNodes, result);

        }
        if (NOT_PAGINATION) {
            endwhile = true;
        }

        log.debug("commit " + getType());
        getIndexer().commit();
    }
    return result;
}

From source file:org.dspace.app.cris.network.AVisualizationGraphModeTwo.java

@Override
public List<VisualizationGraphNode> load(List<String[]> discardedNode, Integer importedNodes,
        Boolean otherError) throws Exception {
    // load all publications
    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(getQuery());//from   ww  w. j av  a  2s .  co m
    solrQuery.addFacetField(getFacetFieldQuery());
    // solrQuery.addFilterQuery("authors_fauthority:rp00001");
    solrQuery.setFacetLimit(Integer.MAX_VALUE);
    solrQuery.setFacetMinCount(1);
    solrQuery.setRows(0);
    QueryResponse rsp = getService().getSearcher().search(solrQuery);
    FacetField facets = rsp.getFacetField(getFacetFieldQuery());
    System.out.println(facets.getValueCount());
    // for each interests get authority's authors
    List<VisualizationGraphNode> result = null;
    int counter = 0;
    external: for (Count facetElement : facets.getValues()) {
        counter++;

        log.debug(getConnectionName() + " - " + counter + " of " + facets.getValueCount());
        System.out.println(getConnectionName() + " - " + counter + " of " + facets.getValueCount());
        result = new LinkedList<VisualizationGraphNode>();
        try {

            String facetValue = facetElement.getName();

            solrQuery = new SolrQuery();
            String query = (useJoin() ? getJoin() : "") + getFacetFieldQuery() + ":\""
                    + ClientUtils.escapeQueryChars(facetValue) + "\"";
            solrQuery.setQuery(query);
            solrQuery.addFacetField(getFacet(facetValue));
            solrQuery.setFacetMinCount(1);
            solrQuery.setFacetLimit(getFacetLimit());
            solrQuery.setRows(0);

            rsp = getService().getSearcher().search(solrQuery);
            FacetField relations = rsp.getFacetField(getFacet(facetValue));
            int i = 0;
            internal: for (Count relation : relations.getValues()) {

                log.debug("" + counter + " works on " + i + " of " + relations.getValueCount());
                System.out.println(getConnectionName() + " - " + counter + " of " + facets.getValueCount()
                        + " works on " + i + " of " + relations.getValueCount());
                String aaa = relation.getName();
                String[] split = aaa.split("\\|\\|\\|");

                String a = aaa;
                String a_authority = null;
                String a_dept = null;
                String a_displayValue = "";

                if (split.length > 1) {

                    String[] splitAuthority = split[1].split(splitterAuthority);

                    a_displayValue = splitAuthority[0];
                    if (splitAuthority.length > 1) {
                        a_authority = splitAuthority[1];
                        // a_dept = ResearcherPageUtils
                        // .getDepartment(a_authority);
                        a_dept = getDepartmentFromSOLR(a_authority);
                    }

                }

                internalprivate: for (int j = i; j < relations.getValues().size(); j++) {
                    List<String> values = new LinkedList<String>();
                    values.add(facetValue);

                    String bbb = relations.getValues().get(j).getName();
                    split = bbb.split("\\|\\|\\|");

                    String b = bbb;
                    String b_authority = null;
                    String b_dept = null;
                    String b_displayValue = "";

                    if (split.length > 1) {
                        String[] splitAuthority = split[1].split(splitterAuthority);

                        b_displayValue = splitAuthority[0];
                        if (splitAuthority.length > 1) {
                            b_authority = splitAuthority[1];
                            // a_dept = ResearcherPageUtils
                            // .getDepartment(a_authority);
                            b_dept = getDepartmentFromSOLR(b_authority);
                        }
                    }

                    if (j == i) {
                        buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue, values,
                                buildExtra(facetValue), a_dept, b_dept, ConstantNetwork.ENTITY_PLACEHOLDER_RP);
                    } else {
                        if (!a.equals(b)) {
                            buildRow(result, a, a_authority, a_displayValue, b, b_authority, b_displayValue,
                                    values, buildExtra(facetValue), a_dept, b_dept, ConstantNetwork.ENTITY_RP);
                        }
                    }
                }

                i++;

            }

        } catch (Exception e) {
            log.error("Error try to build object to index with ID:" + "");
            log.error(e.getMessage(), e);
            otherError = true;
            continue;
        }
        importedNodes = indexNode(discardedNode, importedNodes, result);
    }

    log.debug("commit " + getType());
    getIndexer().commit();
    return result;
}