[opencms-dev] Misleading behaviour on linked resources and SOLR

Rüdiger Kurz r.kurz at alkacon.com
Tue Jul 16 11:35:53 CEST 2013


Hi,

I've written the attached test case and this works fine.

What is does is:
1. Creating a folder
2. Creating a resource (brother)
3. Creating a sibling of this resource (sister)
4. Modify the content of the brother
5. Publish the modification
6. Check if the the two siblings are found by a query that contains the 
new content
7. Check if the document field content equals the new content
8. Check if the content of brother and sister are the same
9. Check if the old content has been gone
10. Checks if the DB content in the online project is equal

So far I think this works as expected. If you can add any details I've 
missed, please let us know.

greetings
Rüdiger

Am 10.07.2013 18:00, schrieb Rüdiger Kurz:
> Hi Carsten,
>
> if I understood you correctly you're talking about siblings. It can be
> that there is an indexing issue when changing / publishing a sibling
> without its brothers and sisters.
>
> First of all I will write a test case to verify if your assumptions (1
> and 2) are true. If this will be the case this is fact a bug as you said
> in (3) and I will create a git issue.
>
> I don't think that it is possible to check the checkbox by default by
> configuration, but I might be wrong, please feel free to correct me.
>
> cheers
> Rüdiger
>
> Am 10.07.2013 17:01, schrieb Carsten Wilhelm:
>> Dear all,
>>
>> We have encountered some interesting behaviour on our website.
>>
>> What we do:
>>
>> ·we create content in one folder and link it in another folder
>>
>> ·on one page we use a SOLR query with parent folder for the first folder
>>
>> ·on another page we use a SOLR query for the same type, but the second
>> folder
>>
>> So far, everything works like a charm.
>>
>> When we edit the content, the content gets changed in both folders
>> (since it’s linked content, of course).
>>
>> But: when we publish the file directly, there appeares a checkbox
>> „publish all links“ (or similar, we’re using the german locale in the
>> backend) which is unchecked.
>>
>> Publishing with checking this box results in both pages displaying the
>> correct new content.
>>
>> Publishing without checking this box results in two different outputs -
>> the page using the folder, where we have published the content is OK,
>> the other shows the old content.
>>
>> After publishing, there is no way to publish the other version in the
>> other folder - from the explorer point of view it seems that this
>> content has been published (which isn’t the case).
>>
>> Some questions arise in my mind:
>>
>> 1)It seems that the content is stored in a single instance in the
>> database, but multiple in the SOLR index
>>
>> 2)Furthermore publishing only some of the linked versions result in
>> changing only some of the SOLR entries
>>
>> 3)Is this expected behaviour or is this a bug I need to add in the issue
>> tracker?
>>
>> A workaround for that could be to check the checkbox by default - can I
>> configure this in OpenCms somewhere?
>>
>> Kind regards,
>>
>> Carsten
>

-- 
Kind Regards,
Rüdiger.

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

Rüdiger Kurz

Alkacon Software GmbH  - The OpenCms Experts
http://www.alkacon.com - http://www.opencms.org
-------------- next part --------------
/*
 * File   : $Source$
 * Date   : $Date$
 * Version: $Revision$
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (C) 2002 - 2009 Alkacon Software (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.search.solr;

import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.types.CmsResourceTypeFolder;
import org.opencms.file.types.CmsResourceTypePlain;
import org.opencms.main.CmsContextInfo;
import org.opencms.main.OpenCms;
import org.opencms.report.CmsShellReport;
import org.opencms.search.CmsSearchIndex;
import org.opencms.search.CmsSearchResource;
import org.opencms.search.documents.CmsExtractionResultCache;
import org.opencms.search.documents.I_CmsDocumentFactory;
import org.opencms.search.extractors.CmsExtractionResult;
import org.opencms.test.OpenCmsTestCase;
import org.opencms.test.OpenCmsTestProperties;
import org.opencms.util.CmsFileUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;

import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;

/**
 * Tests the Solr configuration.<p>
 * 
 * @since 9.x
 */
public class TestSolrConfiguration extends OpenCmsTestCase {

    /**
     * Default JUnit constructor.<p>
     * 
     * @param arg0 JUnit parameters
     */
    public TestSolrConfiguration(String arg0) {

        super(arg0);
    }

    /**
     * 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.setName(TestSolrConfiguration.class.getName());
        suite.addTest(new TestSolrConfiguration("testReindexPublishedSiblings"));


        TestSetup wrapper = new TestSetup(suite) {

            @Override
            protected void setUp() {

                setupOpenCms("solrtest", "", "/../org/opencms/search/solr");
                // disable all lucene indexes
                for (String indexName : OpenCms.getSearchManager().getIndexNames()) {
                    if (!indexName.equalsIgnoreCase(AllTests.SOLR_ONLINE)) {
                        CmsSearchIndex index = OpenCms.getSearchManager().getIndex(indexName);
                        if (index != null) {
                            index.setEnabled(false);
                        }
                    }
                }
            }

            @Override
            protected void tearDown() {

                removeOpenCms();
            }
        };

        return wrapper;
    }

    /**
     * Test result count for changed content of two siblings.<p>
     * 
     * @throws Throwable if something goes wrong
     */
    public void testReindexPublishedSiblings() throws Throwable {

        echo("Test result count for changed content of two siblings");
        CmsObject cms = getCmsObject();

        // create a folder with two siblings and publish them together
        String folder = "/reindexPublishedSiblings/";
        cms.createResource(folder, CmsResourceTypeFolder.getStaticTypeId());
        String brother = folder + "test_brother.txt";
        CmsProperty firstTitleProperty = new CmsProperty(
            CmsPropertyDefinition.PROPERTY_TITLE,
            "BROTHER AND SISTER",
            null);
        List<CmsProperty> props = new ArrayList<CmsProperty>();
        props.add(firstTitleProperty);
        CmsResource resource = cms.createResource(
            brother,
            CmsResourceTypePlain.getStaticTypeId(),
            "Solr Enterprise Serach".getBytes(),
            props);
        String sister = folder + "test_sister.txt";
        cms.createSibling(brother, sister, props);
        OpenCms.getPublishManager().publishResource(cms, folder);
        OpenCms.getPublishManager().waitWhileRunning();

        // modify and publish only the source
        CmsFile file = cms.readFile(resource);
        file.setContents("OpenCms Enterprise Content Management System".getBytes());
        cms.lockResource(file);
        cms.writeFile(file);
        OpenCms.getPublishManager().publishResource(cms, brother, false, null);
        OpenCms.getPublishManager().waitWhileRunning();

        // create a query matching the new content
        CmsSolrQuery query = new CmsSolrQuery(getCmsObject(), null);
        query.setQuery("\"OpenCms Enterprise Content Management System\"");
        List<Locale> locles = Collections.emptyList();
        query.setLocales(locles);
        query.setSearchRoots("/");
        query.setRows(new Integer(10));

        // Offline and Online both siblings should be found for the new content
        CmsSolrIndex oindex = OpenCms.getSearchManager().getIndexSolr(AllTests.SOLR_ONLINE);
        CmsSolrResultList rl = oindex.search(cms, query);
        assertEquals("Both siblings must be found, they have the same content.", 2, rl.size());

        CmsSearchResource brotherDoc = rl.get(0);
        CmsSearchResource sisterDoc = rl.get(1);

        assertEquals(
            "Brother must be there",
            "/sites/default/reindexPublishedSiblings/test_brother.txt",
            brotherDoc.getRootPath());
        assertEquals(
            "Sister must be there",
            "/sites/default/reindexPublishedSiblings/test_sister.txt",
            sisterDoc.getRootPath());

        assertEquals(
            "The content must be",
            "OpenCms Enterprise Content Management System",
            brotherDoc.getField("content"));

        assertEquals(
            "The content of the found documents must be equal",
            brotherDoc.getField("content"),
            sisterDoc.getField("content"));

        query.setQuery("\"Solr Enterprise Serach\"");
        CmsSolrResultList rl2 = oindex.search(cms, query);
        assertEquals("Old content must not be found anymore", 0, rl2.size());

        cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
        String sisterContent = new String(cms.readFile(sister).getContents());
        String brotherContent = new String(cms.readFile(brother).getContents());
        assertEquals(
            "Sister and brother must have the same content in the online project",
            sisterContent,
            brotherContent);
    }
}


More information about the opencms-dev mailing list