On 8/13/2015 4:00 AM, griglo wrote:
> Hello, I have rather simple question regarding copyFields and appending of
> values. I am using Solr 3.7. Is it possible to define some given value in
> schema.xml and use that with copyField directive ?? I would like to append
> some values (tokens) to field which is constructed from another fields using
> copyFields. Or only solution is to provide those tokens in indexed documents
> as fields ?? I prefer having those token values configured in schema rather
> than providing them directly in documents. Thank you.

Since there is no version 3.7, I assume you're running 4.7.

You can define fields in your schema with a default value.  As long as
you are absolutely certain that your indexing program will never send
those fields, then the default value will always be present, and I am
pretty sure that it can be copied to another field.  I have not actually
tried this, but the theory is sound, and if it doesn't work, I'd file a
bug, because I think it SHOULD work.

Here is a very small example schema, created with copy/paste from an
actual schema and a tiny bit of editing.  I don't know if it would work
as a complete schema or not.  It might be missing some important component.

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="test" version="1.5">
  <uniqueKey>id</uniqueKey>
  <fieldType name="string" class="solr.StrField" sortMissingLast="true"
omitNorms="true" termPositions="false"/>
  <fieldtype name="ignored" class="solr.StrField" stored="false"
indexed="false" multiValued="true" omitNorms="true"/>
  <fieldType name="genText" class="solr.TextField"
sortMissingLast="true" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
    </analyzer>
  </fieldType>

  <field name="id" type="string" indexed="true" stored="true"
omitTermFreqAndPositions="true" docValues="true" required="true"/>
  <field name="description" type="genText" indexed="true" stored="true"/>
  <field name="catchall" type="genText" indexed="true" stored="false"
multiValued="true" termVectors="true"/>
  <field name="default1" type="ignored" default="Extra Stuff"/>

 <copyField source="description" dest="catchall"/>
  <copyField source="default1" dest="catchall"/>
</schema>

When you index a document that contains "id" and "description", but
leave out default1, the catchall field should end up containing the
description as well as the "Extra Stuff" that is the default value on
default1.  The default1 field itself will not be in the index, because
it is set to the "ignored" type that is not indexed or stored.

Thanks,
Shawn

Reply via email to