Solr仅选择返回ID

时间:2014-01-04 18:01:39

标签: java postgresql search solr

我是Solr的新手,我按照一些教程来设置它。我正在使用Postgresql。当我跑http://localhost:8080/solr/select?q=*:*时,我回来了:

<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">7</int>
    <lst name="params">
      <str name="q">*:*</str>
    </lst></lst>
    <result name="response" numFound="56" start="0">
      <doc>
        <str name="id">1</str>
      </doc>
      <doc>
        <str name="id">2</str>
      </doc>
      ...
      ...
      <doc>
        <str name="id">10</str>
      </doc>
    </result>
  </response>

我希望得到一个包含first_name和last_name的子列表。

requestHandler中的solrconfig.xml

  <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
 <lst name="defaults">
   <str name="config">data-config.xml</str>
 </lst>

我的data-config.xml

    <dataConfig>
<dataSource type="JdbcDataSource"
        driver="org.postgresql.Driver" 
        name="ds1" url="jdbc:postgresql://localhost/some_db" user="db_user" password="hatpants" />
  <document name="kids">
    <entity name="kid" pk="ID" dataSource="ds1" 
            query="select id,first_name,last_name from kid">
        <field column="ID" name="id" indexed="true" />
        <field column="FIRST_NAME" name="first_name" indexed="true" />
        <field column="LAST_NAME" name="last_name" indexed="true" />
    </entity>
  </document>
</dataConfig>

当我运行数据导入时:http://localhost:8080/solr/dataimport?command=full-import我明白了:

<response>
  <lst name="responseHeader">
    <int name="status">0</int>
    <int name="QTime">4</int>
  </lst>
  <lst name="initArgs">
    <lst name="defaults">
      <str name="config">data-config.xml</str>
    </lst></lst>
    <str name="command">full-import</str>
    <str name="status">idle</str>
    <str name="importResponse"/>
    <lst name="statusMessages">
      <str name="Total Requests made to DataSource">1</str>
      <str name="Total Rows Fetched">56</str>
      <str name="Total Documents Skipped">0</str>
      <str name="Full Dump Started">2014-01-04 04:47:14</str>
      <str name="">Indexing completed. Added/Updated: 56 documents. Deleted 0 documents.</str>
      <str name="Committed">2014-01-04 04:47:14</str>
      <str name="Optimized">2014-01-04 04:47:14</str>
      <str name="Total Documents Processed">56</str>
      <str name="Time taken ">0:0:0.243</str>
    </lst>
    <str name="WARNING">This response format is experimental.  It is likely to change in the future.</str>
  </response>

在我看来它能够连接到数据库。我在db中总共有56条记录。当我进行特定选择时,它不会返回任何结果。

1 个答案:

答案 0 :(得分:1)

我明白了。

我需要将这些字段添加到我的schema.xml文件中的字段部分。

<field name="first_name" type="text" indexed="true" stored="true" multiValued="true" />
<field name="last_name" type="text" indexed="true" stored="true" multiValued="true" />

<copyField source="first_name" dest="text"/>
<copyField source="last_name" dest="text"/>