Message Boards

Indexing Entity without storing to DB

Nishith Lakhlani, modified 2 Years ago.

Indexing Entity without storing to DB

New Member Posts: 4 Join Date: 7/5/21 Recent Posts

Can we achieve indexing for a custom entity without storing in to the DB?

thumbnail
Olaf Kock, modified 2 Years ago.

RE: Indexing Entity without storing to DB

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts

Yes, of course you can. The framework does not care where you get the data (that you display) from.

Nishith Lakhlani, modified 2 Years ago.

RE: RE: Indexing Entity without storing to DB

New Member Posts: 4 Join Date: 7/5/21 Recent Posts

I am looking for solution for DXP 7.0
I have used liferay sample guestbook entry entity for POC.
I want to save entity to search index but not store in database.
So in the EntrylocalServiceImpl ,I have removed the line

entryPersistence.update(entry);

I have replace it with following code:

Indexer<Entry> indexer = IndexerRegistryUtil.nullSafeGetIndexer(Entry.class);
indexer.reindex(entry);

but it doesnt trigger index and the doReindex method of the EntryIndexer class is not getting invoked.
Any alternative to achieve this?

thumbnail
Russell Bohl, modified 2 Years ago.

RE: RE: Indexing Entity without storing to DB

Expert Posts: 291 Join Date: 2/13/13 Recent Posts

Nishith, did you test the sample? Is search and indexing working before you change anything?

Nishith Lakhlani, modified 2 Years ago.

RE: RE: Indexing Entity without storing to DB

New Member Posts: 4 Join Date: 7/5/21 Recent Posts

@Russel
Yes. If I add the 

entryPersistence.update(entry);

The entry gets indexed. Once I remove that line. It does not index.

thumbnail
Russell Bohl, modified 2 Years ago.

RE: RE: Indexing Entity without storing to DB

Expert Posts: 291 Join Date: 2/13/13 Recent Posts

Okay, your indexing code looks fine to me, and search and indexing is working as expected using the usual mechanism. I think one easy thing you should try is removing the @Indexable annotation from the method. I don't know all that this does, but it's probably kicking off an indexing action (delete or reindex) whenever a persistence call is made. I don't know why it would get in the way of your manual indexing code, but it might be a feature of the annotation (sanitize any other indexing calls that might interfere, or something). I'm on a limb with these guesses, but removing teh annotation is probably worth a shot, if you haven't already.

Nishith Lakhlani, modified 2 Years ago.

RE: RE: Indexing Entity without storing to DB

New Member Posts: 4 Join Date: 7/5/21 Recent Posts

@Russel
I have already tried removing the annotation. It DOES NOT help.

thumbnail
Russell Bohl, modified 2 Years ago.

RE: Indexing Entity without storing to DB

Expert Posts: 291 Join Date: 2/13/13 Recent Posts

Now that I come back to this Nishith, I'm going to conclude that you cannot do this on Liferay 7.0. I believe it was Liferay 7.2 that introduced the idea of applications using their own index as their primary storage. But you would not be doing this in a SB app.

Some of the DXP apps that use it are Synonym Sets and Result Rankings.

This ticket for documentation has some code snipopets (they look like they're for 7.2).

https://issues.liferay.com/browse/LRDOCS-7653