Solrj之Multicore查询

1,创建Multicore 

  1),复制D:\work\solr_home\test,命名为core。
  2),修改D:\work\solr_home\test\ core.properties
    name=test
    config=solrconfig.xml
    schema=schema.xml
    dataDir=data
  改成:
    name=core1
  3)、重启tomcat

2,添加索引

  向每个core添加索引:
  修改private static String url="http://localhost:8081/solr/test";
  每次添加不同core只需要修改test即可,也可以以参数将core传入。
  添加索引的方法跟上节将的方法一样,在此就不再累述了。

3,查询

  HttpSolrClient server = SolrServer.getServer();
  SolrQuery sQuery = new SolrQuery();
  sQuery.setQuery(str);
  sQuery.setStart(0);
  sQuery.setRows(5);
  sQuery.set("shards", "localhost:8081/solr/test,localhost:8081/solr/core1,localhost:8081/solr/core2");
  QueryResponse queryResponse;
  try {
    queryResponse = server.query(sQuery);
    List<TestBO> indexBOLists = queryResponse.getBeans(TestBO.class);
    for (TestBO bo : indexBOLists) {
      System.out.println(bo.getDes_s());
    }
  } catch (Exception e) {
    e.printStackTrace();
  }

管理界面安全配置

仅针对tomcat:

1、修改G:\solr5\apache-tomcat-8.0.28\conf\tomcat-users.xml

在tomcat-users标签内添加:

<role rolename="solr"/>

<user username="admin" password="admin" roles="solr"/>

2、修改G:\solr5\apache-tomcat-8.0.28\webapps\solr\WEB-INF\web.xml

<security-constraint>

<web-resource-collection>

<web-resource-name>RestrictaccesstoSolradmin</web-resource-name>

<url-pattern>/admin/*</url-pattern>

<http-method>DELETE</http-method>

<http-method>GET</http-method>

 

<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<description>This applies only to the "tomcat" security role</description>
<role-name>solr</role-name>
<role-name>admin</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>please input user and password.</realm-name>
</login-config>

 

posted @ 2020-10-07 10:37  漫步程序路  阅读(252)  评论(0)    收藏  举报