2011-04-12 38 views
3

我是solr的新手。我有幾個關於Solr的索引和搜索的問題:如何使用單個solr實例(兩個不同的搜索字段沒有連接)對兩個不同的表進行索引和搜索(兩個不同的搜索字段沒有連接)

  1. 我可以配置指數兩個表(沒有任何關係1.書籍和2電腦又都是在同一個數據源)如果我想有兩個搜索框。是否有可能做一個像在一個data-config.xml中定義兩個實體

如果是,請讓我知道的步驟。

我想我們可以使用兩個不同的data-config.xml文件。但是需要知道如何在schema.xml中進行配置和相應的更改。

  1. 如何將solr配置爲索引一個solr實例上的PDF文件和Mysql。

請幫幫我,讓我們知道是否有任何參考文件。

回答

0

您可以輕鬆地使用Solr做到這一點,只需要一個良好的閱讀在DataImportHandler: http://wiki.apache.org/solr/DataImportHandler 和這個例子: http://wiki.apache.org/solr/MultipleIndexes

然後做一些googleing各地的關於實體的具體例子。基本上,你的數據-config.xml中想是這樣的(未測試):

<entity name="books" transformer="TemplateTransformer" dataSource="myindex" 
     query="SELECT * FROM t_books";> 
<field column="category" template="books" name="category"/></entity> 
<entity name="computers" 
      dataSource="myindex" 
     query="SELECT * FROM t_computers"> 
    <field column="category" template="computers" name="category"/></entity> 

使用模板的兩個實體分開,並定義類別字段爲您schema.xml中的字符串。此外,請確保你注意你是如何設置的唯一ID參數,對於這個特定主題的一些信息是在這裏: http://lucene.472066.n3.nabble.com/Indexing-multiple-entities-td504464.html 並檢查在這裏: http://search.lucidimagination.com/search/document/f84c3abf7e859be1/dataimporthanlder_multiple_entities_will_step_into_each_other

通過這種方法,你必須在這兩組數據同樣的指數,如果你希望他們爲兩個獨立的搜索框工作,你可以簡單地運行您的搜索,如:

更改爲MyQuery和類別:(書籍)< ---這隻會讓你從書本結果或者這另一個只會讓你的計算機結果---> myquery和類別:(電腦)。 希望它有幫助。 併爲您的PDF的問題,我認爲你必須使用Apache的提卡模塊,我不會在這裏多的幫助,我沒有用它自己,但這裏的鏈接: http://wiki.apache.org/solr/TikaEntityProcessor

+0

當我試圖指數兩個Entity這種風格,它甚至沒有編入索引的實體。 – 2014-03-20 10:33:06

+0

請參考以下鏈接:http://stackoverflow.com/questions/22534121/how-to-index-and-search-two-different-tables-which-are-in-same-datasource-using – 2014-03-20 13:20:30

5

2個不同的表沒有關係

數據-config.xml中:

<document> 
     <entity name="topic" transformer="TemplateTransformer" pk="topic_id" query="select topic_id,topic_title,creation_date,updation_date,vote_count,....."> 
      <field column=" doc_id " template="TOPIC_${topic.topic_id} " /> 
      <field column="doc_type " template="TOPIC " /> 

     </entity> 

     <entity name="product " transformer="TemplateTransformer " pk="product_id " query="SELECT product_id,..... "> 
      <field column="doc_id " template="PRODUCT_${product.product_id} " /> 
      <field column="doc_type " template="PRODUCT " /> 
      <field column="product_supplier_id " name="product_supplier_id " /> 
      <field column="supplier_product_code " name="supplier_product_code " /> 
      <field column="product_display_name " name="product_display_name " /> 
     </entity> 
    </document> 

架構。XML:

<schema> 
     . . . 
     <fields> 

      <field name="doc_id" type="string" /> 
      <field name="doc_type" type="string" /> 

      <field name="catchall" type="string" stored="false" omitNorms="true" multiValued="true" /> 


      <field name="topic_title" type="text_general" />. . . . 
     </fields> 

     <uniqueKey>doc_id</uniqueKey> 
     <copyField source="*" dest="catchall" /> 

     <!-- field for the QueryParser to use when an explicit fieldname is absent --> 
     <defaultSearchField>catchall</defaultSearchField> 
    </schema> 

更多信息 - http://www.lucidimagination.com/blog/2011/02/12/solr-powered-isfdb-part-4/

沒有上述領域應要求或建立索引時

可能會產生問題

你可以在瀏覽器查詢像http://localhost:8080/solr/select/?q=*:*&fq=doc_type:PRODUCT

+0

救星,謝謝。 – bluehallu 2013-08-22 09:41:15

相關問題