Search in sources :

Example 1 with I_CmsSearchIndex

use of org.opencms.search.I_CmsSearchIndex in project opencms-core by alkacon.

the class CmsSearchConfiguration method generateXml.

/**
 * @see org.opencms.configuration.I_CmsXmlConfiguration#generateXml(org.dom4j.Element)
 */
public Element generateXml(Element parent) {
    // add <search> node
    Element searchElement = parent.addElement(N_SEARCH);
    if (OpenCms.getRunLevel() >= OpenCms.RUNLEVEL_3_SHELL_ACCESS) {
        // initialized OpenCms instance is available, use latest values
        m_searchManager = OpenCms.getSearchManager();
    }
    // add class attribute (if required)
    if (!m_searchManager.getClass().equals(CmsSearchManager.class)) {
        searchElement.addAttribute(A_CLASS, m_searchManager.getClass().getName());
    }
    // add the Solr node
    if (m_searchManager.getSolrServerConfiguration() != null) {
        Element solr = searchElement.addElement(N_SOLR);
        CmsSolrConfiguration conf = m_searchManager.getSolrServerConfiguration();
        solr.addAttribute(A_ENABLED, new Boolean(conf.isEnabled()).toString());
        if (conf.getServerUrl() != null) {
            solr.addAttribute(A_SERVER_URL, conf.getServerUrl().toString());
        }
        if (conf.getHomeFolderPath() != null) {
            solr.addElement(N_HOME).addText(conf.getHomeFolderPath());
        }
        if (conf.getSolrFileName() != null) {
            solr.addElement(N_CONFIG_FILE).addText(conf.getSolrFileName());
        }
        solr.addElement(N_COMMIT_MS).addText(String.valueOf(conf.getSolrCommitMs()));
    }
    // add <directory> element
    searchElement.addElement(N_DIRECTORY).addText(m_searchManager.getDirectory());
    // add <timeout> element
    searchElement.addElement(N_TIMEOUT).addText(String.valueOf(m_searchManager.getTimeout()));
    // add <offlineUpdateFrequency> element
    searchElement.addElement(N_OFFLINE_UPDATE_FREQUENCY).addText(String.valueOf(m_searchManager.getOfflineUpdateFrequency()));
    // add <maxIndexWaitTime> element
    searchElement.addElement(N_MAX_INDEX_WAIT_TIME).addText(String.valueOf(m_searchManager.getMaxIndexWaitTime()));
    // add <forceunlock> element
    if (m_searchManager.getForceunlock() != null) {
        searchElement.addElement(N_FORCEUNLOCK).addText(m_searchManager.getForceunlock().toString());
    }
    // add <exerpt> element
    searchElement.addElement(N_EXCERPT).addText(String.valueOf(m_searchManager.getMaxExcerptLength()));
    // add <extractionCacheMaxAge> element
    searchElement.addElement(N_EXTRACTION_CACHE_MAX_AGE).addText(String.valueOf(m_searchManager.getExtractionCacheMaxAge()));
    // add <maxModificationsBeforeCommit> element
    searchElement.addElement(N_MAX_MODIFICATIONS_BEFORE_COMMIT).addText(String.valueOf(m_searchManager.getMaxModificationsBeforeCommit()));
    // add <highlighter> element
    searchElement.addElement(N_HIGHLIGHTER).addText(m_searchManager.getHighlighter().getClass().getName());
    // <documenttypes>
    Element documenttypesElement = searchElement.addElement(N_DOCUMENTTYPES);
    for (CmsSearchDocumentType currSearchDocType : m_searchManager.getDocumentTypeConfigs()) {
        // add the next <documenttype> element
        Element documenttypeElement = documenttypesElement.addElement(N_DOCUMENTTYPE);
        // add <name> element
        documenttypeElement.addElement(N_NAME).addText(currSearchDocType.getName());
        // add <class> element
        documenttypeElement.addElement(N_CLASS).addText(currSearchDocType.getClassName());
        // add <mimetypes> element
        Element mimetypesElement = documenttypeElement.addElement(N_MIMETYPES);
        // get the list of mimetypes to trigger the document factory class
        Iterator<String> mimeTypesIterator = currSearchDocType.getMimeTypes().iterator();
        while (mimeTypesIterator.hasNext()) {
            // add <mimetype> element(s)
            mimetypesElement.addElement(N_MIMETYPE).addText(mimeTypesIterator.next());
        }
        // add <resourcetypes> element
        Element restypesElement = documenttypeElement.addElement(N_RESOURCETYPES);
        // get the list of Cms resource types to trigger the document factory
        Iterator<String> resTypesIterator = currSearchDocType.getResourceTypes().iterator();
        while (resTypesIterator.hasNext()) {
            // add <resourcetype> element(s)
            restypesElement.addElement(N_RESOURCETYPE).addText(resTypesIterator.next());
        }
    }
    // </documenttypes>
    // <analyzers>
    Element analyzersElement = searchElement.addElement(N_ANALYZERS);
    ArrayList<Locale> analyzerLocaleList = new ArrayList<Locale>(m_searchManager.getAnalyzers().keySet());
    // sort Analyzers in ascending order
    Collections.sort(analyzerLocaleList, CmsLocaleComparator.getComparator());
    Iterator<Locale> analyzersLocaleInterator = analyzerLocaleList.iterator();
    while (analyzersLocaleInterator.hasNext()) {
        CmsSearchAnalyzer searchAnalyzer = m_searchManager.getCmsSearchAnalyzer(analyzersLocaleInterator.next());
        // add the next <analyzer> element
        Element analyzerElement = analyzersElement.addElement(N_ANALYZER);
        // add <class> element
        analyzerElement.addElement(N_CLASS).addText(searchAnalyzer.getClassName());
        // add <locale> element
        analyzerElement.addElement(N_LOCALE).addText(searchAnalyzer.getLocale().toString());
    }
    // </analyzers>
    // <indexes>
    Element indexesElement = searchElement.addElement(N_INDEXES);
    for (I_CmsSearchIndex searchIndex : m_searchManager.getSearchIndexesAll()) {
        // add the next <index> element
        Element indexElement = indexesElement.addElement(N_INDEX);
        // add class attribute (if required)
        if (!searchIndex.getClass().equals(CmsSearchIndex.class)) {
            indexElement.addAttribute(A_CLASS, searchIndex.getClass().getName());
        }
        // add <name> element
        indexElement.addElement(N_NAME).addText(searchIndex.getName());
        // add <rebuild> element
        indexElement.addElement(N_REBUILD).addText(searchIndex.getRebuildMode());
        // add <project> element
        indexElement.addElement(N_PROJECT).addText(searchIndex.getProject());
        // add <locale> element
        indexElement.addElement(N_LOCALE).addText(searchIndex.getLocale().toString());
        // add <configuration> element
        String fieldConfigurationName = searchIndex.getFieldConfigurationName();
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(fieldConfigurationName)) {
            indexElement.addElement(N_CONFIGURATION).addText(fieldConfigurationName);
        }
        // add <sources> element
        Element sourcesElement = indexElement.addElement(N_SOURCES);
        // iterate above sourcenames
        Iterator<String> sourcesIterator = searchIndex.getSourceNames().iterator();
        while (sourcesIterator.hasNext()) {
            // add <source> element
            sourcesElement.addElement(N_SOURCE).addText(sourcesIterator.next());
        }
        // iterate additional params
        CmsParameterConfiguration indexConfiguration = searchIndex.getConfiguration();
        if (indexConfiguration != null) {
            indexConfiguration.appendToXml(indexElement);
        }
    }
    // </indexes>
    // <indexsources>
    Element indexsourcesElement = searchElement.addElement(N_INDEXSOURCES);
    for (CmsSearchIndexSource searchIndexSource : m_searchManager.getSearchIndexSources().values()) {
        // add <indexsource> element(s)
        Element indexsourceElement = indexsourcesElement.addElement(N_INDEXSOURCE);
        // add <name> element
        indexsourceElement.addElement(N_NAME).addText(searchIndexSource.getName());
        // add <indexer class=""> element
        Element indexerElement = indexsourceElement.addElement(N_INDEXER).addAttribute(N_CLASS, searchIndexSource.getIndexerClassName());
        for (Entry<String, String> entry : searchIndexSource.getParams().entrySet()) {
            // add <param name=""> element(s)
            indexerElement.addElement(I_CmsXmlConfiguration.N_PARAM).addAttribute(I_CmsXmlConfiguration.A_NAME, entry.getKey()).addText(entry.getValue());
        }
        // add <resources> element
        Element resourcesElement = indexsourceElement.addElement(N_RESOURCES);
        Iterator<String> resourceIterator = searchIndexSource.getResourcesNames().iterator();
        while (resourceIterator.hasNext()) {
            // add <resource> element(s)
            resourcesElement.addElement(N_RESOURCE).addText(resourceIterator.next());
        }
        // add <documenttypes-indexed> element
        Element doctypes_indexedElement = indexsourceElement.addElement(N_DOCUMENTTYPES_INDEXED);
        Iterator<String> doctypesIterator = searchIndexSource.getDocumentTypes().iterator();
        while (doctypesIterator.hasNext()) {
            // add <name> element(s)
            doctypes_indexedElement.addElement(N_NAME).addText(doctypesIterator.next());
        }
    }
    // </indexsources>
    // <fieldconfigurations>
    Element fieldConfigurationsElement = searchElement.addElement(N_FIELDCONFIGURATIONS);
    for (I_CmsSearchFieldConfiguration fieldConfiguration : m_searchManager.getFieldConfigurations()) {
        Element fieldConfigurationElement = fieldConfigurationsElement.addElement(N_FIELDCONFIGURATION);
        // add class attribute (if required)
        if (!fieldConfiguration.getClass().equals(CmsLuceneFieldConfiguration.class)) {
            fieldConfigurationElement.addAttribute(A_CLASS, fieldConfiguration.getClass().getName());
        }
        fieldConfigurationElement.addElement(N_NAME).setText(fieldConfiguration.getName());
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(fieldConfiguration.getDescription())) {
            fieldConfigurationElement.addElement(N_DESCRIPTION).setText(fieldConfiguration.getDescription());
        }
        // search fields
        Element fieldsElement = fieldConfigurationElement.addElement(N_FIELDS);
        for (CmsSearchField sfield : fieldConfiguration.getFields()) {
            if (sfield instanceof CmsLuceneField) {
                CmsLuceneField field = (CmsLuceneField) sfield;
                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, CmsLuceneField.STR_COMPRESS);
                } else {
                    fieldElement.addAttribute(A_STORE, String.valueOf(field.isStored()));
                }
                String index;
                if (field.isIndexed()) {
                    if (field.isTokenizedAndIndexed()) {
                        // index and tokenized
                        index = CmsStringUtil.TRUE;
                    } else {
                        // indexed but not tokenized
                        index = CmsLuceneField.STR_UN_TOKENIZED;
                    }
                } else {
                    // not indexed at all
                    index = CmsStringUtil.FALSE;
                }
                fieldElement.addAttribute(A_INDEX, index);
                if (field.isInExcerptAndStored()) {
                    fieldElement.addAttribute(A_EXCERPT, String.valueOf(true));
                }
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(field.getDefaultValue())) {
                    fieldElement.addAttribute(A_DEFAULT, field.getDefaultValue());
                }
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(field.getType())) {
                    fieldElement.addAttribute(A_TYPE, field.getType());
                }
                if (field.getAnalyzer() != null) {
                    String className = field.getAnalyzer().getClass().getName();
                    if (className.startsWith(CmsSearchManager.LUCENE_ANALYZER)) {
                        className = className.substring(CmsSearchManager.LUCENE_ANALYZER.length());
                    }
                    fieldElement.addAttribute(A_ANALYZER, className);
                }
                // field mappings
                for (I_CmsSearchFieldMapping mapping : field.getMappings()) {
                    Element mappingElement = fieldElement.addElement(N_MAPPING);
                    mappingElement.addAttribute(A_TYPE, mapping.getType().toString());
                    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(mapping.getDefaultValue())) {
                        mappingElement.addAttribute(A_DEFAULT, mapping.getDefaultValue());
                    }
                    // add class attribute (if required)
                    if (!mapping.getClass().equals(CmsSearchFieldMapping.class) || (mapping.getType() == CmsSearchFieldMappingType.DYNAMIC)) {
                        mappingElement.addAttribute(A_CLASS, mapping.getClass().getName());
                    }
                    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(mapping.getParam())) {
                        mappingElement.setText(mapping.getParam());
                    }
                }
            }
        }
    }
    return searchElement;
}
Also used : Locale(java.util.Locale) CmsSolrConfiguration(org.opencms.search.solr.CmsSolrConfiguration) I_CmsSearchIndex(org.opencms.search.I_CmsSearchIndex) Element(org.dom4j.Element) CmsSearchManager(org.opencms.search.CmsSearchManager) CmsSearchDocumentType(org.opencms.search.CmsSearchDocumentType) ArrayList(java.util.ArrayList) CmsSearchField(org.opencms.search.fields.CmsSearchField) I_CmsSearchIndex(org.opencms.search.I_CmsSearchIndex) CmsSearchIndex(org.opencms.search.CmsSearchIndex) CmsLuceneFieldConfiguration(org.opencms.search.fields.CmsLuceneFieldConfiguration) I_CmsSearchFieldConfiguration(org.opencms.search.fields.I_CmsSearchFieldConfiguration) I_CmsSearchFieldMapping(org.opencms.search.fields.I_CmsSearchFieldMapping) CmsSearchAnalyzer(org.opencms.search.CmsSearchAnalyzer) CmsLuceneField(org.opencms.search.fields.CmsLuceneField) CmsSearchIndexSource(org.opencms.search.CmsSearchIndexSource)

Example 2 with I_CmsSearchIndex

use of org.opencms.search.I_CmsSearchIndex in project opencms-core by alkacon.

the class CmsSearchDialog method createDialogHtml.

/**
 * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
 *
 * This overwrites the method from the super class to create a layout variation for the widgets.<p>
 *
 * @param dialog the dialog (page) to get the HTML for
 * @return the dialog HTML for all defined widgets of the named dialog (page)
 */
@Override
protected String createDialogHtml(String dialog) {
    // check if the configured search index exists
    I_CmsSearchIndex index = getIndex();
    if (index == null) {
        throw new CmsIllegalStateException(Messages.get().container(Messages.ERR_INDEX_INVALID_1, getSettings().getUserSettings().getWorkplaceSearchIndexName()));
    }
    StringBuffer result = new StringBuffer(1024);
    // create widget table
    result.append(createWidgetTableStart());
    // show error header once if there were validation errors
    result.append(createWidgetErrorHeader());
    if (dialog.equals(PAGES[0])) {
        // content
        result.append(createWidgetBlockStart(key(Messages.GUI_SEARCH_QUERY_TITLE_0)));
        result.append(createDialogRowsHtml(0, 3));
        result.append(createWidgetBlockEnd());
        // fields for limiting time ranges
        // result.append(createWidgetBlockStart(key(Messages.GUI_SEARCH_TIME_RANGES_0)));
        // result.append(createDialogRowsHtml(4, 7));
        // result.append(createWidgetBlockEnd());
        result.append(createWidgetBlockStart(key(Messages.GUI_SEARCH_FIELDS_TITLE_0)));
        result.append(createDialogRowsHtml(8, 8));
        result.append(createWidgetBlockEnd());
    }
    // close widget table
    result.append(createWidgetTableEnd());
    return result.toString();
}
Also used : I_CmsSearchIndex(org.opencms.search.I_CmsSearchIndex) CmsIllegalStateException(org.opencms.main.CmsIllegalStateException)

Example 3 with I_CmsSearchIndex

use of org.opencms.search.I_CmsSearchIndex in project opencms-core by alkacon.

the class TestPlainQuerySearchConfigurationParser method suite.

/**
 * Test suite for this test class.<p>
 *
 * @return the test suite
 */
public static Test suite() {
    OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
    TestSuite suite = new TestSuite();
    suite.addTest(new TestPlainQuerySearchConfigurationParser("testSpecialParamExtraction"));
    TestSetup wrapper = new TestSetup(suite) {

        @Override
        protected void setUp() {
            setupOpenCms("simpletest", "/", "/../org/opencms/search/solr");
            // disable all lucene indexes
            for (String indexName : OpenCms.getSearchManager().getIndexNames()) {
                if (!indexName.equalsIgnoreCase(CmsSolrIndex.DEFAULT_INDEX_NAME_ONLINE)) {
                    I_CmsSearchIndex index = OpenCms.getSearchManager().getIndex(indexName);
                    if (index != null) {
                        index.setEnabled(false);
                    }
                }
            }
        }

        @Override
        protected void tearDown() {
            removeOpenCms();
        }
    };
    return wrapper;
}
Also used : TestSetup(junit.extensions.TestSetup) I_CmsSearchIndex(org.opencms.search.I_CmsSearchIndex) TestSuite(junit.framework.TestSuite)

Example 4 with I_CmsSearchIndex

use of org.opencms.search.I_CmsSearchIndex in project opencms-core by alkacon.

the class TestSearchStateParameters method suite.

/**
 * Test suite for this test class.<p>
 *
 * @return the test suite
 */
public static Test suite() {
    OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
    TestSuite suite = new TestSuite();
    suite.addTest(new TestSearchStateParameters("testCheckAndUncheckFacetItems"));
    suite.addTest(new TestSearchStateParameters("testAddRemoveAdditionalParam"));
    TestSetup wrapper = new TestSetup(suite) {

        @Override
        protected void setUp() {
            setupOpenCms("simpletest", "/", "/../org/opencms/search/solr");
            // disable all lucene indexes
            for (String indexName : OpenCms.getSearchManager().getIndexNames()) {
                if (!indexName.equalsIgnoreCase(CmsSolrIndex.DEFAULT_INDEX_NAME_ONLINE)) {
                    I_CmsSearchIndex index = OpenCms.getSearchManager().getIndex(indexName);
                    if (index != null) {
                        index.setEnabled(false);
                    }
                }
            }
        }

        @Override
        protected void tearDown() {
            removeOpenCms();
        }
    };
    return wrapper;
}
Also used : TestSetup(junit.extensions.TestSetup) I_CmsSearchIndex(org.opencms.search.I_CmsSearchIndex) TestSuite(junit.framework.TestSuite)

Example 5 with I_CmsSearchIndex

use of org.opencms.search.I_CmsSearchIndex in project opencms-core by alkacon.

the class CmsSearchIndexTable method loadTable.

/**
 * (Re)loads the table.<p>
 */
public void loadTable() {
    m_container.removeAllItems();
    List<I_CmsSearchIndex> indexes = m_manager.getAllElements();
    for (I_CmsSearchIndex index : indexes) {
        if (index.isEnabled()) {
            Item item = m_container.addItem(index);
            item.getItemProperty(TableProperty.Name).setValue(index.getName());
            item.getItemProperty(TableProperty.FieldConfig).setValue(index.getFieldConfiguration().getName());
            item.getItemProperty(TableProperty.Locale).setValue(index.getLocale().getDisplayName());
            item.getItemProperty(TableProperty.Project).setValue(index.getProject());
            item.getItemProperty(TableProperty.Rebuild).setValue(index.getRebuildMode());
        }
    }
}
Also used : Item(com.vaadin.v7.data.Item) I_CmsSearchIndex(org.opencms.search.I_CmsSearchIndex)

Aggregations

I_CmsSearchIndex (org.opencms.search.I_CmsSearchIndex)29 TestSetup (junit.extensions.TestSetup)8 TestSuite (junit.framework.TestSuite)8 CmsSearchManager (org.opencms.search.CmsSearchManager)8 CmsSearchIndexSource (org.opencms.search.CmsSearchIndexSource)6 CmsListItem (org.opencms.workplace.list.CmsListItem)5 ArrayList (java.util.ArrayList)4 CmsSearchException (org.opencms.search.CmsSearchException)4 CmsLuceneField (org.opencms.search.fields.CmsLuceneField)4 CmsSearchField (org.opencms.search.fields.CmsSearchField)4 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Locale (java.util.Locale)2 Map (java.util.Map)2 CmsIllegalStateException (org.opencms.main.CmsIllegalStateException)2 CmsSearchIndex (org.opencms.search.CmsSearchIndex)2 I_CmsSearchFieldConfiguration (org.opencms.search.fields.I_CmsSearchFieldConfiguration)2 I_CmsSearchFieldMapping (org.opencms.search.fields.I_CmsSearchFieldMapping)2 Item (com.vaadin.v7.data.Item)1 Set (java.util.Set)1