return $qpa ;
}
-
- /**
- * getSearchByIdQuery - get the query built to get the search results when we are looking for an int
- *
- * @return array query+params array
- */
- function getSearchByIdQuery() {
- $qpa = db_construct_qpa () ;
-
- $qpa = db_construct_qpa ($qpa,
- 'SELECT DISTINCT ON (a.group_artifact_id,a.artifact_id) a.group_artifact_id, a.artifact_id') ;
- $qpa = db_construct_qpa ($qpa,
- ' FROM artifact a WHERE a.group_artifact_id=$1 AND a.artifact_id=$2',
- array ($this->artifactId,
- $this->searchId)) ;
-
- return $qpa;
- }
}
// Local Variables:
}
return $qpa ;
}
-
- /**
- * getSearchByIdQuery - get the sql query built to get the search results when we are looking for an int
- *
- * @return array query+params array
- */
- function getSearchByIdQuery() {
- $qpa = db_construct_qpa () ;
- $qpa = db_construct_qpa ($qpa,
- 'SELECT msg_id FROM forum WHERE msg_id=$1 AND group_forum_id=$2',
- array ($this->searchId,
- $this->forumId)) ;
-
- return $qpa ;
- }
}
// Local Variables:
return $qpa ;
}
- /**
- * getSearchByIdQuery - get the sql query built to get the search results when we are looking for an int
- *
- * @return array query+params array
- */
- function getSearchByIdQuery() {
- $qpa = db_construct_qpa () ;
- $qpa = db_construct_qpa ($qpa,
- 'SELECT msg_id FROM forum, forum_group_list WHERE msg_id=$1 AND forum_group_list.group_forum_id=forum.group_forum_id AND group_forum_id=$2',
- array ($this->searchId,
- $this->forumId)) ;
-
- return $qpa;
- }
-
/**
* getSections - returns the list of available forums
*
* @var resource $result
*/
var $result;
- /**
- * When search by id is enabled, the id to search for
- *
- * @var int $searchId
- */
- var $searchId = false;
/**
* if we want to search for all the words or if only one is sufficient
*
* @param int $rowsPerPage number of rows per page
*/
function __construct($words, $offset, $isExact, $rowsPerPage = SEARCH__DEFAULT_ROWS_PER_PAGE) {
- $this->field_separator = ' ioM0Thu6_fieldseparator_kaeph9Ee ';
$this->cleanSearchWords($words);
//We manual escap because every Query in Search escap parameters
$this->setError(_('Error: criteria not specified'));
return;
}
- if(is_numeric($words) && $this->implementsSearchById()) {
- $this->searchId = (int) $words;
- } else {
- $words = preg_replace("/[ \t]+/", ' ', $words);
- if(strlen($words) < 3) {
- $this->setError(_('Error: search query too short'));
- return;
- }
- $words = htmlspecialchars($words);
- $words = strtr($words, array('%' => '\%', '_' => '\_'));
- $phrase = '';
- $inQuote = false;
- foreach(explode(' ', quotemeta($words)) as $word) {
- if($inQuote) {
+
+ $words = preg_replace("/[ \t]+/", ' ', $words);
+ if(strlen($words) < 3) {
+ $this->setError(_('Error: search query too short'));
+ return;
+ }
+ $words = htmlspecialchars($words);
+ $words = strtr($words, array('%' => '\%', '_' => '\_'));
+ $phrase = '';
+ $inQuote = false;
+ foreach(explode(' ', quotemeta($words)) as $word) {
+ if($inQuote) {
+ if(substr($word, -1) == "'") {
+ $word = substr($word, 0, -1);
+ $inQuote = false;
+ $phrase .= ' '.$word;
+ $this->phrases[] = $phrase;
+ } else {
+ $phrase .= ' '.$word;
+ }
+ } else {
+ if(substr($word, 0, 1) == "'") {
+ $word = substr($word, 1);
+ $inQuote = true;
if(substr($word, -1) == "'") {
+ // This is a special case where the phrase is just one word
$word = substr($word, 0, -1);
$inQuote = false;
- $phrase .= ' '.$word;
- $this->phrases[] = $phrase;
+ $this->words[] = $word;
} else {
- $phrase .= ' '.$word;
+ $phrase = $word;
}
} else {
- if(substr($word, 0, 1) == "'") {
- $word = substr($word, 1);
- $inQuote = true;
- if(substr($word, -1) == "'") {
- // This is a special case where the phrase is just one word
- $word = substr($word, 0, -1);
- $inQuote = false;
- $this->words[] = $word;
- } else {
- $phrase = $word;
- }
- } else {
- $this->words[] = $word;
- }
+ $this->words[] = $word;
}
}
}
*/
function executeQuery() {
- if($this->searchId) {
- $qpa = $this->getSearchByIdQuery();
- } else {
- $qpa = $this->getQuery();
- }
-
$this->result = db_query_qpa (
- $qpa,
+ $this->getQuery(),
$this->rowsPerPage + 1,
$this->offset,
'SYS_DB_SEARCH'
}
}
- /**
- * implementsSearchById - check if the current object implements the search by id feature by having a getSearchByIdQuery method
- *
- * @return boolean true if our object implements search by id, false otherwise.
- */
- function implementsSearchById() {
- return method_exists($this, 'getSearchByIdQuery');
- }
-
/**
* getResult - returns the result set
*
}
return $sections;
}
-
- function getSearchByIdQuery() {
- $qpa = db_construct_qpa () ;
- $qpa = db_construct_qpa ($qpa,
- 'SELECT DISTINCT artifact.artifact_id, artifact.group_artifact_id, artifact.summary, artifact.open_date, users.realname, artifact_group_list.name FROM artifact LEFT OUTER JOIN artifact_message USING (artifact_id), users, artifact_group_list WHERE users.user_id = artifact.submitted_by AND artifact_group_list.group_artifact_id = artifact.group_artifact_id AND artifact_group_list.group_id = $1 ',
- array ($this->groupId)) ;
- if ($this->sections != SEARCH__ALL_SECTIONS) {
- $qpa = db_construct_qpa ($qpa,
- 'AND artifact_group_list.group_artifact_id = ANY ($1) ',
- array( db_int_array_to_any_clause ($this->sections))) ;
- }
- $qpa = db_construct_qpa ($qpa,
- 'AND artifact.artifact_id=$1 ORDER BY artifact_group_list.name, artifact.artifact_id',
- array ($this->searchId)) ;
-
- return $qpa ;
- }
}
// Local Variables:
DELETE FROM artifact_idx;
ALTER TABLE artifact_idx ADD PRIMARY KEY (artifact_id);
-INSERT INTO artifact_idx (SELECT a.artifact_id, to_tsvector(a.summary) || to_tsvector(a.details) || coalesce(ff_tsvector_agg(to_tsvector(am.body)), to_tsvector('')) AS vectors FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id) GROUP BY a.artifact_id, a.summary, a.details);
+INSERT INTO artifact_idx (SELECT a.artifact_id, to_tsvector(a.artifact_id::text) || to_tsvector(a.summary) || to_tsvector(a.details) || coalesce(ff_tsvector_agg(to_tsvector(am.body)), to_tsvector('')) AS vectors FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id) GROUP BY a.artifact_id, a.summary, a.details);
DROP TABLE artifact_message_idx;
DELETE FROM project_task_idx;
ALTER TABLE project_task_idx ADD PRIMARY KEY (project_task_id);
-INSERT INTO project_task_idx (SELECT t.project_task_id, to_tsvector(t.summary) || to_tsvector(t.details) || coalesce(ff_tsvector_agg(to_tsvector(tm.body)), to_tsvector('')) AS vectors FROM project_task t LEFT OUTER JOIN project_messages tm USING (project_task_id) GROUP BY t.project_task_id, t.summary, t.details);
+INSERT INTO project_task_idx (SELECT t.project_task_id, to_tsvector(t.project_task_id::text) || to_tsvector(t.summary) || to_tsvector(t.details) || coalesce(ff_tsvector_agg(to_tsvector(tm.body)), to_tsvector('')) AS vectors FROM project_task t LEFT OUTER JOIN project_messages tm USING (project_task_id) GROUP BY t.project_task_id, t.summary, t.details);
DROP TABLE project_messages_idx;
CREATE OR REPLACE FUNCTION update_vectors() RETURNS TRIGGER AS '
DELETE FROM artifact_idx WHERE artifact_id=OLD.artifact_id;
ELSE
DELETE FROM artifact_idx WHERE artifact_id=NEW.artifact_id;
- INSERT INTO artifact_idx (SELECT a.artifact_id, to_tsvector(a.summary) || to_tsvector(a.details) || coalesce(ff_tsvector_agg(to_tsvector(am.body)), to_tsvector('''')) AS vectors FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id) WHERE a.artifact_id=NEW.artifact_id GROUP BY a.artifact_id, a.summary, a.details);
+ INSERT INTO artifact_idx (SELECT a.artifact_id, to_tsvector(a.artifact_id::text) || to_tsvector(a.summary) || to_tsvector(a.details) || coalesce(ff_tsvector_agg(to_tsvector(am.body)), to_tsvector('''')) AS vectors FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id) WHERE a.artifact_id=NEW.artifact_id GROUP BY a.artifact_id, a.summary, a.details);
END IF;
-- **** artifact_message table ****
ELSIF table_name = ''artifact_message'' THEN
DELETE FROM artifact_idx WHERE artifact_id=OLD.artifact_id;
ELSE
DELETE FROM artifact_idx WHERE artifact_id=NEW.artifact_id;
- INSERT INTO artifact_idx (SELECT a.artifact_id, to_tsvector(a.summary) || to_tsvector(a.details) || coalesce(ff_tsvector_agg(to_tsvector(am.body)), to_tsvector('''')) AS vectors FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id) WHERE a.artifact_id=NEW.artifact_id GROUP BY a.artifact_id, a.summary, a.details);
+ INSERT INTO artifact_idx (SELECT a.artifact_id, to_tsvector(a.artifact_id::text) || to_tsvector(a.summary) || to_tsvector(a.details) || coalesce(ff_tsvector_agg(to_tsvector(am.body)), to_tsvector('''')) AS vectors FROM artifact a LEFT OUTER JOIN artifact_message am USING (artifact_id) WHERE a.artifact_id=NEW.artifact_id GROUP BY a.artifact_id, a.summary, a.details);
END IF;
-- **** doc_data table ****
ELSIF table_name = ''doc_data'' THEN
DELETE FROM project_task_idx WHERE project_task_id=OLD.project_task_id;
ELSE
DELETE FROM project_task_idx WHERE project_task_id=NEW.project_task_id;
- INSERT INTO project_task_idx (SELECT t.project_task_id, to_tsvector(t.summary) || to_tsvector(t.details) || coalesce(ff_tsvector_agg(to_tsvector(tm.body)), to_tsvector('''')) AS vectors FROM project_task t LEFT OUTER JOIN project_messages tm USING (project_task_id) WHERE t.project_task_id=NEW.project_task_id GROUP BY t.project_task_id, t.summary, t.details);
+ INSERT INTO project_task_idx (SELECT t.project_task_id, to_tsvector(t.project_task_id::text) || to_tsvector(t.summary) || to_tsvector(t.details) || coalesce(ff_tsvector_agg(to_tsvector(tm.body)), to_tsvector('''')) AS vectors FROM project_task t LEFT OUTER JOIN project_messages tm USING (project_task_id) WHERE t.project_task_id=NEW.project_task_id GROUP BY t.project_task_id, t.summary, t.details);
END IF;
-- **** project_messages table ****
ELSIF table_name = ''project_messages'' THEN