set documentid in findById(), getDocument returns content, take out getFolder()

This commit is contained in:
Uwe Steinmann 2021-06-24 11:39:13 +02:00
parent 50e8c84932
commit 04c494eaaa

View File

@ -165,7 +165,7 @@ class SeedDMS_SQLiteFTS_Indexer {
* @param string $query * @param string $query
* @param array $limit array with elements 'limit' and 'offset' * @param array $limit array with elements 'limit' and 'offset'
* @return boolean false in case of an error, otherwise array with elements * @return boolean false in case of an error, otherwise array with elements
* 'count', 'hits', 'facets' * 'count', 'hits', 'facets'. 'hits' is an array of SeedDMS_SQLiteFTS_QueryHit
*/ */
public function find($query, $limit=array()) { /* {{{ */ public function find($query, $limit=array()) { /* {{{ */
if(!$this->_conn) if(!$this->_conn)
@ -206,20 +206,21 @@ class SeedDMS_SQLiteFTS_Indexer {
/** /**
* Get a single document from index * Get a single document from index
* *
* @param integer $id id of document * @param string $id id of document
* @return boolean false in case of an error, otherwise true * @return boolean false in case of an error, otherwise true
*/ */
public function findById($id) { /* {{{ */ public function findById($id) { /* {{{ */
if(!$this->_conn) if(!$this->_conn)
return false; return false;
$sql = "SELECT ".$this->_rawid." FROM docs WHERE ".$this->_rawid."=".(int) $id; $sql = "SELECT ".$this->_rawid.", documentid FROM docs WHERE documentid=".$this->_conn->quote($id);
$res = $this->_conn->query($sql); $res = $this->_conn->query($sql);
$hits = array(); $hits = array();
if($res) { if($res) {
while($rec = $res->fetch(PDO::FETCH_ASSOC)) { while($rec = $res->fetch(PDO::FETCH_ASSOC)) {
$hit = new SeedDMS_SQLiteFTS_QueryHit($this); $hit = new SeedDMS_SQLiteFTS_QueryHit($this);
$hit->id = $rec[$this->_rawid]; $hit->id = $rec[$this->_rawid];
$hit->documentid = $rec['documentid'];
$hits[] = $hit; $hits[] = $hit;
} }
} }
@ -232,11 +233,11 @@ class SeedDMS_SQLiteFTS_Indexer {
* @param integer $id id of index record * @param integer $id id of index record
* @return boolean false in case of an error, otherwise true * @return boolean false in case of an error, otherwise true
*/ */
public function getDocument($id) { /* {{{ */ public function getDocument($id, $content=true) { /* {{{ */
if(!$this->_conn) if(!$this->_conn)
return false; return false;
$sql = "SELECT ".$this->_rawid.", documentid, title, comment, owner, keywords, category, mimetype, origfilename, created, users, status, path FROM docs WHERE documentid='D".$id."'"; $sql = "SELECT ".$this->_rawid.", documentid, title, comment, owner, keywords, category, mimetype, origfilename, created, users, status, path".($content ? ", content" : "")." FROM docs WHERE ".$this->_rawid."='".$id."'";
$res = $this->_conn->query($sql); $res = $this->_conn->query($sql);
$doc = false; $doc = false;
if($res) { if($res) {
@ -255,6 +256,8 @@ class SeedDMS_SQLiteFTS_Indexer {
$doc->addField('users', $rec['users']); $doc->addField('users', $rec['users']);
$doc->addField('status', $rec['status']); $doc->addField('status', $rec['status']);
$doc->addField('path', $rec['path']); $doc->addField('path', $rec['path']);
if($content)
$doc->addField('content', $rec['content']);
} }
return $doc; return $doc;
} /* }}} */ } /* }}} */
@ -265,7 +268,7 @@ class SeedDMS_SQLiteFTS_Indexer {
* @param integer $id id of folder * @param integer $id id of folder
* @return boolean false in case of an error, otherwise true * @return boolean false in case of an error, otherwise true
*/ */
public function getFolder($id) { /* {{{ */ public function __getFolder($id) { /* {{{ */
if(!$this->_conn) if(!$this->_conn)
return false; return false;