4

I'm writing a custom indexer for SI4T - I've captured a package representing the publish of a page from Tridion and am using it locally to test against my Deployer set-up in Eclipse.

My local Deployer is publishing to the same Broker db (using the SI4T JPASearchDAOFactory) as our DEV env where we setup the SI4T TBBs.

My problem is that even though I've unpublished my test page and I can see its removal from Broker before each test run, every time I drag/drop the test package into my local incoming folder, SI4T always treats it as an update - as my updateItemInIndex method is always triggered.

The JPASearchDAOFactory seems to set FactoryAction.UPDATE in both create and update implementations - is that correct - is the intention to treat adds and updates as the same?

It would explain why I never see my addItemToIndex called.

1 Answer 1

4

That is correct. Essentially, a Page Update is always done by the underlying JPA implementation as an JPASearchPageDAO.update, followed by a JPASearchPageDAO.create, so in essence both are doing the same things. This has got me stuck quite a while when I was building this as well.

If you want to change that behaviour because you have to do extra stuff while creating pages, you could do something like this:

@Component("JPASearchPageDAO")
@Scope("prototype")
public class JPASearchPageDAO extends JPAPageDAO implements PageDAO
{
    private String storageId;
    // Let's keep track of this DAO
    private boolean isUpdating = false;

    public void create(CharacterData page, String relativePath) throws StorageException
    {
        FactoryAction action = FactoryAction.CREATE

        if (!this.isUpdating)
        {
            /**
             * Do creation specific stuff here, or in the Factory, since we've now set
             * the action to CREATE.
             */ 


        }
        else
        {
            action = FactoryAction.UPDATE
        }

        log.debug("Create.");
        TridionPublishableItemProcessor tp;
        try
        {
            tp = new TridionPublishableItemProcessor(
                    page.getString(),
                    action,
                    IndexType.PAGE,
                    Integer.toString(page.getPublicationId()),
                    "tcm:" + page.getPublicationId() +"-" + page.getId() + "-64"
                    , this.storageId);
            CharacterData c = tp.processPageSource(page);
            if (c != null)
            {
                super.create(c, relativePath);
            }
            else
            {
                log.error("Error processing page: " + relativePath + ", proceeding with deployment of original page");
                super.create(page, relativePath);
            }
        }
        catch (IOException e)
        {
            log.error(Utils.stacktraceToString(e.getStackTrace()));
            throw new StorageException("IO Exception: " + e.getLocalizedMessage(),e);
        }
    }


    // Note: An update triggers a create always.
    @Override
    public void update(CharacterData page, String originalRelativePath, String newRelativePath) throws StorageException
    {
        this.isUpdating = true;

        // ... 
    }
}

Now that I think of it, I'll add this fix in the next release of SI4T as well. :)

1
  • Thanks Raimond. My point was more that the SI4T documentation should probably be updated to highlight that the current implementation won't trigger addItemToIndex even though its a part of the "documented" interface.
    – Neil
    Aug 18, 2014 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.