Hi,
I've managed to get the articles behaving correctly by going to the catalog_tool in the ZMI, selecting all indexes and clicking reindex. There must be a way of doing this programmatically but I can't find it in the Plone source. I'd much prefer to have my code index each object correctly on creation. Please can someone give me a clue?
thanks
Anthony
AnthonyG wrote:
> Hi,
>
> I've been struggling away at creating a script to import a load of data in
> txt files as news articles. Finally I'm almost there but am facing issues
> with search and collections which I assume are due to the fact that I
> haven't add the items to the catalog correctly. I'm running my script using
>
> bin/instance run myscript.py
>
> All the news items get created. I have a collection set up to only show
> items with an effective date before now. My items have their effective date
> set in the future but they still appear. If I edit an individual item
> through the web then its effective date is then picked up correctly and it
> isn't shown in the collection. Also text in the body of the news article
> isn't being found when I search.
>
> I am calling reindexObject().
>
> Any help would be very much appreciated. The code is below
>
> thanks
>
> Anthony
>
> plone_id = import_folder.invokeFactory(
> type_name = 'News Item',
> id = self.generate_unique_id(used_ids, id, news_article.title,
> import_folder))
> new_item = getattr(import_folder, plone_id)
> new_item.setTitle(news_article.title)
> new_item.setText(self.build_conversation_xhtml(news_article.conversation,
> getSiteEncoding(portal)))
> new_item.setEffectiveDate(correct_day)
> try:
> image_file = open(news_article.relative_image_path, 'rb')
> new_item.getField('image').set(new_item, image_file.read(),
> mimetype='image/jpeg')
> finally:
> image_file.close()
>
> workflowTool.doActionFor(new_item, 'submit-for-publication')
> workflowTool.doActionFor(new_item, 'publish')
> transaction.commit()
> new_item.indexObject()
------------------------------------------------------------------------------
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users