[opencms-dev] solr property mapping, multivalue

Rüdiger Kurz r.kurz at alkacon.com
Fri Feb 15 11:42:01 CET 2013


Hi Carl-Erik,

1. Add a field 'yourFieldName' to the schema.xml

2. Adjust, compile and add the attached class example to the classpath

3. Adjust the Solr field config of your index (opencms-search.xml)

<fieldconfiguration 
class="org.opencms.search.solr.CmsSolrFieldConfiguration">
   <name>your_solr_config</name>
   <description>The Solr field configuration.</description>
     <fields>
       <field name="yourFieldName">
         <mapping type="dynamic"
                  class="your.package.CmsDynamicDummyField">
           special
         </mapping>
       </field>
     </fields>
</fieldconfiguration>

Good luck!
rüdiger

Am 15.02.2013 11:21, schrieb Carl-Erik Herheim:
> Thanks for the quick reply Rüdiger,
>
> 1) The field value comes from an OpenCms property field
> 2) Yes, it can be formatted in any way necessary
> 3) My programming skills are somewhat limited, but yes.
>
> - Carl-Erik
>
> Rüdiger Kurz skrev 15.02.2013 10:51:
>> Hi Carl-Erik,
>>
>> where does your field values come from?
>> 1. From a XML content
>> 2. A OpenCms Property
>>
>> Do you have the opportunity to manipulate that value? Like using
>> another separator, removing white spaces??
>>
>> Are you able to write a own Java class and add it to your class path?
>>
>> Depending on your answer the solution will be different.
>>
>> regards
>> Rüdiger
>>
>>
>> Am 15.02.2013 10:07, schrieb Carl-Erik Herheim:
>>> Hey list,
>>>
>>> I'm wondering if it's possible to map property values to a multivalue
>>> field in the solr index.
>>> For example, if a property field has the value "A, B, C, D", I would
>>> like this to be indexed in a multivalued field,
>>> where each letter is an individual value. Is there any way to do this?
>>>
>>>
>>> Thanks,
>>> Carl-Erik

-- 
Kind Regards,
Rüdiger.

-------------------

Rüdiger Kurz

Alkacon Software GmbH  - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org
-------------- next part --------------
package org.opencms.search.solr;

import org.opencms.file.CmsObject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsResource;
import org.opencms.search.extractors.I_CmsExtractionResult;
import org.opencms.search.fields.CmsSearchFieldMapping;
import org.opencms.search.fields.CmsSearchFieldMappingType;

import java.util.List;

/**
 * Dummy Field Mapping implementation.<p>
 */
public class CmsDynamicDummyField extends CmsSearchFieldMapping {

    /** Serial version UID. */
    private static final long serialVersionUID = -3451280904747959635L;

    /**
     * Public constructor.<p>
     */
    public CmsDynamicDummyField() {

        super();
    }

    /**
     * @see org.opencms.search.fields.CmsSearchFieldMapping#getStringValue(org.opencms.file.CmsObject, org.opencms.file.CmsResource, org.opencms.search.extractors.I_CmsExtractionResult, java.util.List, java.util.List)
     */
    @Override
    public String getStringValue(
        CmsObject cms,
        CmsResource res,
        I_CmsExtractionResult extractionResult,
        List<CmsProperty> properties,
        List<CmsProperty> propertiesSearched) {

        String result = null;
        if (getType().getMode() == CmsSearchFieldMappingType.DYNAMIC.getMode()) {
            // dynamic mapping
            if ("special".equals(getParam())) {

                for (CmsProperty prop : properties) {
                    if (prop.getName().equals("yourProp")) {
                        String value = prop.getValue();
                        result = value.replaceAll("YOUR_SEPARATOR", "\n");
                    }
                }
            }
        } else {
            // default mapping
            result = super.getStringValue(cms, res, extractionResult, properties, propertiesSearched);
        }
        return result;
    }
}


More information about the opencms-dev mailing list