Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EZP-28165: Incorrect increment of object_count in ezsearch_word #1319

Merged
merged 2 commits into from
Nov 21, 2017
Merged

Fix EZP-28165: Incorrect increment of object_count in ezsearch_word #1319

merged 2 commits into from
Nov 21, 2017

Conversation

gabrielfin
Copy link
Contributor

When updating object_count in ezsearch_word, eZSearchEngine splits the list of words in chunks of 500. But in every cycle of the loop not only the current chunk but all of the previous chunks are incremented. Which means that if there are, lets say 3 chunks, the first chunk gets an increment of +3, the second of +2, and the third of +1.

Steps to reproduce:

  1. Create a new object with an attribute that has (plenty) more than 500 indexable words.
  2. Pick any word that is mentioned at the beginning of that attribute.
  3. Publish the object
  4. Find that word in ezsearch_word and watch the object_count value.
  5. Edit the object created in step 1 and publish it without modifying it.
  6. Find again the word in ezsearch_word and watch the object_count value.

Result:
The object_count has a larger value than it should.

Fix:
Simply move $wordIDArray from outside the for to inside, so that it is reset on every loop. I also renamed the variable to $wordIDArrayChuck, to make it consistent with $wordArrayChuck, but that's not necessary.

@@ -185,16 +184,17 @@ function buildWordIDArray( $indexArrayOnlyWords )
// Build a has of the existing words
$wordResCount = count( $wordRes );
$existingWordArray = array();
$wordIDArrayChuck = array();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we just move init of $wordIDArray here to avoid needing to change lines below?

@gabrielfin
Copy link
Contributor Author

Done.

@andrerom
Copy link
Contributor

andrerom commented Oct 31, 2017

Thanks! Could you btw create JIRA issue for this? Affected version will be 2017.10

@gabrielfin
Copy link
Contributor Author

@gabrielfin gabrielfin changed the title Fix for incorrect increment of object_count in ezsearch_word Fix EZP-28165: Incorrect increment of object_count in ezsearch_word Oct 31, 2017
Copy link
Member

@alongosz alongosz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, seems like >=1.7 LTS is affected as well (I trusted in The Legacy Code when porting this ;)).

I'll fix it there as well once I have more time (in the new stack requires test and some naming changes as they're misleading IMHO - see $wordIDArray, $wordArray and buildWordIDArray which returns $wordArray)

@andrerom andrerom added this to the 2017.10.1 milestone Nov 21, 2017
@andrerom andrerom merged commit ee65f38 into ezsystems:master Nov 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants