1

I've been looking for an answer to this issue I have with an array but so far no answer here nor the web.

We have a TYPO3 website that has indexed search configured and installed. We crawl records (~60000) using the crawler extension. Everything was configured and running fine but we saw that some records were not appearing on the search results.

I debugged the TYPO3 code and found that some words were not related to its records in the index_rel table.

What I found is that when the running code enters the method indexTypo3PageContent() on line 573 the method checkWordList() is called with the array of words passed as an argument. Inside the method there is an unset of some array values. This is where something is wrong because if I am right the array is passed by value, however the array outside the method checkWordList() is changed, there are less words. Therefore some words will not be reverse indexed to its record.

I can change the code. It is very easy. However I want to understand the problem. Is it a PHP bug? Aren't PHP arrays passed by value? I am using PHP 5.5 on Ubuntu.

If anyone can giving a hint of what's happening I will appreciate very much.

Anyway I am posting a bug on TYPO3 bug system.

Bests,

B.

  • 1
    It has been answered here already http://stackoverflow.com/questions/2030906/are-arrays-in-php-passed-by-value-or-by-reference – Rohit Gupta Apr 25 '15 at 23:36
  • Rohit thank you very much for your answer. I guess then I found a bug in PHP because according to the answers on that page an array is passed by value when it is modified inside the function. However something must be happening when PHP parses the file I indicated in my question. Maybe it is because the unset is inside control structures. I tried code like this before posting: `'5']; x($a); print_r($a); ?>` It works like expected. That file does not. – Braulio J. Solano Apr 26 '15 at 02:27
  • Where did you check the array outside? The `checkWordList` method is just for inserting the words into a separate table which is then referenced to from the index table. As the parameters are not passed by reference there is no chance of the modification you spoke about. I can not reproduce the issue you are describing. – Michael May 02 '15 at 08:30
  • @Michael, I will post an answer. I am sorry. It was in the night. I was tired and I was checking the debugging information by eye. I actually found the problem, will describe it in the answer. Bests. ;-) – Braulio J. Solano May 03 '15 at 20:01

1 Answers1

0

Arrays are passed by value indeed (or as some have pointed by reference if they are not modified in the function or method, see the Rohit comment above).

I thought the arrays were different but were not. It was just fatigue. Debugging in late hours is not productive.

Anyway, I found the problem after digging more into the code. I am using a TYPO3 4 LTS version of indexed_search.

The method indexAnalyze of the indexer calls two other methods: analyzeHeaderInfo and analyzeBody. Both methods are almost identical except that analyzeHeaderInfo does not set first (first occurrence) which is actually an array index. Then in the method submitWords, when the query is made with an unset first, MySQL complains about first being NULL. Therefore the insertion is not made. This does not happen on newer version because of code cleansing. As one can see in the provided link to the code, there is a type cast to int, therefore if first is unset it will be zero and not null. One could still discuss about the semantic of every metadata having first ocurrence equal to zero but that's another story.

Hope this could help someone using and old indexed_search of TYPO3. ;-)