2012-06-10 45 views
1

我剛剛安裝了Solr,我得到了默認架構與我一起工作。但是,當我將模式從默認模式更改爲簡單模式時,我無法通過solr通過php連接,但可以通過tomcat仍然連接。我的PHP代碼如下所示:使用PHP連接Solr

require_once 'Apache/Solr/Service.php'; 

     $solr = new Apache_Solr_Service(
     'xxx.xx.xxx.xxx', 
     8080, 
     '/dev.example.com/'); 

     if(!$solr->ping()){   
      echo 'Solr Down'; 
     } 

而且我在Solr模式

<?xml version="1.0" ?> 
<schema name="testschema1" version="1.5"> 
    <types> 
    <fieldtype name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/> 
    </types> 

<fields> 
    <!-- general --> 
    <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/> 
    <field name="type" type="string" indexed="true" stored="true" multiValued="false" /> 
    <field name="name" type="string" indexed="true" stored="true" multiValued="false" /> 
    <field name="core0" type="string" indexed="true" stored="true" multiValued="false" /> 
</fields> 

<!-- field to use to determine and enforce document uniqueness. --> 
<uniqueKey>id</uniqueKey> 

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

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

而且當我用Java的罐子start.jr我得到這個錯誤

SEVERE: org.apache.solr.common.SolrException: undefined field text 
    at org.apache.solr.schema.IndexSchema.getDynamicFieldType(IndexSchema.java:1330) 
    at org.apache.solr.schema.IndexSchema$SolrQueryAnalyzer.getAnalyzer(IndexSchema.java:408) 

只是爲了澄清,當我將模式更改爲上面的模式時,它只從PHP連接,solr提供的默認模式起作用。我是否缺少一些必需的選項?

回答

1

它看起來像當你嘗試與solr連接時,它正在尋找一個名爲text的字段,該字段在模式中缺失。

以下行添加到您的模式,然後再試一次:

<field name="text" type="text" indexed="true" stored="true" multiValued="true" /> 
+0

不確定這是否合理,默認字段設置爲: name

2

似乎文本字段solrconfig.xml中引用了幾次(我發現通過同樣的錯誤這個帖子)。您可以將這些引用更新爲您選擇的字段名稱(無論您在架構中是否有意義)。

這樣做爲我解決了這個問題。

+1

感謝您在此處添加您的解決方案。看起來比'更好',而不是必須添加一個任意的未使用'text'字段到模式以滿足錯誤消息,但要小心Solr的更新,它可能會替換你的'solrconfig.xml'定製。 – Sepster

+0

的確,我的solrconfig.xml是高度自定義的,並且將其與Apache Solr使用的內聯聯繫起來很痛苦。 – Dan