PHP

Solr PHP Client Example

Define the index FieldS in Solr schema.xml

Before you can index data with solr, you need to define the types of the data. You can do this with the file "schema.xml", which can be found in the /conf folder of your solr installation.

Solr indexes so called "documents" which consists of an array of fields. If you want to add new documents to the index with PHP, you create a $doc-object with the PHP Service Class and fill the fields of the object with its value. Then you send the $doc-object to the solr server. The index will be updated if the $doc-object fits the defined index-schema in the schemal.xml file.

With the following example I will explain the structure of the solr schema.xml:

erläutert:

Example:

<schema name="ayalon" version="1.1">
  ...
  <fields>
  <field name="id" type="string" indexed="true" stored="true" required="true" />
  <field name="title" type="text" indexed="true" stored="true"/>
  <field name="titleSort" type="string" indexed="true" stored="false"/>
  <field name="text" type="text" indexed="true" stored="true"/>
  <field name="category" type="text" indexed="true" stored="true" multiValued="true"/>
  ...
  </fields>
 
  <uniqueKey>id</uniqueKey>
  ...
  <copyField source="title" dest="titleSort"/>
  ...
</schema>

Explanation:

English
Schlagwörter: