gui shall use rt index for tags and notes handling

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2022-12-31 09:03:58 +01:00
parent 8a75e5f62c
commit 2740902c08
3 changed files with 76 additions and 21 deletions

View File

@ -20,11 +20,13 @@ class ControllerMessageNote extends Controller {
if(isset($this->request->post['note']) && isset($this->request->post['id'])) {
if($this->model_search_search->check_your_permission_by_id($this->request->post['id']) == 1) {
$this->model_search_message->add_message_note($this->request->post['id'], $session->get("uid"), urldecode($this->request->post['note']));
if(RT) {
$this->model_search_message->add_message_rt_note($this->request->post['id'], $session->get("uid"), urldecode($this->request->post['note']));
} else {
$this->model_search_message->add_message_note($this->request->post['id'], $session->get("uid"), urldecode($this->request->post['note']));
}
}
}
}
}
?>

View File

@ -457,7 +457,11 @@ class ModelSearchMessage extends Model {
public function get_message_tag($id = '', $uid = 0) {
if($id == '' || $uid <= 0) { return ''; }
$query = $this->db->query("SELECT `tag` FROM " . TABLE_TAG . " WHERE uid=? AND id=?", array($uid, $id));
if(RT) {
$query = $this->sphx->query("SELECT tag FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid=$id");
} else {
$query = $this->db->query("SELECT `tag` FROM " . TABLE_TAG . " WHERE uid=? AND id=?", array($uid, $id));
}
if(isset($query->row['tag'])) { return strip_tags($query->row['tag']); }
@ -469,11 +473,19 @@ class ModelSearchMessage extends Model {
if($id == '' || $uid <= 0) { return 0; }
if($tag == '') {
$query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id=?", array($uid, $id));
if(RT) {
$this->sphx->query("DELETE FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid=$id");
} else {
$query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id=?", array($uid, $id));
}
} else {
$query = $this->db->query("UPDATE " . TABLE_TAG . " SET tag=? WHERE uid=? AND id=?", array($tag, $uid, $id));
if($this->db->countAffected() == 0) {
$query = $this->db->query("INSERT INTO " . TABLE_TAG . " (id, uid, tag) VALUES(?,?,?)", array($id, $uid, $tag));
if(RT) {
$this->sphx->query("REPLACE INTO " . SPHINX_TAG_INDEX . " (mid, uid, tag) VALUES (?,?,?)",[$id,$uid,$tag]);
} else {
$query = $this->db->query("UPDATE " . TABLE_TAG . " SET tag=? WHERE uid=? AND id=?", array($tag, $uid, $id));
if($this->db->countAffected() == 0) {
$query = $this->db->query("INSERT INTO " . TABLE_TAG . " (id, uid, tag) VALUES(?,?,?)", array($id, $uid, $tag));
}
}
}
@ -484,11 +496,20 @@ class ModelSearchMessage extends Model {
public function bulk_add_message_tag($ids = array(), $uid = 0, $tag = '', $q = '') {
$arr = array_merge(array($uid), $ids);
$query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id IN ($q)", $arr);
if(RT) {
$ids_str = implode(",", $ids);
$this->sphx->query("DELETE FROM " . SPHINX_TAG_INDEX . " WHERE uid=$uid AND mid IN ($ids_str)");
} else {
$query = $this->db->query("DELETE FROM " . TABLE_TAG . " WHERE uid=? AND id IN ($q)", $arr);
}
if($tag) {
foreach ($ids as $id) {
$query = $this->db->query("INSERT INTO " . TABLE_TAG . " (id, uid, tag) VALUES(?,?,?)", array($id, $uid, $tag));
if(RT) {
$this->sphx->query("INSERT INTO " . SPHINX_TAG_INDEX . " (mid, uid, tag) VALUES(?,?,?)", [$id, $uid, $tag]);
} else {
$query = $this->db->query("INSERT INTO " . TABLE_TAG . " (id, uid, tag) VALUES(?,?,?)", array($id, $uid, $tag));
}
}
}
}
@ -497,7 +518,11 @@ class ModelSearchMessage extends Model {
public function get_message_note($id = '', $uid = 0) {
if($id == '' || $uid <= 0) { return ''; }
$query = $this->db->query("SELECT `note` FROM " . TABLE_NOTE . " WHERE uid=? AND id=?", array($uid, $id));
if(RT) {
$query = $this->sphx->query("SELECT note FROM " . SPHINX_NOTE_INDEX . " WHERE uid=$uid AND mid=$id");
} else {
$query = $this->db->query("SELECT `note` FROM " . TABLE_NOTE . " WHERE uid=? AND id=?", array($uid, $id));
}
if(isset($query->row['note'])) { return strip_tags(urldecode($query->row['note'])); }
@ -521,6 +546,18 @@ class ModelSearchMessage extends Model {
}
public function add_message_rt_note($id = '', $uid = 0, $note = '') {
if($id == '' || $uid <= 0) { return 0; }
$this->sphx->query("DELETE FROM " . SPHINX_NOTE_INDEX . " WHERE uid=$uid AND mid=$id");
if($note) {
$this->sphx->query("INSERT INTO " . SPHINX_NOTE_INDEX . " (mid, uid, note) VALUES (?,?,?)",[$id,$uid,$note]);
}
return 1;
}
public function get_message_private($id = 0) {
if($id == 0) { return 0; }

View File

@ -416,10 +416,16 @@ class ModelSearchSearch extends Model {
$s = $this->fixup_sphinx_operators($s);
$q = $this->sphx->query("SELECT iid FROM $sphx_table WHERE uid=" . $session->get("uid") . " AND MATCH('@$field $s') LIMIT $offset,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS);
if(RT) {
$idfield = 'mid';
} else {
$idfield = 'iid';
}
$q = $this->sphx->query("SELECT $idfield FROM $sphx_table WHERE uid=" . $session->get("uid") . " AND MATCH('@$field $s') LIMIT $offset,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS);
foreach($q->rows as $a) {
$id_list .= "," . $a['iid'];
$id_list .= "," . $a[$idfield];
}
if($id_list) { $id_list = substr($id_list, 1, strlen($id_list)); }
@ -513,18 +519,28 @@ class ModelSearchSearch extends Model {
}
}
array_unshift($ids, (int)$session->get("uid"));
$tags = $this->db->query("SELECT `id`, `tag` FROM `" . TABLE_TAG . "` WHERE `uid`=? AND `id` IN ($q)", $ids);
foreach ($tags->rows as $t) {
$tag[$t['id']] = $t['tag'];
if(RT) {
$id_field = 'mid';
$ids_str = implode(",", $ids);
$tags = $this->sphx->query("SELECT mid, tag FROM " . SPHINX_TAG_INDEX . " WHERE uid=" . (int)$session->get("uid") . " AND mid IN ($ids_str)");
} else {
$id_field = 'id';
array_unshift($ids, (int)$session->get("uid"));
$tags = $this->db->query("SELECT `id`, `tag` FROM `" . TABLE_TAG . "` WHERE `uid`=? AND `id` IN ($q)", $ids);
}
$notes = $this->db->query("SELECT `id`, `note` FROM " . TABLE_NOTE . " WHERE `uid`=? AND `id` IN ($q)", $ids);
foreach ($tags->rows as $t) {
$tag[$t[$id_field]] = $t['tag'];
}
if(RT) {
$notes = $this->sphx->query("SELECT mid, note FROM " . SPHINX_NOTE_INDEX . " WHERE uid=" . (int)$session->get("uid") . " AND mid IN ($ids_str)");
} else {
$notes = $this->db->query("SELECT `id`, `note` FROM " . TABLE_NOTE . " WHERE `uid`=? AND `id` IN ($q)", $ids);
}
foreach ($notes->rows as $n) {
$note[$n['id']] = $n['note'];
$note[$n[$id_field]] = $n['note'];
}
$lang = Registry::get('language');