Solr/lucene分散検索、Solr Integrate katta step 4


上のいくつかのステップができました.テスト、テストコードを追加できます.
package net.dkatta;

import java.util.Iterator;
import java.util.Map;

import net.sf.katta.client.ClientResult;
import net.sf.katta.util.KattaException;
import net.sf.katta.util.ZkConfiguration;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.katta.KattaClient;
import org.apache.solr.katta.KattaRequest;
import org.apache.solr.katta.KattaResponse;

/**
 * <pre>
 * Created by IntelliJ IDEA.
 * User: zhenqin
 * Date: 12-10-12
 * Time:  11:45
 * To change this template use File | Settings | File Templates.
 *
 * </pre>
 *
 * @author zhenqin
 */
public class ClientMain {
    
    
    
    public static void main(String[] args) throws KattaException {
        KattaClient kattaClient = new KattaClient(new ZkConfiguration());
//        Client client = new Client(SolrKattaServer.class);

        SolrQuery query = new SolrQuery();
        String word = "facet";

        query.setQuery("content:facet");

        query.setParam("fl", "title, content, score");

//        query.addFilterQuery("content:(" + word + ")");

        query.setRows(10);// , , 0
        query.setSortField("score", SolrQuery.ORDER.desc);// 
        query.add(CommonParams.QT, "standard");


        System.out.println(query.toString());
        QueryResponse queryResponse = null;
        SolrResponse solrResponse = null;

        KattaRequest request = new KattaRequest(query);

        try {
            ClientResult<KattaResponse> res = kattaClient.request(10 * 1000L, new String[]{"*"}, request);
            System.out.println(res);
            java.util.Collection<KattaResponse> ls = res.getResults();

            KattaResponse kr = ls.iterator().next();
            SolrResponse response = kr.getRsp();

            if(response instanceof QueryResponse) {
                queryResponse = (QueryResponse)response;
                System.out.println("========================true");
            } else {
                System.out.println("========================false" + response.getClass().getName());
                queryResponse = new QueryResponse();
                queryResponse.setResponse(response.getResponse());
            }

            
            System.out.println(" : " + queryResponse.getResults().size());
            SolrDocumentList docs = queryResponse.getResults();
            for (SolrDocument doc : docs) {
                for (Iterator<Map.Entry<String, Object>> iter = doc.iterator(); iter.hasNext();) {
                    Map.Entry<String, Object> entry = iter.next();
                    System.out.print("Key: " + entry.getKey() + "  ");
                    System.out.println("Value: " + entry.getValue());
                }
                System.out.println("----------------------------------------------");
            }
        } catch(Exception e) {
            e.printStackTrace();
        }

    }
}
実行後ClientMain出力:
10-18 14:44:21 [INFO  ][ zookeeper.ZooKeeper ]  (379  ) Initiating client connection, connectString=localhost:2181 sessionTimeout=5000 watcher=org.I0Itec.zkclient.ZkClient@5d40f8c3
10-18 14:44:21 [INFO  ][ zookeeper.ClientCnxn ]  (1058  ) Opening socket connection to server localhost/127.0.0.1:2181
10-18 14:44:21 [INFO  ][ zookeeper.ClientCnxn ]  (947  ) Socket connection established to localhost/127.0.0.1:2181, initiating session
10-18 14:44:21 [INFO  ][ zookeeper.ClientCnxn ]  (736  ) Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x13a7236897c0009, negotiated timeout = 10000
10-18 14:44:21 [INFO  ][ zkclient.ZkClient ]  (449  ) zookeeper state changed (SyncConnected)
10-18 14:44:21 [INFO  ][ client.Client ]  (143  ) indices=[solrhome1]
q=content%3Afacet&fl=title%2C+content%2C+score&rows=10&sort=score+desc&qt=standard
ClientResult: 1 results, 0 errors, 1/1 shards (closed) (complete)
========================falseorg.apache.solr.client.solrj.response.SolrResponseBase
 : 2
Key: sid  Value: 7039ce44-20bc-41d4-8278-2377654b3f35
Key: title  Value: facet.field
Key: content  Value: This param allows you to specify a field which should be treated as a facet
Key: score  Value: 0.9991327
----------------------------------------------
Key: sid  Value: 832c11d4-e1c1-453d-8a56-a9726d8e3b44
Key: title  Value: facet.field
Key: content  Value: This param allows you to specify a field which should be treated as a facet
Key: score  Value: 0.9991327
----------------------------------------------
同時に、step 3で起動したNodeとShardは同時に2回検索した.ログ:
10-18 14:44:22 [INFO  ][ core.SolrCore ]  (1386  ) [solrhome1#proxy] webapp=null path=/select params={rows=10&sort=score+desc&fl=sid%2Cscore&q=content%3Afacet&start=0&fsv=true&isShard=true} hits=2 status=0 QTime=20 
10-18 14:44:22 [INFO  ][ core.SolrCore ]  (1386  ) [solrhome1#proxy] webapp=null path=/select params={rows=10&fl=title%2C+content%2C+score%2Csid&q=content%3Afacet&ids=7039ce44-20bc-41d4-8278-2377654b3f35%2C832c11d4-e1c1-453d-8a56-a9726d8e3b44&isShard=true} status=0 QTime=4 
もちろんstep 3に2つのshardを加えると、2つのshardのインデックスが検索される.さらに多くのノードを同時に追加すると、*を使用してすべてのノードを検索し、solrhome 1は1つのノードのみを検索する.