1<?php 2 3namespace dokuwiki\Search\Index; 4 5/** 6 * Basic Building block to access individual index files 7 */ 8abstract class AbstractIndex 9{ 10 /** @var string name of the index */ 11 protected $idx; 12 13 /** @var string $suffix of the index */ 14 protected $suffix; 15 16 /** @var string full filename to the index */ 17 protected $filename; 18 19 /** 20 * Initialize the index 21 * 22 * The $suffix argument is for an index that is split into multiple parts. 23 * Different index files should use different base names. 24 * 25 * @param string $idx name of the index 26 * @param string $suffix subpart identifier 27 */ 28 public function __construct($idx, $suffix = '') 29 { 30 global $conf; 31 $this->filename = $conf['indexdir'] . '/' . $idx . $suffix . '.idx'; 32 $this->idx = $idx; 33 $this->suffix = $suffix; 34 } 35 36 /** 37 * @return string the full path to the underlying file 38 */ 39 public function getFilename() 40 { 41 return $this->filename; 42 } 43 44 /** 45 * Change a line in the index 46 * 47 * If the line doesn't exist, it will be added, creating empty 48 * lines inbetween as necessary 49 * 50 * @param int $rid the line number, count starting at 0 51 * @param string $value line content to write 52 */ 53 abstract public function changeRow($rid, $value); 54 55 /** 56 * Retrieve a line from the index 57 * 58 * Returns an empty string for non-existing lines 59 * 60 * @param int $rid the line number 61 * @return string a line with trailing whitespace removed 62 */ 63 abstract public function retrieveRow($rid); 64 65 /** 66 * Searches the Index for a given value and adds it if not found 67 * 68 * Entries previously marked as deleted will be restored. 69 * 70 * Note the existance of an entry in the index does not say anything about the exististance 71 * of the real world object (eg. a page) 72 * 73 * You should preferable use accessCachedValue() instead. 74 * 75 * @param string $value 76 * @return int the RID of the entry 77 */ 78 public function accessValue($value) 79 { 80 $result = $this->accessValues([$value]); 81 return $result[$value]; 82 } 83 84 /** 85 * Searches the Index for all given values and adds them if not found 86 * 87 * @param string[] $values 88 * @return array the RIDs of the entries 89 */ 90 abstract public function accessValues($values); 91 92 /** 93 * Clears the index by deleting its file 94 * @return void 95 */ 96 public function clear() 97 { 98 @unlink($this->filename); 99 } 100 101} 102