1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
<?php
/**
* GForge Search Engine
*
* Copyright 2004 (c) Dominik Haas, GForge Team
*
* http://gforge.org
*
* @version $Id: DocsSearchQuery.class 5273 2006-02-08 18:47:59Z danper $
*/
require_once('common/search/SearchQuery.class');
class DocsSearchQuery extends SearchQuery {
/**
* group id
*
* @var int $groupId
*/
var $groupId;
/**
* flag if non public items are returned
*
* @var boolean $showNonPublic
*/
var $showNonPublic;
/**
* Constructor
*
* @param string $words words we are searching for
* @param int $offset offset
* @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
* @param int $groupId group id
* @param array $sections sections to search in
* @param boolean $showNonPublic flag if private sections are searched too
*/
function DocsSearchQuery($words, $offset, $isExact, $groupId, $sections=SEARCH__ALL_SECTIONS, $showNonPublic=false) {
$this->groupId = $groupId;
$this->showNonPublic = $showNonPublic;
$this->SearchQuery($words, $offset, $isExact);
$this->setSections($sections);
}
/**
* getQuery - get the sql query built to get the search results
*
* @return string sql query to execute
*/
function getQuery() {
global $sys_use_fti;
if ($sys_use_fti) {
return $this->getFTIQuery();
} else {
$sql = 'SELECT doc_data.docid, doc_data.title, doc_data.description, doc_groups.groupname'
.' FROM doc_data, doc_groups'
.' WHERE doc_data.doc_group = doc_groups.doc_group'
.' AND doc_data.group_id ='.$this->groupId;
if ($this->sections != SEARCH__ALL_SECTIONS) {
$sql .= ' AND doc_groups.doc_group IN ('.$this->sections.') ';
}
if ($this->showNonPublic) {
$sql .= ' AND doc_data.stateid IN (1, 4, 5)';
} else {
$sql .= ' AND doc_data.stateid = 1';
}
$sql .= ' AND (('.$this->getIlikeCondition('title', $this->words).')'
.' OR ('.$this->getIlikeCondition('description', $this->words).'))'
.' ORDER BY doc_groups.groupname, doc_data.docid';
}
return $sql;
}
function getFTIQuery() {
if ($this->showNonPublic) {
$nonPublic = "1, 4, 5";
} else {
$nonPublic = "1";
}
if ($this->sections != SEARCH__ALL_SECTIONS) {
$sections = "AND doc_groups.doc_group IN ($this->sections)";
} else {
$sections = '';
}
$words = $this->getFormattedWords();
$group_id=$this->groupId;
$sql="SELECT doc_data.docid, headline(doc_data.title, q) AS title,
headline(doc_data.description, q) AS description, doc_groups.groupname
FROM doc_data, doc_groups, to_tsquery('$words') AS q, doc_data_idx
WHERE doc_data.doc_group = doc_groups.doc_group
AND doc_data.docid = doc_data_idx.docid AND vectors @@ q
AND doc_data.group_id = '$group_id'
$sections
AND doc_data.stateid IN ($nonPublic)
ORDER BY rank(vectors, q) DESC";
return $sql;
}
/**
* getSections - returns the list of available doc groups
*
* @param $groupId int group id
* @param $showNonPublic boolean if we should consider non public sections
*/
function getSections($groupId, $showNonPublic=false) {
$sql = 'SELECT doc_groups.doc_group, doc_groups.groupname FROM doc_groups, doc_data'
.' WHERE doc_groups.doc_group = doc_data.doc_group AND doc_groups.group_id = '.$groupId;
if ($showNonPublic) {
$sql .= ' AND doc_data.stateid IN (1, 4, 5)';
} else {
$sql .= ' AND doc_data.stateid = 1';
}
$sql .= ' ORDER BY groupname';
$sections = array();
$res = db_query($sql);
while($data = db_fetch_array($res)) {
$sections[$data['doc_group']] = $data['groupname'];
}
return $sections;
}
}
?>
|