apache solr最多可显示11789条结果

时间:2014-09-16 20:17:55

标签: apache solr

我正在插入总数为8000000的文档,但在插入时我可以看到solr仅接收11789个文档并开始覆盖其他文档。所以在整个插入过程之后我只能在solr中看到11789文档。

我是solr的新手。 请帮助。 谢谢

以下是我的代码。自动提交的设置是默认设置。 很抱歉迟到了。

 import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;

import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.mule.api.MuleEventContext;
import org.mule.api.MuleMessage;
import org.mule.api.lifecycle.Callable;

public class smartGalleries implements Callable {

    @Override
public Object onCall(MuleEventContext ctx) throws Exception {
    MuleMessage msg = ctx.getMessage();

    HttpSolrServer server = new HttpSolrServer("http://localhost:8984/solr");


    ArrayList<SolrInputDocument> docList = new ArrayList<SolrInputDocument>();
    JSONParser parse = new JSONParser();
    for (int a = 0; a < 12; a++) {

        File opFile = new File("/input/output" + a + ".txt");
        FileReader fr = new FileReader(opFile.getAbsoluteFile());
        BufferedReader br = new BufferedReader(fr);

        JSONArray jsa = (JSONArray) parse.parse(br);


        for (int i = 0; i < jsa.size(); i++) {

            // INSERTING THE WHOLE STRUCTURE IN MONGODB

            JSONObject object = (JSONObject) jsa.get(i);
            SolrInputDocument doc = new SolrInputDocument();

            // CONVERSION TO GALLERY OBJECT




            JSONObject metadata = (JSONObject) object.get("metadata");

            ArrayList<Asset> assetList = new ArrayList<Asset>();

            JSONArray gis = (JSONArray) object.get("gallery_item_set");

            for (int k = 0; k < gis.size(); k++) {

                JSONObject gisobj = (JSONObject) gis.get(k);
                Asset asset = new Asset();

                SolrInputDocument assetDoc = new SolrInputDocument();

                if (gisobj.containsKey("content")) {
                    JSONObject content = (JSONObject) gisobj.get("content");

                    asset.setHeight(Integer.parseInt(content.get("height")
                            .toString()));
                    asset.setWidth(Integer.parseInt(content.get("width")
                            .toString()));
                    asset.setOrientation(content.get("orientation")
                            .toString());
                    asset.setId((content.get("guid").toString()));
                    assetDoc.addField("height", asset.getHeight());
                    assetDoc.addField("width", asset.getWidth());
                    assetDoc.addField("orientation",
                            asset.getOrientation());
                    assetDoc.addField("id", asset.getId());

                    Date createdImage = new SimpleDateFormat(
                            "yyyy-MM-dd HH:mm:ss", Locale.ENGLISH)
                            .parse(content.get("created_at").toString());
                    Date modifiedImage = new SimpleDateFormat(
                            "yyyy-MM-dd HH:mm:ss", Locale.ENGLISH)
                            .parse(content.get("modified_at").toString());
                    Date publishedImage = new SimpleDateFormat(
                            "yyyy-MM-dd HH:mm:ss", Locale.ENGLISH)
                            .parse(content.get("published_at").toString());

                    asset.setCreatedDate(createdImage);
                    asset.setModifiedDate(modifiedImage);
                    asset.setPublishedDate(publishedImage);
                    assetDoc.addField("createdDate", asset
                            .getCreatedDate().toString());
                    assetDoc.addField("publishedDate", asset
                            .getPublishedDate().toString());
                    assetDoc.addField("modifiedDate", asset
                            .getModifiedDate().toString());
                    if (content.containsKey("attribution_text")) {

                        asset.setCredit(content.get("attribution_text")
                                .toString());
                        assetDoc.addField("credit", asset.getCredit());

                    }

                    if (content.containsKey("description")) {
                        asset.setDescription(content.get("description")
                                .toString());
                        assetDoc.addField("description",
                                asset.getDescription());
                    }

                    if (content.containsKey("metadata")) {
                        JSONObject contentmeta = (JSONObject) content
                                .get("metadata");
                        if (contentmeta.containsKey("keyword")) {
                            JSONObject contentmetakey = (JSONObject) contentmeta
                                    .get("keyword");
                            JSONArray unknownSet = (JSONArray) contentmetakey
                                    .get("unknown_set");
                            ArrayList<String> imgKeyword = new ArrayList<String>();
                            if (unknownSet.size() != 0) {

                                for (int l = 0; l < unknownSet.size(); l++) {
                                    JSONObject text = (JSONObject) unknownSet
                                            .get(l);
                                    if (text.get("text__t") != null) {
                                        imgKeyword.add(text.get("text__t")
                                                .toString());

                                    }
                                }
                            }

                            asset.setKeywords(imgKeyword);
                            assetDoc.addField("keywords",
                                    asset.getKeywords());
                        }
                    }
                }

                JSONObject gismeta = (JSONObject) gisobj.get("metadata");
                if (gismeta != null) {
                    if (gismeta.containsKey("caption")) {
                        if (gismeta.get("caption") != null)
                            asset.setCaption(gismeta.get("caption")
                                    .toString());
                        assetDoc.addField("caption",
                                asset.getCaption());

                    }
                }

                asset.setPosition(Integer.parseInt(gisobj.get("position")
                        .toString()));
                assetDoc.addField("position", asset.getPosition());

                docList.add(assetDoc);


                server.add(assetDoc);


                System.out.println(doc);

            }



            server.commit();





        }


        server.setConnectionTimeout(100);
    }


    return msg;
}
}

和错误::

Exception stack is:
1. No buffer space available (maximum connections reached?): connect (java.net.SocketException)
  java.net.DualStackPlainSocketImpl:-2 (null)
2. IOException occured when talking to server at: http://localhost:8983/solr (org.apache.solr.client.solrj.SolrServerException)
  org.apache.solr.client.solrj.impl.HttpSolrServer:566 (null)
3. Component that caused exception is: DefaultJavaComponent{filetestFlow1.component.1935247117}. Message payload is of type: String (org.mule.component.ComponentException)
  org.mule.component.DefaultComponentLifecycleAdapter:348 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.net.SocketException: No buffer space available (maximum connections reached?): connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

0 个答案:

没有答案