/** * Public constructor.<p> * * @param luceneField */ public CmsSolrField(CmsLuceneField luceneField) { super(); String name = luceneField.getName(); IndexSchema schema = OpenCms.getSearchManager().getSolrServerConfiguration().getSolrSchema(); if (schema.hasExplicitField(name)) { // take the lucene field name for Solr } else if ((luceneField.getType() != null) && schema.isDynamicField(luceneField.getName() + "_" + luceneField.getType())) { // try to use the specified type attribute as dynamic field suffix name = luceneField.getName() + "_" + luceneField.getType(); } else { // fallback create a general_text field name = luceneField.getName() + "_txt"; } setName(name); setBoost(luceneField.getBoost()); setDefaultValue(luceneField.getDefaultValue()); for (I_CmsSearchFieldMapping mapping : luceneField.getMappings()) { addMapping(mapping); } }
/** * Returns the list of searchable fields used in the workplace search index.<p> * * @return the list of searchable fields used in the workplace search index */ public List<CmsLuceneField> getFields() { CmsSearchIndex index = getIndex(); List<CmsLuceneField> result = new ArrayList<CmsLuceneField>(); Iterator<CmsSearchField> i = index.getFieldConfiguration().getFields().iterator(); while (i.hasNext()) { CmsLuceneField field = (CmsLuceneField)i.next(); if (field.isIndexed() && field.isDisplayed()) { // only include indexed (ie. searchable) fields result.add(field); } } return result; }
/** * Returns <code>true</code> if this fields content is used in the search result excerpt.<p> * * A field can only be used in the excerpt if it is stored, see {@link #isStored()}.<p> * * @return <code>true</code> if this fields content is used in the search result excerpt * * @see #isStored() */ public boolean isInExcerptAndStored() { return isInExcerpt() && isStored(); }
/** * Returns the display name of the field.<p> * * @return the display name of the field */ public String getDisplayName() { if (!isDisplayed()) { return IGNORE_DISPLAY_NAME; } if (m_displayName == null) { return getName(); } else { return m_displayName; } }
/** * Creates a field from the configuration and the provided content.<p> * * The configured name of the field as provided by {@link #getName()} is used.<p> * * If no valid content is provided (that is the content is either <code>null</code> or * only whitespace), then no field is created and <code>null</code> is returned.<p> * * @param content the content to create the field with * * @return a field created from the configuration and the provided content */ public Field createField(String content) { return createField(getName(), content); }
CmsSetupXmlHelper.setValue(document, xpath + "/@" + I_CmsXmlConfiguration.A_NAME, field.getName()); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(field.getDisplayNameForConfiguration())) { CmsSetupXmlHelper.setValue( document, xpath + "/@" + CmsSearchConfiguration.A_DISPLAY, field.getDisplayNameForConfiguration()); if (field.isCompressed()) { CmsSetupXmlHelper.setValue( document, document, xpath + "/@" + CmsSearchConfiguration.A_STORE, String.valueOf(field.isStored())); if (field.isIndexed()) { if (field.isTokenizedAndIndexed()) { if (field.getBoost() != CmsSearchField.BOOST_DEFAULT) { CmsSetupXmlHelper.setValue( document, xpath + "/@" + CmsSearchConfiguration.A_BOOST, String.valueOf(field.getBoost())); if (field.isInExcerptAndStored()) { CmsSetupXmlHelper.setValue(document, xpath + "/@" + CmsSearchConfiguration.A_EXCERPT, String.valueOf(true)); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(field.getDefaultValue())) { CmsSetupXmlHelper.setValue(
while (itFields.hasNext()) { CmsLuceneField field = (CmsLuceneField)itFields.next(); String fieldName = field.getName(); boolean fieldStore = field.isStored(); String fieldIndex = field.getIndexed(); boolean fieldExcerpt = field.isInExcerpt(); float fieldBoost = field.getBoost(); String fieldDefault = field.getDefaultValue(); html.append(", ").append("default=").append(field.getDefaultValue()); Iterator<I_CmsSearchFieldMapping> itMappings = field.getMappings().iterator(); while (itMappings.hasNext()) { CmsSearchFieldMapping mapping = (CmsSearchFieldMapping)itMappings.next();
/** * @see org.opencms.workplace.list.A_CmsListDialog#getListItems() */ @Override protected List<CmsListItem> getListItems() { List<CmsListItem> result = new ArrayList<CmsListItem>(); // get content List<CmsSearchField> fields = getFields(); Iterator<CmsSearchField> itFields = fields.iterator(); CmsLuceneField field; while (itFields.hasNext()) { field = (CmsLuceneField)itFields.next(); CmsListItem item = getList().newItem(field.getName()); String defaultValue = field.getDefaultValue(); if (defaultValue == null) { defaultValue = "-"; } item.set(LIST_COLUMN_NAME, field.getName()); item.set(LIST_COLUMN_DISPLAY, resolveMacros(field.getDisplayName())); item.set(LIST_COLUMN_BOOST, new Float(field.getBoost()).toString()); item.set(LIST_COLUMN_INDEX, field.getIndexed()); item.set(LIST_COLUMN_EXCERPT_HIDE, Boolean.valueOf(field.isInExcerpt())); item.set(LIST_COLUMN_STORE_HIDE, Boolean.valueOf(field.isStored())); item.set(LIST_COLUMN_DEFAULT, defaultValue); result.add(item); } return result; }
content = getDefaultValue(); if (isIndexed()) { if (isTokenizedAndIndexed()) { ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); ft.setTokenized(true); ft.setStored(isStored() || isCompressed()); Field result = new Field(name, content, ft); if (getBoost() != BOOST_DEFAULT) { result.setBoost(getBoost());
/** * 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); } }
if (m_field.getName() == null) { m_field.setStored(true); m_field.setIndexed(true); m_field.setDisplayed(true); m_field.setBoost(CmsSearchField.BOOST_DEFAULT); if (m_field.getName() == null) { addWidget(new CmsWidgetDialogParameter(m_field, "name", PAGES[0], new CmsInputWidget())); } else {
while (itFields.hasNext()) { CmsLuceneField curField = (CmsLuceneField)itFields.next(); if (curField.getName().equals(field)) { fieldObject = curField; fieldObject.setInExcerpt(true); writeConfiguration(true); fieldObject.setIndexed(true); writeConfiguration(true); fieldObject.setStored(true); writeConfiguration(true); fieldObject.setInExcerpt(false); writeConfiguration(true); fieldObject.setIndexed(false); writeConfiguration(true); fieldObject.setStored(false); writeConfiguration(true);
/** * 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<CmsSelectWidgetOption> getFieldList() { List<CmsSelectWidgetOption> retVal = new ArrayList<CmsSelectWidgetOption>(); try { Iterator<CmsSearchField> i = getSearchFields().iterator(); while (i.hasNext()) { CmsLuceneField field = (CmsLuceneField)i.next(); retVal.add( new CmsSelectWidgetOption( field.getName(), true, getMacroResolver().resolveMacros(field.getDisplayName()))); } } catch (Exception e) { // noop } return retVal; }
result.append(key(Messages.GUI_LIST_FIELD_ACTION_DELETE_CONF_1, new Object[] {m_field.getName()})); result.append(createWidgetTableEnd()); result.append(dialogBlockEnd());
/** * Returns the String value state of this field if it is indexed (and possibly tokenized) in the Lucene index.<p> * * @return the String value state of this field if it is indexed (and possibly tokenized) in the Lucene index * * @see #isTokenizedAndIndexed() * @see #isIndexed() */ @Override public String getIndexed() { if (isTokenizedAndIndexed()) { return String.valueOf(isTokenizedAndIndexed()); } if (isIndexed()) { return STR_UN_TOKENIZED; } else { return String.valueOf(isIndexed()); } }
/** * 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 = getFields().iterator(); while (i.hasNext()) { CmsLuceneField field = (CmsLuceneField)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); }
/** * Returns an analyzer that wraps the given base analyzer with the analyzers of this individual field configuration.<p> * * @param analyzer the base analyzer to wrap * * @return an analyzer that wraps the given base analyzer with the analyzers of this individual field configuration */ public Analyzer getAnalyzer(Analyzer analyzer) { // parent folder and last modified lookup fields must use whitespace analyzer WhitespaceAnalyzer ws = new WhitespaceAnalyzer(); Map<String, Analyzer> analyzers = new HashMap<String, Analyzer>(); // first make map the default hard coded fields analyzers.put(CmsSearchField.FIELD_PARENT_FOLDERS, ws); analyzers.put(CmsSearchField.FIELD_CATEGORY, ws); analyzers.put(CmsSearchField.FIELD_DATE_LASTMODIFIED_LOOKUP, ws); analyzers.put(CmsSearchField.FIELD_DATE_CREATED_LOOKUP, ws); for (CmsLuceneField field : getLuceneFields()) { Analyzer fieldAnalyzer = field.getAnalyzer(); if (fieldAnalyzer != null) { // this field has an individual analyzer configured analyzers.put(field.getName(), fieldAnalyzer); } } // return the individual field configured analyzer return new PerFieldAnalyzerWrapper(analyzer, analyzers); }
while (itFields.hasNext()) { CmsLuceneField curField = (CmsLuceneField)itFields.next(); if (curField.getName().equals(getParamField())) { m_field = curField; break; m_field = new CmsLuceneField(); m_field = new CmsLuceneField();
/** * Returns <code>true</code> if the content of this field is tokenized in the Lucene index.<p> * * A field can only be tokenized if it is also indexed, see {@link #isIndexed()}.<p> * * Please refer to the Lucene documentation about the concept behind tokenized and untokenized fields.<p> * * @return <code>true</code> if the content of this field is tokenized in the Lucene index * * @see #isStored() * @see #isIndexed() */ public boolean isTokenizedAndIndexed() { return m_tokenized && isIndexed(); }
/** * Checks the configuration to write.<p> * * @return true if configuration is valid, otherwise false */ private boolean checkWriteConfiguration() { if (!m_field.getMappings().isEmpty()) { return true; } return false; } }