18

我正在开发一个网络应用程序。我使用 spring mvc 框架、cassandra 和 solr。我使用独立的 solr,而不是 solr 云。我使用 solr 作为全文检索工具。我面临一个奇怪的问题,首先是schema.xml.

<schema name="KSP_core" version="1.1">
  <types>
    <fieldType name="uuid" class="solr.UUIDField" indexed="true" />  
    <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
    <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
  <fieldType name="text_ik" class="solr.TextField"> 
    <analyzer type="index" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/> 
    <analyzer type="query" isMaxWordLength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"/> 
    </fieldType>
  </types>

 <fields>   
  <!-- general -->
  <field name="id"        type="uuid"    indexed="true"  stored="true"  multiValued="false" required="true"/>
  <field name="dbTable"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 
  <field name="userId"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 
  <field name="originatorId"      type="string"    indexed="true"  stored="true"  multiValued="false" />
  <field name="associatedObjectId"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 
  <field name="createTime"      type="date"      indexed="true"  stored="true"/>
  <field name="status"     type="int"    indexed="true"  stored="true"  multiValued="false" />
  <field name="postType"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 

  <!-- user activity -->
  <field name="userOperate" type="string" indexed="true" stored="true" multiValued="false"/>


  <!--user reputation-->
  <field name="reputation" type="int"      indexed="true"  stored="true"/>
  <field name="dayTime"      type="string"    indexed="true"  stored="true"/> 
  <field name="reason"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 

  <!--user tags-->
  <field name="tagId"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 
  <field name="tagName"      type="string"    indexed="true"  stored="true"  multiValued="false" /> 

  <field name="reputationOnTag" type="int"      indexed="true"  stored="true"/>
  <field name="_version_" type="long" indexed="true" stored="true"/>
 </fields>

  <uniqueKey>id</uniqueKey>
 <!-- field for the QueryParser to use when an explicit fieldname is absent -->
 <defaultSearchField>userId</defaultSearchField>

 <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
 <solrQueryParser defaultOperator="OR"/>
</schema>

然后我给你看 solrconfig.xml

 <?xml version="1.0" encoding="UTF-8" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<!--
 This is a stripped down config file used for a simple example...  
 It is *not* a good example to work from. 
-->
<config>
  <luceneMatchVersion>LUCENE_40</luceneMatchVersion>
  <!--  The DirectoryFactory to use for indexes.
        solr.StandardDirectoryFactory, the default, is filesystem based.
        solr.RAMDirectoryFactory is memory based, not persistent, and doesn't work with replication. -->
  <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}"/>

  <dataDir>${solr.core0.data.dir:}</dataDir>

  <updateHandler class="solr.DirectUpdateHandler2">
    <updateLog>
      <str name="dir">${solr.core0.data.dir:}</str>
    </updateLog>
  </updateHandler>

  <!-- realtime get handler, guaranteed to return the latest stored fields 
    of any document, without the need to commit or open a new searcher. The current 
    implementation relies on the updateLog feature being enabled. -->
  <requestHandler name="/get" class="solr.RealTimeGetHandler">
    <lst name="defaults">
      <str name="omitHeader">true</str>
    </lst>
  </requestHandler>  

  <requestHandler name="/replication" class="solr.ReplicationHandler" startup="lazy" /> 

  <requestDispatcher handleSelect="true" >
    <requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" />
  </requestDispatcher>

  <requestHandler name="standard" class="solr.StandardRequestHandler" default="true" />
  <requestHandler name="/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />
  <requestHandler name="/update" class="solr.UpdateRequestHandler"  />
  <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />

  <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
    <lst name="invariants">
      <str name="q">solrpingquery</str>
    </lst>
    <lst name="defaults">
      <str name="echoParams">all</str>
    </lst>
  </requestHandler>

  <!-- config for the admin interface --> 
  <admin>
    <defaultQuery>solr</defaultQuery>
  </admin>

</config>

当我从 solr 查询数据时,我一般使用 solrj 库来实现查询。喜欢:

   String queryExpression = "*:*";
   String sortField = "createTime";
   String baseUrl = SolrUtil.getSolrBaseURL(solrHttpServer.getBaseURL());
   solrHttpServer.setBaseURL(baseUrl + "/" + coreName);
   SolrQuery query = new SolrQuery();
   query.setQuery(queryExpression);
   query.setSortField(sortField, SolrQuery.ORDER.asc);
   QueryResponse rsp = solrHttpServer.query(query);

以下代码是查询时的错误信息:

org.apache.solr.common.SolrException: undefined field userId
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:401)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:181)
    at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:90)
    at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
    at com.augmentum.ksp.solr.dao.impl.SolrBaseDaoImpl.query(SolrBaseDaoImpl.java:141)
    at com.augmentum.ksp.service.impl.TagStatsServiceImpl.getUserTagStats(TagStatsServiceImpl.java:50)
    at com.augmentum.ksp.controller.TagStatsController.getUserTagStats(TagStatsController.java:162)
    at sun.reflect.GeneratedMethodAccessor188.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.util.AssertionThreadLocalFilter.doFilter(AssertionThreadLocalFilter.java:54)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.util.HttpServletRequestWrapperFilter.doFilter(HttpServletRequestWrapperFilter.java:75)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:201)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.augmentum.iaphelper.filter.AuthenticationFilter.doFilter(Unknown Source)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.augmentum.ksp.filter.I18nFilter.doFilter(I18nFilter.java:22)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)

从信息中,我只知道我的控制器、服务和 dao 工作正常。很奇怪,大部分时间都能正常工作,但是刷新JSP页面20次之内一定会报错,这让我很担心。我可以保证我的solr服务器正常启动。并且索引已加载。我不知道如何找到解决它的方法,因为我不知道问题的根源。

此外,还出现了许多类似的错误,这次不是名为 userId 的字段,而是名为 dbTable 的字段。

org.apache.solr.common.SolrException: undefined field dbTable
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:401)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:181)
    at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:90)
    at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
    at com.augmentum.ksp.solr.dao.impl.SolrBaseDaoImpl.query(SolrBaseDaoImpl.java:135)
    at com.augmentum.ksp.service.impl.UserServiceImpl.listUserReputationByTime(UserServiceImpl.java:1222)
    at com.augmentum.ksp.controller.UserControler.listUserReputationByTime(UserControler.java:374)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.util.AssertionThreadLocalFilter.doFilter(AssertionThreadLocalFilter.java:54)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.util.HttpServletRequestWrapperFilter.doFilter(HttpServletRequestWrapperFilter.java:75)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:201)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.augmentum.iaphelper.filter.AuthenticationFilter.doFilter(Unknown Source)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.augmentum.ksp.filter.I18nFilter.doFilter(I18nFilter.java:22)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)

有没有人遇到过同样的问题?

4

1 回答 1

5

如我所见,您在代码中更改了 baseUrl。正如您在评论中所说,您在同一页面上查询多个核心,并且它们都使用相同的HttpSolrServer. 因此,您的解决方案似乎缺乏同步,并且可能同时运行两个请求,一个请求查询另一个请求的“核心”。

当然,您可以同步您的方法。但我认为,在你的情况下,最好不要HttpSolrServer每次都抽搐,而是为你的查询设置额外的参数,这将用作你的baseUrl. 您需要在创建时设置baseUrl一次HttpSolrServer

HttpSolrServer solrHttpServer = new HttpSolrServer(baseUrl);

而不是为每个查询更改它,您将设置参数(代码的差异):

 String queryExpression = "*:*";
 String sortField = "createTime";
-String baseUrl = SolrUtil.getSolrBaseURL(solrHttpServer.getBaseURL());
-solrHttpServer.setBaseURL(baseUrl + "/" + coreName);
 SolrQuery query = new SolrQuery();
+query.set(CommonParams.QT, "/" + coreName + "/select");
 query.setQuery(queryExpression);
 query.setSortField(sortField, SolrQuery.ORDER.asc);
 QueryResponse rsp = solrHttpServer.query(query);

但最好的解决方案是HttpSolrServer为每个核心分开:

Map<String, HttpSolrServer> servers = new HashMap<String, HttpSolrServer>();
servers.put(coreName1, new HttpSolrServer(baseUrl + "/" + coreName1));
...

产生的代码更改:

 String queryExpression = "*:*";
 String sortField = "createTime";
-String baseUrl = SolrUtil.getSolrBaseURL(solrHttpServer.getBaseURL());
-solrHttpServer.setBaseURL(baseUrl + "/" + coreName);
 SolrQuery query = new SolrQuery();
 query.setQuery(queryExpression);
 query.setSortField(sortField, SolrQuery.ORDER.asc);
-QueryResponse rsp = solrHttpServer.query(query);
+QueryResponse rsp = servers.get(coreName).query(query);
于 2013-10-19T08:27:52.637 回答