{"id":1191,"date":"2022-08-30T15:13:54","date_gmt":"2022-08-30T15:13:54","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/notice-undefined-offset-in-my-zend-ib-search-lucene-index-segmentinfo-php-on-line-641-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:13:54","modified_gmt":"2022-08-30T15:13:54","slug":"notice-undefined-offset-in-my-zend-ib-search-lucene-index-segmentinfo-php-on-line-641-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/notice-undefined-offset-in-my-zend-ib-search-lucene-index-segmentinfo-php-on-line-641-collection-of-common-programming-errors\/","title":{"rendered":"Notice: Undefined offset: in \/my\/Zend\/ib\/Search\/Lucene\/Index\/SegmentInfo.php on line 641-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;ve a problem in indexing with Zend Search Lucene framework.<\/p>\n<p>Our file repository has ~25000 files and I&#8217;m trying to index them. But during batch indexing, this error occurred:<\/p>\n<pre>\nNotice: \nUndefined offset: 2047 in \/my\/Zend\/lib\/Search\/Lucene\/Index\/SegmentInfo.php on line 641 \nNotice: \nTrying to get property of non-object in \/my\/Zend\/lib\/Search\/Lucene\/Index\/SegmentMerger.php on line 202 \nFatal error: \nUncaught exception 'Zend_Search_Lucene_Exception' with message 'Error occured while file reading.' in \/my\/Zend\/lib\/Search\/Lucene\/Storage\/File\/Filesystem.php:174 \nStack trace: \n#0 \/my\/Zend\/lib\/Search\/Lucene\/Storage\/File.php(470): Zend_Search_Lucene_Storage_File_Filesystem-&gt;_fread(524287) \n#1 \/my\/Zend\/lib\/Search\/Lucene\/Index\/SegmentMerger.php(203): Zend_Search_Lucene_Storage_File-&gt;readBinary() \n#2 \/my\/Zend\/lib\/Search\/Lucene\/Index\/SegmentMerger.php(126): Zend_Search_Lucene_Index_SegmentMerger-&gt;_mergeStoredFields() \n#3 \/my\/Zend\/lib\/Search\/Lucene\/Index\/Writer.php(385): Zend_Search_Lucene_Index_SegmentMerger-&gt;merge() \n#4 \/my\/Zend\/lib\/Search\/Lucene\/Index\/Writer.php(341): Zend_Search_Lucene_Index_Writer-&gt;_mergeSegments(Array) \n#5 \/my\/Zend\/lib\/Search\/Lucene\/Index\/Writer.php(250): Zend_Search_Lucene_Index_Writer-&gt;_maybeMergeSegments() \n#6 \/my\/Zend\/lib\/Search\/Luc in \/my\/Zend\/lib\/Search\/Lucene\/Storage\/File\/Filesystem.php on line 174 \n<\/pre>\n<p>It occured when my program index 1000th file.<\/p>\n<p>my code is here:<\/p>\n<p>(I send fileNames through an ajax code.)<\/p>\n<pre><code>$handle = fopen('\/my\/index\/directory\/my.lock', 'w');\nif (flock($handle, LOCK_EX)){\n    $mergeFactor = 300;\n    $fileName = $_POST['fileName'];\n    $index = Zend_Search_Lucene::open($path);\n    $doc = new FileDocument($fileName,true);\n    $similarity = new Search_Similarity();\n    Zend_Search_Lucene_Search_Similarity::setDefault($similarity);\n    Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('UTF-8');\n    Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());\n    $index-&gt;setMergeFactor($mergeFactor);\n    \/\/if ($index-&gt;count() % 50 == 0){\n    \/\/  $index-&gt;optimize();\n    \/\/}\n    $index-&gt;addDocument($doc);\n    flock($handle, LOCK_UN);\n}else {\n    echo \"UNABLE To Lock!\";\n}\nfclose($handle);\n<\/code><\/pre>\n<p>My Zend Version: 1.11.11<\/p>\n<p>and when I toggle comments to optimize my index manually, this error occured in another file:<\/p>\n<pre>\nNotice: \nUndefined offset: 16383 in \/my\/Zend\/lib\/Search\/Lucene\/Index\/SegmentInfo.php on line 641 \nNotice: \nTrying to get property of non-object in \/my\/Zend\/lib\/Search\/Lucene\/Index\/SegmentMerger.php on line 202 \nFatal error: \nUncaught exception 'Zend_Search_Lucene_Exception' with message 'Error occured while file reading.' in \/my\/Zend\/lib\/Search\/Lucene\/Storage\/File\/Filesystem.php:174 \nStack trace: \n#0 \/my\/Zend\/lib\/Search\/Lucene\/Storage\/File.php(470): Zend_Search_Lucene_Storage_File_Filesystem-&gt;_fread(81919) \n#1 \/my\/Zend\/lib\/Search\/Lucene\/Index\/SegmentMerger.php(203): Zend_Search_Lucene_Storage_File-&gt;readBinary() \n#2 \/my\/Zend\/lib\/Search\/Lucene\/Index\/SegmentMerger.php(126): Zend_Search_Lucene_Index_SegmentMerger-&gt;_mergeStoredFields() \n#3 \/my\/Zend\/lib\/Search\/Lucene\/Index\/Writer.php(385): Zend_Search_Lucene_Index_SegmentMerger-&gt;merge() \n#4 \/my\/Zend\/lib\/Search\/Lucene\/Index\/Writer.php(807): Zend_Search_Lucene_Index_Writer-&gt;_mergeSegments(Array) \n#5 \/my\/Zend\/lib\/Search\/Lucene.php(1456): Zend_Search_Lucene_Index_Writer-&gt;optimize() \n#6 \/my\/Zend\/lib\/Search\/Lucene\/Proxy.php(518): Zend in \/my\/Zend\/lib\/Search\/Lucene\/Storage\/File\/Filesystem.php on line 174 \n<\/pre>\n<ol>\n<li>\n<p>What&#8217;s my problem?!<\/p>\n<\/li>\n<li>\n<p>What&#8217;s my solution?! \ud83d\ude00<\/p>\n<\/li>\n<\/ol>\n<p>Thanks. \ud83d\ude42<\/p>\n<ol>\n<li>\n<p>I have the same problem, but I have to add some lines of code in Zend Lucene, becauce couldn&#8217;t find solution. There are two checking on existing field, below:<\/p>\n<p>in file: Zend\/Search\/Lucene\/Index\/SegmentInfo.php<\/p>\n<pre><code>public function getField($fieldNum)\n{\n    if (isset($this-&gt;_fields[$fieldNum])) \/\/ add this line to check field in the fields array\n        return $this-&gt;_fields[$fieldNum];\n}\n<\/code><\/pre>\n<p>in file: Zend\/Search\/Lucene\/Index\/SegmentManager.php<\/p>\n<pre><code>private function _mergeStoredFields()\n{\n    \/\/..\n    foreach ($this-&gt;_segmentInfos as $segName =&gt; $segmentInfo) {\n        \/\/ ..\n        for ($count = 0; $count &lt; $segmentInfo-&gt;count(); $count++) {\n            \/\/ ..\n            for ($count2 = 0; $count2 &lt; $fieldCount; $count2++) {\n                \/\/ ..\n                if (!$fieldInfo)    \/\/ add this lines\n                    continue;       \/\/ to exclude empty field\n            }\n            \/\/ ..\n      }\n      \/\/ ..\n    }\n    \/\/ ..\n}\n<\/code><\/pre>\n<p>Better late than never :)))<\/p>\n<h2>UPD: hm.. unfortunately as I learn this code isn&#8217;t a solution \ud83d\ude41<\/h2>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:40:14. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve a problem in indexing with Zend Search Lucene framework. Our file repository has ~25000 files and I&#8217;m trying to index them. But during batch indexing, this error occurred: Notice: Undefined offset: 2047 in \/my\/Zend\/lib\/Search\/Lucene\/Index\/SegmentInfo.php on line 641 Notice: Trying to get property of non-object in \/my\/Zend\/lib\/Search\/Lucene\/Index\/SegmentMerger.php on line 202 Fatal error: Uncaught exception &#8216;Zend_Search_Lucene_Exception&#8217; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,8],"tags":[],"class_list":["post-1191","post","type-post","status-publish","format-standard","hentry","category-uncategorized","category-zend-framework"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1191"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1191\/revisions"}],"predecessor-version":[{"id":8899,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1191\/revisions\/8899"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}