Time for action – defining an example document

We can now define a new Solr document and post it to the new core to index it with the following steps:

  1. Our document will have the following structure:
    <add>
      <doc>
        <field name='id'>01</field>
        <field name='author'>Erich Gamma</field>
        <field name='author'>Richard Helm</field>
        <field name='author'>Ralph Johnson</field>
        <field name='author'>John Vlissides</field>
        <field name='title'>Design Patterns: Elements of Reusable Object-Oriented Software</field>
        <field name='text'>Design Patterns: Elements of Reusable Object-Oriented Software is a software engineering book describing recurring solutions to common problems in software design. (Source:http://en.wikipedia.org/wiki/Design_Patterns)</field>
        <field name='fullText' type='string'>The most famous book about Design Patterns.</field>
        <field name='keyword_string'>Design Patterns</field>
        <field name='keyword_string'>Software</field>
        <field name='language_string'>C++</field>
        <field name='language_string'>Smalltalk</field>
      </doc>
    </add>
  2. Now, to simplify,save it with the name docs.xml under the /SolrStarterBook/solr-app/test/chp02/ directory.

What just happened?

In this small example we can easily recognize how the different types of fields are used. We write a value for every field representing the document, and multiple lines for multivalued fields (one for each different value to be added). Note that the field with the names keyword_string and language_string are handled as dynamic fields in our configuration.

Finally we directly added some text for the field fullText, even if we have defined it just as a destination for copyField and as the default field for searches. We did this to demonstrate two basic facts: the field is just a normal field, and its value will be added twice in the index according to copyField we have defined, which takes every field as a source (source='*'). The reason for this apparently wrong behavior is that copyField concatenates values on the destination field. So if you already have text in the field you use as the destination, you should use another way to select sources. You probably would map sources by an explicit name, and in most real cases you would choose not to post any value to the destination field.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.107.210