Solr为术语向量查询返回错误500

时间:2016-02-24 20:21:14

标签: solr

在solr query web界面中的

我想得到术语向量值,例如具有最高术语频率的术语,等等。

为此,我使用查询http://domain/tvrh?q=text:[* TO *]&wt=json&indent=true&tv.all=true&terms.fl=text

此查询出现以下错误:

"termVectors": [
"uniqueKeyFieldName",
"_id",
"14708d4c-7145-46b7-98d0-727baff35ab9",
[
  "uniqueKey",
  "14708d4c-7145-46b7-98d0-727baff35ab9"
]
],
  "error": {
"trace": "java.lang.NullPointerException
at org.apache.solr.handler.component.TermVectorComponent.process(TermVectorComponent.java:329)
at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:277)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:143)
at org.apache.solr.core.SolrCore.execute(SolrCore.java:2068)
at org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:669)
at org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:462)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:214)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:179)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)
",
            "code": 500

有什么想法吗?

编辑:

我的schema.xml描述字段:

<field name="description" 
 type="text_general"
 indexed="true" 
 stored="true" 
 multiValued="true" 
 termVectors="true" 
 termPositions="true" 
 termOffsets="true"/>


<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stop-words-all-sorted.txt" />
    <!-- in this example, we will only use synonyms at query time
    <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
    -->
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stop-words-all-sorted.txt" />
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

根据Karsten的建议,无论查询如何,我都会使用/ terms来获得term-frequency。 http://localhost:8983/solr/core/terms?wt=json&indent=true&terms.fl=description

我现在得到术语频率,但是没有显示单个术语,但存储了整个文本。

1 个答案:

答案 0 :(得分:2)

IndexReader.html#getTermVectors的结果为空导致Nullpointer异常,因此大多数情况下您没有使用TermVectortermVectors="true")建立索引。

您可以在schema.xml的field definition中添加TermVectors。例如:

<field name="includes"
   type="text_general"
   indexed="true"
   stored="true"
   multiValued="true"
   termVectors="true"
   termPositions="true"
   termOffsets="true" />

顺便说一句:

如果您希望文档频率不受查询限制,则应使用Terms Component

如果您希望文档频率仅限于查询,则可以使用facetting(以“text”作为facet)。