/** * Creates a new mapping node.<p> * * @param document the document to modify * @param xpath the xpath to the field mapping, ie <code>opencms/search/fieldconfigurations/fieldconfiguration[name='...']/fields/field[@name="..."]/mappings/mapping[@type='...']</code> * @param mapping the field mapping */ protected void createFieldMapping(Document document, String xpath, CmsSearchFieldMapping mapping) { CmsSetupXmlHelper.setValue(document, xpath + "/@" + I_CmsXmlConfiguration.A_TYPE, mapping.getType().toString()); CmsSetupXmlHelper.setValue(document, xpath + "/@" + I_CmsXmlConfiguration.A_DEFAULT, mapping.getDefaultValue()); // add class attribute (if required) if (!mapping.getClass().equals(CmsSearchFieldMapping.class) || (mapping.getType() == CmsSearchFieldMappingType.DYNAMIC)) { CmsSetupXmlHelper.setValue( document, xpath + "/@" + I_CmsXmlConfiguration.A_CLASS, mapping.getClass().getName()); } if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(mapping.getParam())) { CmsSetupXmlHelper.setValue(document, xpath, mapping.getParam()); } }
/** * Public constructor for a new search field mapping.<p> * * @param type the type to use, see {@link #setType(CmsSearchFieldMappingType)} * @param param the mapping parameter, see {@link #setParam(String)} */ public CmsSearchFieldMapping(CmsSearchFieldMappingType type, String param) { this(); setType(type); setParam(param); }
switch (getType().getMode()) { case 0: // content if (extractionResult != null) { if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParam())) { content = CmsProperty.get(getParam(), properties).getValue(); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParam())) { content = CmsProperty.get(getParam(), propertiesSearched).getValue(); if ((extractionResult != null) && CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParam())) { String[] paramParts = getParam().split("\\|"); Map<String, String> localizedContentItems = null; String xpath = null; xpath = paramParts[0].trim(); content = getContentItemForXPath(localizedContentItems, xpath); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParam())) { I_CmsResource.CmsResourceAttribute attribute = null; try { attribute = I_CmsResource.CmsResourceAttribute.valueOf(getParam()); } catch (Exception e) { content = getDefaultValue();
CmsSearchFieldMapping map = new CmsSearchFieldMapping(CmsSearchFieldMappingType.ITEM, param); field.addMapping(map);
/** * Removes a search field mapping from the given field.<p> * * @param field the field * @param mapping mapping to remove from the field * * @return true if remove was successful, false if preconditions for removal are ok but the given * mapping was unknown. * * @throws CmsIllegalStateException if the given mapping is the last mapping inside the given field. */ public boolean removeSearchFieldMapping(CmsSearchField field, CmsSearchFieldMapping mapping) throws CmsIllegalStateException { if (field.getMappings().size() < 2) { throw new CmsIllegalStateException(Messages.get().container( Messages.ERR_FIELD_MAPPING_DELETE_2, mapping.getType().toString(), field.getName())); } else { if (LOG.isInfoEnabled()) { LOG.info(Messages.get().getBundle().key( Messages.LOG_REMOVE_FIELD_MAPPING_INDEX_2, mapping.toString(), field.getName())); } return field.getMappings().remove(mapping); } }
CmsSearchField.BOOST_DEFAULT); solrField.addMapping( new CmsSearchFieldMapping(CmsSearchFieldMappingType.CONTENT, CmsSearchField.FIELD_CONTENT)); m_solrFields.put(solrField.getName(), solrField); for (Locale locale : OpenCms.getLocaleManager().getAvailableLocales()) { CmsSearchField.BOOST_DEFAULT); solrField.addMapping( new CmsSearchFieldMapping(CmsSearchFieldMappingType.CONTENT, CmsSearchField.FIELD_CONTENT)); m_solrFields.put(solrField.getName(), solrField); CmsSearchFieldMapping map = new CmsSearchFieldMapping( CmsSearchFieldMappingType.ATTRIBUTE, CmsSearchField.FIELD_STATE); map = new CmsSearchFieldMapping(CmsSearchFieldMappingType.ATTRIBUTE, CmsSearchField.FIELD_USER_LAST_MODIFIED); sfield.addMapping(map); m_solrFields.put(sfield.getName(), sfield); map = new CmsSearchFieldMapping(CmsSearchFieldMappingType.ATTRIBUTE, CmsSearchField.FIELD_USER_CREATED); sfield.addMapping(map); m_solrFields.put(sfield.getName(), sfield); map = new CmsSearchFieldMapping(CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_TITLE); sfield.addMapping(map); map = new CmsSearchFieldMapping(CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_DESCRIPTION); sfield.addMapping(map); map = new CmsSearchFieldMapping(CmsSearchFieldMappingType.ATTRIBUTE, I_CmsXmlConfiguration.A_NAME); sfield.addMapping(map);
/** * @see org.opencms.search.fields.I_CmsSearchFieldMapping#setType(java.lang.String) */ public void setType(String type) { CmsSearchFieldMappingType mappingType = CmsSearchFieldMappingType.valueOf(type); if (mappingType == null) { // invalid mapping type has been used, throw an exception throw new CmsRuntimeException( new CmsMessageContainer(Messages.get(), Messages.ERR_FIELD_TYPE_UNKNOWN_1, new Object[] {type})); } setType(mappingType); }
m_mapping = new CmsSearchFieldMapping(true); m_mapping = new CmsSearchFieldMapping(true);
/** * Removes a search field mapping from the given field.<p> * * @param field the field * @param mapping mapping to remove from the field * * @return true if remove was successful, false if preconditions for removal are ok but the given * mapping was unknown. * * @throws CmsIllegalStateException if the given mapping is the last mapping inside the given field. */ public boolean removeSearchFieldMapping(CmsLuceneField field, CmsSearchFieldMapping mapping) throws CmsIllegalStateException { if (field.getMappings().size() < 2) { throw new CmsIllegalStateException( Messages.get().container( Messages.ERR_FIELD_MAPPING_DELETE_2, mapping.getType().toString(), field.getName())); } else { if (LOG.isInfoEnabled()) { LOG.info( Messages.get().getBundle().key( Messages.LOG_REMOVE_FIELD_MAPPING_INDEX_2, mapping.toString(), field.getName())); } return field.getMappings().remove(mapping); } }
/** * Sets the mapping type as a String.<p> * * @param type the name of the type to set */ public void setType(String type) { CmsSearchFieldMappingType mappingType = CmsSearchFieldMappingType.valueOf(type); if (mappingType == null) { // invalid mapping type has been used, throw an exception throw new CmsRuntimeException(new CmsMessageContainer( Messages.get(), Messages.ERR_FIELD_TYPE_UNKNOWN_1, new Object[] {type})); } setType(mappingType); } }
switch (getType().getMode()) { case 0: // content if (extractionResult != null) { case 1: // property case 2: // property-search if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParam())) { boolean search = (getType() == CmsSearchFieldMappingType.PROPERTY_SEARCH); if (search) { content = CmsProperty.get(getParam(), propertiesSearched).getValue(); } else { content = CmsProperty.get(getParam(), properties).getValue(); if ((extractionResult != null) && CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParam())) { content = extractionResult.getContentItems().get(getParam()); content = getDefaultValue();
CmsSearchField.BOOST_DEFAULT, null); field.addMapping(new CmsSearchFieldMapping(CmsSearchFieldMappingType.CONTENT, null)); result.addField(field); 0.0f, null); field.addMapping(new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_TITLE)); field.addMapping(new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_TITLE)); field.addMapping(new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_KEYWORDS)); field.addMapping(new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_DESCRIPTION)); field.addMapping(new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_TITLE)); field.addMapping(new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_KEYWORDS));
/** * Public constructor for a new search field mapping.<p> * * @param type the type to use, see {@link #setType(CmsSearchFieldMappingType)} * @param param the mapping parameter, see {@link #setParam(String)} */ public CmsSearchFieldMapping(CmsSearchFieldMappingType type, String param) { this(); setType(type); setParam(param); }
/** * @see org.opencms.workplace.list.A_CmsListDialog#getListItems() */ @Override protected List<CmsListItem> getListItems() { List<CmsListItem> result = new ArrayList<CmsListItem>(); // get content List<I_CmsSearchFieldMapping> mappings = getMappings(); Iterator<I_CmsSearchFieldMapping> itMappings = mappings.iterator(); CmsSearchFieldMapping mapping; while (itMappings.hasNext()) { mapping = (CmsSearchFieldMapping)itMappings.next(); CmsListItem item = getList().newItem(mapping.getType().toString()); String defaultValue = mapping.getDefaultValue(); String param = mapping.getParam(); if (defaultValue == null) { defaultValue = "-"; } if (param == null) { param = "-"; } item.set(LIST_COLUMN_VALUE, param); item.set(LIST_COLUMN_TYPE, mapping.getType().toString()); item.set(LIST_COLUMN_DEFAULT, defaultValue); result.add(item); } return result; }
CmsSearchField.BOOST_DEFAULT, null); field.addMapping(new CmsSearchFieldMapping(CmsSearchFieldMappingType.CONTENT, null, true)); result.addField(field); null); field.addMapping( new CmsSearchFieldMapping(CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_TITLE, true)); result.addField(field); new CmsSearchFieldMapping(CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_TITLE, true)); result.addField(field); new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_KEYWORDS, new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_DESCRIPTION, new CmsSearchFieldMapping(CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_TITLE, true)); field.addMapping( new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_KEYWORDS, true)); field.addMapping( new CmsSearchFieldMapping(
CmsSearchFieldMapping mapping = (CmsSearchFieldMapping)mappings.next(); Element mappingElement = fieldElement.addElement(N_MAPPING); mappingElement.addAttribute(A_TYPE, mapping.getType().toString()); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(mapping.getDefaultValue())) { mappingElement.addAttribute(A_DEFAULT, mapping.getDefaultValue()); || (mapping.getType() == CmsSearchFieldMappingType.DYNAMIC)) { mappingElement.addAttribute(A_CLASS, mapping.getClass().getName()); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(mapping.getParam())) { mappingElement.setText(mapping.getParam());