content = getDefaultValue(); if (isIndexed()) { if (isTokenizedAndIndexed()) { index = Field.Index.ANALYZED; } else { if (isCompressed()) { store = Field.Store.COMPRESS; } else if (isStored()) { store = Field.Store.YES; Field result = new Field(getName(), content, store, index); if (getBoost() != BOOST_DEFAULT) { result.setBoost(getBoost());
/** * Sets the boost factor of this field (only for display use).<p> * * @param boost the boost factor to set * * @see #setBoost(String) */ public void setBoostDisplay(String boost) { setBoost(boost); }
/** * Returns the field names used for a regular result.<p> * * @return the field names used for a regular result */ public Set<String> getReturnFields() { if (m_fieldAdded) { for (CmsSearchField field : getLuceneFields()) { if (field.isStored() && !LAZY_FIELDS.contains(field.getName())) { m_returnFields.add(field.getName()); } } } m_fieldAdded = false; return m_returnFields; } }
/** * Returns a list of all field names (Strings) that are used in generating the search excerpt.<p> * * @return a list of all field names (Strings) that are used in generating the search excerpt */ public List<String> getExcerptFieldNames() { if (m_excerptFieldNames == null) { // lazy initialize the field names m_excerptFieldNames = new ArrayList<String>(); Iterator<CmsSearchField> i = m_fields.iterator(); while (i.hasNext()) { CmsSearchField field = i.next(); if (field.isInExcerptAndStored()) { m_excerptFieldNames.add(field.getName()); } } } // create a copy of the list to prevent changes in other classes return new ArrayList<String>(m_excerptFieldNames); }
CmsSearchField field = (CmsSearchField)fields.next(); Element fieldElement = fieldsElement.addElement(N_FIELD); fieldElement.addAttribute(A_NAME, field.getName()); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(field.getDisplayNameForConfiguration())) { fieldElement.addAttribute(A_DISPLAY, field.getDisplayNameForConfiguration()); if (field.isCompressed()) { fieldElement.addAttribute(A_STORE, CmsSearchField.STR_COMPRESS); } else { fieldElement.addAttribute(A_STORE, String.valueOf(field.isStored())); if (field.isIndexed()) { if (field.isTokenizedAndIndexed()) { if (field.getBoost() != CmsSearchField.BOOST_DEFAULT) { fieldElement.addAttribute(A_BOOST, String.valueOf(field.getBoost())); if (field.isInExcerptAndStored()) { fieldElement.addAttribute(A_EXCERPT, String.valueOf(true)); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(field.getDefaultValue())) { fieldElement.addAttribute(A_DEFAULT, field.getDefaultValue()); if (field.getAnalyzer() != null) { String className = field.getAnalyzer().getClass().getName(); if (className.startsWith(CmsSearchField.LUCENE_ANALYZER)) { className = className.substring(CmsSearchField.LUCENE_ANALYZER.length()); Iterator mappings = field.getMappings().iterator();
setDisplayName(displayName); setName(name); setStored(isStored); setCompressed(isCompressed); setIndexed(isIndexed); setTokenized(isTokenized); setInExcerpt(isInExcerpt); setAnalyzer(analyzer); setBoost(boost); setDefaultValue(defaultValue);
/** * @see java.lang.Object#toString() */ @Override public String toString() { return getName(); } }
/** * 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); } }
/** * @see org.opencms.workplace.CmsWidgetDialog#actionCommit() */ @Override public void actionCommit() { List<Throwable> errors = new ArrayList<Throwable>(); try { // if new create it first boolean found = false; Iterator<I_CmsSearchFieldMapping> itMappings = m_field.getMappings().iterator(); while (itMappings.hasNext()) { I_CmsSearchFieldMapping curMapping = itMappings.next(); if (curMapping.getType().toString().equals(m_mapping.getType().toString()) && (((curMapping.getParam() == null) && (m_mapping.getParam() == null)) || (curMapping.getParam().equals(m_mapping.getParam())))) { found = true; } } if (!found) { m_field.addMapping(m_mapping); } writeConfiguration(); } catch (Throwable t) { errors.add(t); } // set the list of errors to display when saving failed setCommitErrors(errors); }
/** * Returns a list of <code>{@link CmsSelectWidgetOption}</code> objects for field list selection.<p> * * @return a list of <code>{@link CmsSelectWidgetOption}</code> objects */ private List getFieldList() { List retVal = new ArrayList(); try { Iterator i = getFields().iterator(); while (i.hasNext()) { CmsSearchField field = (CmsSearchField)i.next(); retVal.add(new CmsSelectWidgetOption(field.getName(), true, getMacroResolver().resolveMacros( field.getDisplayName()))); } } catch (Exception e) { // noop } return retVal; }
Analyzer fieldAnalyzer = field.getAnalyzer(); if (fieldAnalyzer != null) { result.addAnalyzer(field.getName(), fieldAnalyzer);
Iterator<CmsSearchFieldMapping> mappings = fieldConfig.getMappings().iterator(); while (mappings.hasNext()) { Fieldable field = fieldConfig.createField(text.toString()); document.add(field);
/** * Checks the configuration to write.<p> * * @return true if configuration is valid, otherwise false */ private boolean checkWriteConfiguration() { if ((m_fieldconfiguration != null) || m_fieldconfiguration.getFields().isEmpty()) { for (CmsSearchField field : m_fieldconfiguration.getFields()) { if (field.getMappings().isEmpty()) { return false; } } return true; } return false; } }
field = new CmsSearchField( CmsSearchField.FIELD_CONTENT, "%(key.field.content)", CmsSearchField.BOOST_DEFAULT, null); field.addMapping(new CmsSearchFieldMapping(CmsSearchFieldMappingType.CONTENT, null)); result.addField(field); field = new CmsSearchField( CmsSearchField.FIELD_TITLE, CmsSearchField.IGNORE_DISPLAY_NAME, 0.0f, null); field.addMapping(new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_TITLE)); field = new CmsSearchField(CmsSearchField.FIELD_TITLE_UNSTORED, "%(key.field.title)", false, true); field.addMapping(new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_TITLE)); field = new CmsSearchField(CmsSearchField.FIELD_KEYWORDS, "%(key.field.keywords)", true, true); field.addMapping(new CmsSearchFieldMapping( CmsSearchFieldMappingType.PROPERTY, CmsPropertyDefinition.PROPERTY_KEYWORDS));
private Map<String, Type> createUninvertingMap() { Map<String, UninvertingReader.Type> uninvertingMap = new HashMap<String, UninvertingReader.Type>(); CmsSearchField.addUninvertingMappings(uninvertingMap); getFieldConfiguration().addUninvertingMappings(uninvertingMap); return uninvertingMap; }
/** * Returns the list of configured field names (Strings).<p> * * @return the list of configured field names (Strings) */ public List<String> getFieldNames() { if (m_fieldNames == null) { // lazy initialize the field names m_fieldNames = new ArrayList<String>(); for (CmsSearchField field : m_fields) { m_fieldNames.add(field.getName()); } } // create a copy of the list to prevent changes in other classes return new ArrayList<String>(m_fieldNames); }
while (itFields.hasNext()) { CmsSearchField curField = itFields.next(); if (curField.getName().equals(getParamField())) { m_field = curField; break; Iterator<I_CmsSearchFieldMapping> itMappings = m_field.getMappings().iterator(); while (itMappings.hasNext()) { I_CmsSearchFieldMapping curMapping = itMappings.next();
for (I_CmsSearchFieldMapping mapping : field.getMappings()) { String mapResult = mapping.getStringValue(cms, resource, extractionResult, properties, propertiesSearched); if (mapResult != null) {
/** * Returns the configured {@link CmsSearchField} instance with the given name.<p> * * @param name the search field name to look up * * @return the configured {@link CmsSearchField} instance with the given name */ public CmsSearchField getField(String name) { if (m_fieldLookup == null) { // lazy initialize the field names m_fieldLookup = new HashMap<String, CmsSearchField>(); for (CmsSearchField field : m_fields) { m_fieldLookup.put(field.getName(), field); } } return m_fieldLookup.get(name); }
/** * Sets the boost factor for this field from a String value.<p> * * @param boost the boost factor to set * * @see #setBoost(float) */ public void setBoost(String boost) { try { setBoost(Float.valueOf(boost).floatValue()); } catch (NumberFormatException e) { // invalid number format, use default boost factor setBoost(BOOST_DEFAULT); } }