Message Boards

Indexing a JournalArticle after creating it programmatically

thumbnail
David Yari Podio Casares, modified 6 Years ago.

Indexing a JournalArticle after creating it programmatically

Junior Member Posts: 36 Join Date: 3/24/11 Recent Posts
Hi,

I have developed some code that creates a new JournalArticle and populates it succesfully with data according to its structure.
I'm using Liferay 7.

To create the Article I use the method

com.liferay.journal.service.JournalArticleLocalService.addArticle()


The article is succesfully created, it's state is approved, and I can see all the values correctly if I edit the article with the Liferay interface.
The problem is that I have another portlet which searchs for that kind of articles using :


Indexer<journalarticle> indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class);
indexer.search(...)
</journalarticle>


..., and the new article doesn't appear as a result.
If I re-publish the article using the Liferay interface (without changing anything), then it appears correctly. So, I suspect the new article is not getting indexed.
I tried to add this just after the call to "addArticle(...)" but it doesn't seems to do anything:


Indexer<journalarticle> indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class);
indexer.reindex(article);
</journalarticle>


Does someone know what I can do to re-index the article just after adding it or updating its contents?
Or at least point me to where is the code Liferay uses to publish and index the articles created with its interface?

Thank you!
thumbnail
David Yari Podio Casares, modified 6 Years ago.

RE: Indexing a JournalArticle after creating it programmatically (Answer)

Junior Member Posts: 36 Join Date: 3/24/11 Recent Posts
The problem is solved.

I was just re-indexing before adding some categories to the article that were necessary for it to appear in the search.
If I do the re-indexing after adding the categories it works fine.

Sorry to bother you and thank you!
ronak vora, modified 3 Years ago.

RE: Indexing a JournalArticle after creating it programmatically

Junior Member Posts: 25 Join Date: 9/26/18 Recent Posts
  Indexer<JournalArticle> indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class);  
indexer.reindex(article);

can we do same as for Documents (with document's content)?
  Indexer<DLFileEntry> indexer ​​​​​​​ = IndexerRegistryUtil.getIndexer(DLFileEntry.class);  
indexer.reindex(dLFileEntry);

thumbnail
Jorge Diaz, modified 3 Years ago.

RE: Indexing a JournalArticle after creating it programmatically

Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts
Hi Ronak,

Yes, you should be able to do that, it is the same pattern for all Liferay entities.
Regards
ronak vora, modified 3 Years ago.

RE: Indexing a JournalArticle after creating it programmatically

Junior Member Posts: 25 Join Date: 9/26/18 Recent Posts
Hi Jorge Diaz,

Thanks for Reply and tested but  it seems didn't worked and can't search DLFileEntry (File content at all) and need to ReIndex  10,000+ documents
- When tries with using control panel(Control Panel > Server Administration > Resources > "Reindex Search" button)
1. Takes too much time.
2. Stops server at all.

If there is any other solution for ReIndexing Programatically for Uploaded Document.

Thanks In advance
thumbnail
Jorge Diaz, modified 3 Years ago.

RE: Indexing a JournalArticle after creating it programmatically

Liferay Master Posts: 753 Join Date: 1/9/14 Recent Posts
Hi Ronak,

Do you have any kind of error in your log files when you try to reindex from control panel?
If you have problems reindexing, you can also try my Index Checker app, see:
  - https://web.liferay.com/marketplace/-/mp/application/70121999
That tool allows you to check which documents are missing and reindex only them.
You can also execute a partial reindex, for example, reindex only one site.
Regards,
Jorge