如何调试solr查询而不返回记录

时间:2013-06-19 15:05:35

标签: tomcat solr schema

我正在努力让solr与我的组织合作。它在tomcat 6上设置为多核solr 3.6。

到目前为止,我已修改示例schema.xml以接受记录的特定字段。记录没有问题,当我对所有记录(?q=*:*)运行查询时,它返回所有内容。但是,当我查询绝对在记录中的特定术语(例如?q=green?q=product_description:green)时,没有结果出现。虽然如果我插入一些默认的示例文档,如ipod_video.xml或ipod_other.xml,那么如果它们搜索它们会出现这些记录(例如?q=ipod?q=video

我们所有的新字段都是用indexed=true定义的,所以如果我们查询它们,我不知道为什么我们自己的记录根本就没出现。

有关如何调试此行为的任何想法?

更新 - 添加schema.xml和solrconfig.xml详细信息。

schema.xml与solr 3.6附带的默认schema.xml几乎相同,但添加了这些字段

<fields>
<field name="search_title" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="search_prefix" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="search_description" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="search_content" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="product_date" type="date" indexed="true" stored="true" multiValued="true"/>
<field name="product_thumbnail" type="string" indexed="true" stored="true" multiValued="true"/>

<field name="product_type" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="product_updatepricefunction" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="tagids" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="tagid" type="string" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*_tag" type="string" indexed="true" stored="true"/>
<field name="event_id" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="activity_id" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="activity_function_code" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="search_room" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="weekday" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="activity_weekday" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="activity_begindate" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="activity_begintime" type="string" indexed="true" stored="true"  multiValued="true"/>
<field name="activity_endtime" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="audience" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="format" type="text_general" indexed="true" stored="true"   multiValued="true"/>
<field name="publish_date" type="date" indexed="true" stored="true" multiValued="true"/>
<field name="isbn" type="string" indexed="true" stored="true" multiValued="true" />
<field name="product_code" type="string" indexed="true" stored="true" required="true"/>
</fields>

<uniqueKey>product_code</uniqueKey>

,这是solrconfig.xml的请求处理程序

<requestHandler name="/select" class="solr.SearchHandler">
<!-- default values for query parameters can be specified, these
     will be overridden by parameters in the request
  -->
 <lst name="defaults">
   <str name="echoParams">explicit</str>
   <int name="rows">10</int>
   <str name="df">text</str>
 </lst>
<!-- In addition to defaults, "appends" params can be specified
     to identify values which should be appended to the list of
     multi-val params from the query (or the existing "defaults").
  -->
<!-- In this example, the param "fq=instock:true" would be appended to
     any query time fq params the user may specify, as a mechanism for
     partitioning the index, independent of any user selected filtering
     that may also be desired (perhaps as a result of faceted searching).

     NOTE: there is *absolutely* nothing a client can do to prevent these
     "appends" values from being used, so don't use this mechanism
     unless you are sure you always want it.
  -->
<!--
   <lst name="appends">
     <str name="fq">inStock:true</str>
   </lst>
  -->
<!-- "invariants" are a way of letting the Solr maintainer lock down
     the options available to Solr clients.  Any params values
     specified here are used regardless of what values may be specified
     in either the query, the "defaults", or the "appends" params.

     In this example, the facet.field and facet.query params would
     be fixed, limiting the facets clients can use.  Faceting is
     not turned on by default - but if the client does specify
     facet=true in the request, these are the only facets they
     will be able to see counts for; regardless of what other
     facet.field or facet.query params they may specify.

     NOTE: there is *absolutely* nothing a client can do to prevent these
     "invariants" values from being used, so don't use this mechanism
     unless you are sure you always want it.
  -->
<!--
   <lst name="invariants">
     <str name="facet.field">cat</str>
     <str name="facet.field">manu_exact</str>
     <str name="facet.query">price:[* TO 500]</str>
     <str name="facet.query">price:[500 TO *]</str>
   </lst>
  -->
<!-- If the default list of SearchComponents is not desired, that
     list can either be overridden completely, or components can be
     prepended or appended to the default list.  (see below)
  -->
<!--
   <arr name="components">
     <str>nameOfCustomComponent1</str>
     <str>nameOfCustomComponent2</str>
   </arr>
  -->
</requestHandler>

1 个答案:

答案 0 :(得分:1)

q=<search phrase>表示从所提到的默认字段中搜索。但是,如果您尚未指定默认字段,或者想要查询默认字段以外的特定字段,则应查询Solr,如q=<fieldname>:<search phrase>

Solr提供各种分析器,您可以根据需要使用这些分析器索引文档。看看here

问题更新后编辑

1st - /select requestHandler默认使用字段text,而schema.xml文件没有名为text的字段。

第二 - 在schema.xml文件中,字段search_titlesearch_descriptionsearch_contentaudienceformat属于text_general类型这是标记化的。所有其他字段都是String类型。

第3天 - 要在String类型的字段中进行搜索,您需要拥有确切的搜索短语,或者需要使用通配符。对于例如如果您的文档在green字段中的值为product_type,则查询q=product_type:green会在搜索结果中显示该文档。但是,如果green color字段中的值为product_type,则查询q=product_type:green将不会提供任何输出。但是查询q=product_type:green*会在搜索结果中为您提供一个文档。

我想我已经给你一个良好的开端和关于Solr的基本信息。您现在应该继续阅读我上面提供的链接。