掲示板

Lucene synchronous reindex - SOLVED

thumbnail
10年前 に Marco Rosetti によって更新されました。

Lucene synchronous reindex - SOLVED

Junior Member 投稿: 68 参加年月日: 13/03/06 最新の投稿
Is there a way to make lucene document reindex synchronous?

As far as I know reindex is exectuted on a separated thread but that leads me to inconsistency on front-end views. What I'm trying to achieve is a way to wait for completion before refreshing the page.

Thanks in advance,
Marco
thumbnail
10年前 に David H Nebinger によって更新されました。

RE: Lucene synchronous reindex

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
You're not supposed to be reindexing when users are in. AFAIK reindex is only done from the control panel and should only be done when you have been manually mucking w/ the data outside of the Liferay API.
thumbnail
10年前 に Marco Rosetti によって更新されました。

RE: Lucene synchronous reindex

Junior Member 投稿: 68 参加年月日: 13/03/06 最新の投稿
Thanks David for the quick reply but I think I left too many consideration unwritten, let me explain more in detail:

I have a custom entity (say Student) with a custom indexer. When I update a Student (using Service Builder methods) reindex of that Student takes 2-3 seconds and if I reload that Student from indexes without waiting enought I get the old version.
I am looking for something that could wait for indexing process to complete before setting the entire update process is complete.
thumbnail
10年前 に David H Nebinger によって更新されました。

RE: Lucene synchronous reindex

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
adding a document to lucene does not require a reindex. Just add the document and be done with it.

Reindexing is only needed when the state of your index and the data sink are out of sync with each other; it's not something you do after every add.
thumbnail
10年前 に Marco Rosetti によって更新されました。

RE: Lucene synchronous reindex

Junior Member 投稿: 68 参加年月日: 13/03/06 最新の投稿
When I update fields on my entity I need to propagate those changes to indexes. To do so I call doReindex(Object obj) on my custom indexer but this reindex operation (that's only async AFAIK) takes at least 2-3 seconds. I'm looking for something that makes me wait this operation to complete before returning the control.
Is that the right way to play with lucene indexes? Am I doing something wrong?

Thanks
thumbnail
10年前 に Juan Gonzalez によって更新されました。

RE: Lucene synchronous reindex

Liferay Legend 投稿: 3089 参加年月日: 08/10/28 最新の投稿
Hi Marco,

I don't understand why do you need indexes for displaying information. Are you using services for your entities using service builder?
thumbnail
10年前 に Marco Rosetti によって更新されました。

RE: Lucene synchronous reindex

Junior Member 投稿: 68 参加年月日: 13/03/06 最新の投稿
Juan Gonzalez:
Hi Marco,

I don't understand why do you need indexes for displaying information. Are you using services for your entities using service builder?


Hi Juan,
services for my custom entities are built with service builder.
I need to do lot of searches on my custom entities (expecially on strings, using "like" patterns) so I decided to use Lucene to speed up operations
thumbnail
10年前 に David H Nebinger によって更新されました。

RE: Lucene synchronous reindex

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Marco Rosetti:
When I update fields on my entity I need to propagate those changes to indexes. To do so I call doReindex(Object obj) on my custom indexer but this reindex operation (that's only async AFAIK) takes at least 2-3 seconds. I'm looking for something that makes me wait this operation to complete before returning the control.
Is that the right way to play with lucene indexes? Am I doing something wrong?


Um, no. You shouldn't be reindexing, you should be updating the document. I'm not sure what interface you're doing to access the index, but instead of the doReindex() method, look for something that is related to updating...
thumbnail
10年前 に Marco Rosetti によって更新されました。

RE: Lucene synchronous reindex

Junior Member 投稿: 68 参加年月日: 13/03/06 最新の投稿
David H Nebinger:
Marco Rosetti:
When I update fields on my entity I need to propagate those changes to indexes. To do so I call doReindex(Object obj) on my custom indexer but this reindex operation (that's only async AFAIK) takes at least 2-3 seconds. I'm looking for something that makes me wait this operation to complete before returning the control.
Is that the right way to play with lucene indexes? Am I doing something wrong?


Um, no. You shouldn't be reindexing, you should be updating the document. I'm not sure what interface you're doing to access the index, but instead of the doReindex() method, look for something that is related to updating...


My indexer extends com.liferay.portal.kernel.search.BaseIndexer (as UserIndexer do, for example) and calls SearchEngineUtil.updateDocument(...) when reindexing a single document. Am I doing something wrong?
thumbnail
10年前 に David H Nebinger によって更新されました。

RE: Lucene synchronous reindex

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Long story short, this guy may be optimizing on each update, depending upon the value you have for the "lucene.optimize.interval". Normally this is set to 100 (to auto-optimize after 100 adds/updates). Have you tweaked it to be a different value, i.e. 0 (which optimizes after every update)?

Otherwise, you'll have to step through the code (either just by reading it or via a debugger if possible) to find out exactly when (if) it is reindexing on every write or not...
thumbnail
10年前 に Marco Rosetti によって更新されました。

RE: Lucene synchronous reindex

Junior Member 投稿: 68 参加年月日: 13/03/06 最新の投稿
David H Nebinger:
Long story short, this guy may be optimizing on each update, depending upon the value you have for the "lucene.optimize.interval". Normally this is set to 100 (to auto-optimize after 100 adds/updates). Have you tweaked it to be a different value, i.e. 0 (which optimizes after every update)?

No, I did not change lucene.optimize.interval

David H Nebinger:

Otherwise, you'll have to step through the code (either just by reading it or via a debugger if possible) to find out exactly when (if) it is reindexing on every write or not...

I directly call doReindex(Object obj) on my custom indexer, that triggers SearchEngineUtil.updateDocument(...).
thumbnail
9年前 に Marco Rosetti によって更新されました。

RE: Lucene synchronous reindex - SOLVED

Junior Member 投稿: 68 参加年月日: 13/03/06 最新の投稿
Maybe I found a solution that works for me.
Long story short, adding this line
ProxyModeThreadLocal.setForceSync(true); 

will force document indexing (triggered by a message into message bus) to be synchronous with my thread.

Is there any drawbacks in this approach?

Hope it helps,

-MR