mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-05-11 20:21:16 +00:00
add record_type and some facets
This commit is contained in:
parent
73398f105e
commit
9821dceab3
|
@ -146,6 +146,7 @@ class SeedDMS_SQLiteFTS_IndexedDocument extends SeedDMS_SQLiteFTS_Document {
|
|||
|
||||
if($document->isType('document')) {
|
||||
$this->addField(SeedDMS_SQLiteFTS_Field::Keyword('document_id', 'D'.$document->getID()));
|
||||
$this->addField(SeedDMS_SQLiteFTS_Field::Keyword('record_type', 'document'));
|
||||
$version = $document->getLatestContent();
|
||||
if($version) {
|
||||
$this->addField(SeedDMS_SQLiteFTS_Field::Keyword('mimetype', $version->getMimeType()));
|
||||
|
@ -223,6 +224,7 @@ class SeedDMS_SQLiteFTS_IndexedDocument extends SeedDMS_SQLiteFTS_Document {
|
|||
}
|
||||
} elseif($document->isType('folder')) {
|
||||
$this->addField(SeedDMS_SQLiteFTS_Field::Keyword('document_id', 'F'.$document->getID()));
|
||||
$this->addField(SeedDMS_SQLiteFTS_Field::Keyword('record_type', 'folder'));
|
||||
$this->addField(SeedDMS_SQLiteFTS_Field::Keyword('created', $document->getDate(), 'unindexed'));
|
||||
}
|
||||
} /* }}} */
|
||||
|
|
|
@ -77,9 +77,9 @@ class SeedDMS_SQLiteFTS_Indexer {
|
|||
$version = SQLite3::version();
|
||||
if(self::ftstype == 'fts4') {
|
||||
if($version['versionNumber'] >= 3008000)
|
||||
$sql = 'CREATE VIRTUAL TABLE docs USING fts4(documentid, title, comment, keywords, category, mimetype, origfilename, owner, content, created, users, status, path, notindexed=created, matchinfo=fts3)';
|
||||
$sql = 'CREATE VIRTUAL TABLE docs USING fts4(documentid, record_type, title, comment, keywords, category, mimetype, origfilename, owner, content, created, users, status, path, notindexed=created, matchinfo=fts3)';
|
||||
else
|
||||
$sql = 'CREATE VIRTUAL TABLE docs USING fts4(documentid, title, comment, keywords, category, mimetype, origfilename, owner, content, created, users, status, path, matchinfo=fts3)';
|
||||
$sql = 'CREATE VIRTUAL TABLE docs USING fts4(documentid, record_type, title, comment, keywords, category, mimetype, origfilename, owner, content, created, users, status, path, matchinfo=fts3)';
|
||||
$res = $index->_conn->exec($sql);
|
||||
if($res === false) {
|
||||
return null;
|
||||
|
@ -90,7 +90,7 @@ class SeedDMS_SQLiteFTS_Indexer {
|
|||
return null;
|
||||
}
|
||||
} elseif(self::ftstype == 'fts5') {
|
||||
$sql = 'CREATE VIRTUAL TABLE docs USING fts5(documentid, title, comment, keywords, category, mimetype, origfilename, owner, content, created unindexed, users, status, path)';
|
||||
$sql = 'CREATE VIRTUAL TABLE docs USING fts5(documentid, record_type, title, comment, keywords, category, mimetype, origfilename, owner, content, created unindexed, users, status, path)';
|
||||
$res = $index->_conn->exec($sql);
|
||||
if($res === false) {
|
||||
return null;
|
||||
|
@ -135,7 +135,7 @@ class SeedDMS_SQLiteFTS_Indexer {
|
|||
if($res === false) {
|
||||
return false;
|
||||
}
|
||||
$sql = "INSERT INTO docs (documentid, title, comment, keywords, category, owner, content, mimetype, origfilename, created, users, status, path) VALUES (".$this->_conn->quote($doc->getFieldValue('document_id')).", ".$this->_conn->quote($doc->getFieldValue('title')).", ".$this->_conn->quote($comment).", ".$this->_conn->quote($keywords).", ".$this->_conn->quote($category).", ".$this->_conn->quote($doc->getFieldValue('owner')).", ".$this->_conn->quote($content).", ".$this->_conn->quote($mimetype).", ".$this->_conn->quote($origfilename).", ".(int)$created.", ".$this->_conn->quote($doc->getFieldValue('users')).", ".$this->_conn->quote($status).", ".$this->_conn->quote($doc->getFieldValue('path'))/*time()*/.")";
|
||||
$sql = "INSERT INTO docs (documentid, record_type, title, comment, keywords, category, owner, content, mimetype, origfilename, created, users, status, path) VALUES (".$this->_conn->quote($doc->getFieldValue('document_id')).", ".$this->_conn->quote($doc->getFieldValue('record_type')).", ".$this->_conn->quote($doc->getFieldValue('title')).", ".$this->_conn->quote($comment).", ".$this->_conn->quote($keywords).", ".$this->_conn->quote($category).", ".$this->_conn->quote($doc->getFieldValue('owner')).", ".$this->_conn->quote($content).", ".$this->_conn->quote($mimetype).", ".$this->_conn->quote($origfilename).", ".(int)$created.", ".$this->_conn->quote($doc->getFieldValue('users')).", ".$this->_conn->quote($status).", ".$this->_conn->quote($doc->getFieldValue('path'))/*time()*/.")";
|
||||
$res = $this->_conn->exec($sql);
|
||||
if($res === false) {
|
||||
return false;
|
||||
|
@ -183,13 +183,49 @@ class SeedDMS_SQLiteFTS_Indexer {
|
|||
if(!$this->_conn)
|
||||
return false;
|
||||
|
||||
$sql = "SELECT count(*) AS `c` FROM `docs`";
|
||||
/* First count some records for facets */
|
||||
foreach(array('owner', 'mimetype', 'category') as $facetname) {
|
||||
$sql = "SELECT `".$facetname."`, count(*) AS `c` FROM `docs`";
|
||||
if($query)
|
||||
$sql .= " WHERE docs MATCH ".$this->_conn->quote($query);
|
||||
$res = $this->_conn->query($sql." GROUP BY `".$facetname."`");
|
||||
if(!$res)
|
||||
return false;
|
||||
$facets[$facetname] = array();
|
||||
foreach($res as $row) {
|
||||
if($row[$facetname] && $row['c']) {
|
||||
if($facetname == 'category') {
|
||||
$tmp = explode(' ', $row[$facetname]);
|
||||
if(count($tmp) > 1) {
|
||||
foreach($tmp as $t) {
|
||||
if(!isset($facets[$facetname][$t]))
|
||||
$facets[$facetname][$t] = $row['c'];
|
||||
else
|
||||
$facets[$facetname][$t] += $row['c'];
|
||||
}
|
||||
} else {
|
||||
if(!isset($facets[$facetname][$row[$facetname]]))
|
||||
$facets[$facetname][$row[$facetname]] = $row['c'];
|
||||
else
|
||||
$facets[$facetname][$row[$facetname]] += $row['c'];
|
||||
}
|
||||
} else
|
||||
$facets[$facetname][$row[$facetname]] = $row['c'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT `record_type`, count(*) AS `c` FROM `docs`";
|
||||
if($query)
|
||||
$sql .= " WHERE docs MATCH ".$this->_conn->quote($query);
|
||||
$res = $this->_conn->query($sql);
|
||||
$res = $this->_conn->query($sql." GROUP BY `record_type`");
|
||||
if(!$res)
|
||||
return false;
|
||||
$row = $res->fetch();
|
||||
$facets['record_type'] = array('document'=>0, 'folder'=>0);
|
||||
foreach($res as $row) {
|
||||
$facets['record_type'][$row['record_type']] = $row['c'];
|
||||
}
|
||||
$total = $facets['record_type']['document'] + $facets['record_type']['folder'];
|
||||
|
||||
$sql = "SELECT ".$this->_rawid.", documentid FROM docs";
|
||||
if($query)
|
||||
|
@ -212,7 +248,7 @@ class SeedDMS_SQLiteFTS_Indexer {
|
|||
$hits[] = $hit;
|
||||
}
|
||||
}
|
||||
return array('count'=>$row['c'], 'hits'=>$hits);
|
||||
return array('count'=>$total, 'hits'=>$hits, 'facets'=>$facets);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
|
|
|
@ -89,6 +89,13 @@ class SeedDMS_SQliteFTS_Search {
|
|||
$querystr .= ')';
|
||||
}
|
||||
}
|
||||
if(!empty($fields['record_type'])) {
|
||||
if($querystr)
|
||||
$querystr .= ' AND ';
|
||||
$querystr .= '(record_type:';
|
||||
$querystr .= implode(' OR record_type:', $fields['record_type']);
|
||||
$querystr .= ')';
|
||||
}
|
||||
if(!empty($fields['category'])) {
|
||||
if($querystr)
|
||||
$querystr .= ' AND ';
|
||||
|
@ -96,6 +103,13 @@ class SeedDMS_SQliteFTS_Search {
|
|||
$querystr .= implode(' OR category:', $fields['category']);
|
||||
$querystr .= ')';
|
||||
}
|
||||
if(!empty($fields['mimetype'])) {
|
||||
if($querystr)
|
||||
$querystr .= ' AND ';
|
||||
$querystr .= '(mimetype:"';
|
||||
$querystr .= implode('" OR mimetype:"', $fields['mimetype']);
|
||||
$querystr .= '")';
|
||||
}
|
||||
if(!empty($fields['status'])) {
|
||||
if($querystr)
|
||||
$querystr .= ' AND ';
|
||||
|
@ -131,7 +145,7 @@ class SeedDMS_SQliteFTS_Search {
|
|||
foreach($result["hits"] as $hit) {
|
||||
$recs[] = array('id'=>$hit->id, 'document_id'=>$hit->documentid);
|
||||
}
|
||||
return array('count'=>$result['count'], 'hits'=>$recs, 'facets'=>array());
|
||||
return array('count'=>$result['count'], 'hits'=>$recs, 'facets'=>$result['facets']);
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user