Witam wszystkich natknąłem się na problem którego nie umiem rozwiązać

manowicie zainstalowałem Gallery2 (aplikacje tworzącą gallerie) była w nej wyszukiwarka ale wszyszukiwała tylko po jednym argunecie. znanalazłem na jakimś forum kawałek kodu który umożliwia szukanie kilku wyrazów. wszystko działa bardzo dobrze dopuki nie szukamy czegoś takiego wyzar1 AND wyraz2 i jeden wyraz jest w słowach kluczach a drugi w opisie wtedy nie znajduje nic. więc wpadłem na pomysł żeby podczas ladowania danych do zmiennej z opisem dopisywać do niej słowa klucze po przestudiowaniu znalazłem gdzie to trzeba zrobić

w tej funkcji

function search($options, $criteria, $offset=1, $count=-2) {
global $gallery;

$whereList = array();
$whereData = array();
$columnNumber = 0;
foreach (array('descriptions' => '[GalleryItem::description] '+ '[GalleryItem::keywords]',
'keywords' => '[GalleryItem::keywords]',
'summaries' => '[GalleryItem::summary]',
'titles' => '[GalleryItem::title]')
as $key => $column) {


Dodanie wartości zaznaczonej na czerwono. Próbowałem dodać jak tesksty czyli &a.&b ale nie działa ma ktoś może jakiś pomysł jak to zrobić questionmark.gifquestionmark.gif


zlączam też cały kod wyszukiwarki

  1. <?php
  2. /*
  3.  * Gallery - a web based photo album viewer and editor
  4.  * Copyright (C) 2000-2008 Bharat Mediratta
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or (at
  9.  * your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful, but
  12.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14.  * General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  19.  */
  20.  
  21. GalleryCoreApi::requireOnce('modules/search/classes/GallerySearchInterface_1_0.class');
  22.  
  23. /**
  24.  * This is an implementation of the search module's SearchInterface_1_0
  25.  * @package GalleryCore
  26.  * @subpackage Classes
  27.  * @author Bharat Mediratta <bharat@menalto.com>
  28.  * @version $Revision: 17580 $
  29.  */
  30. class GalleryCoreSearch extends GallerySearchInterface_1_0 {
  31. /**
  32.   * @see GallerySearchInterface_1_0.getSearchModuleInfo
  33.   */
  34. function getSearchModuleInfo() {
  35. global $gallery;
  36.  
  37. list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'core');
  38. if ($ret) {
  39. return array($ret, null);
  40. }
  41.  
  42. $info = array('name' => $module->translate('Gallery Core'),
  43. 'description' => $module->translate('Gallery Core Module'),
  44. 'options' => array(
  45. 'descriptions' => array(
  46. 'description' => $module->translate('Search descriptions'),
  47. 'enabled' => 1),
  48. 'keywords' => array(
  49. 'description' => $module->translate('Search keywords'),
  50. 'enabled' => 1),
  51. 'summaries' => array(
  52. 'description' => $module->translate('Search summaries'),
  53. 'enabled' => 1),
  54. 'titles' => array('description' => $module->translate('Search titles'),
  55. 'enabled' => 1)));
  56. return array(null, $info);
  57. }
  58.  
  59. /**
  60.   * @see GallerySearchInterface_1_0.search
  61.   */
  62. function search($options, $criteria, $offset=0, $count=-1) {
  63. global $gallery;
  64.  
  65. $whereList = array();
  66. $whereData = array();
  67. $columnNumber = 0;
  68. foreach (array('descriptions' => '[GalleryItem::description]',
  69. 'keywords' => '[GalleryItem::keywords]',
  70. 'summaries' => '[GalleryItem::summary]',
  71. 'titles' => '[GalleryItem::title]')
  72. as $key => $column) {
  73.  
  74. /* Replace it with this part
  75. * IT ADDS A BASIC BOOLEAN SEARCH
  76. * START NEW CODE
  77. */
  78.  
  79. if (isset($options[$key])) {
  80.  
  81. $criteria_array = explode(" ", $criteria);
  82. $total_items = count($criteria_array);
  83. $loop_index = 0;
  84. $countWhere = "("; // to group for AND start
  85.  
  86. while ($loop_index < $total_items) {
  87.  
  88. $criteria_item =
  89. trim($criteria_array[$loop_index]);
  90.  
  91. if (strlen($criteria_item) > 0)
  92. {
  93.  
  94. if (($total_items > 1) and ($loop_index > 0))
  95. { // more words so AND or OR needed
  96.  
  97. /* checks if advanced search parameters are entered
  98. * such as + for AND, - for AND NOT and translates them in SQL
  99. * then removes the used special characters for search
  100. * @author Francois Voisard <francois.voisard<at>gmx.ch>
  101. */
  102.  
  103. if (preg_match("/\!/",$criteria_array[$loop_index]))
  104. {
  105. $criteria_item = ltrim($criteria_array[$loop_index],"!");
  106. $countWhere .= "OR $column LIKE ?";
  107. }
  108. elseif (preg_match("/\-/",$criteria_array[$loop_index]))
  109. {
  110. $criteria_item = ltrim($criteria_array[$loop_index],"-");
  111. $countWhere .= "AND $column NOT LIKE ?";
  112. }
  113. else
  114. {
  115. $countWhere .= "AND $column LIKE ?";
  116. }
  117.  
  118. }
  119. else
  120. {
  121.  
  122. if (preg_match("/\!/",$criteria_array[$loop_index]))
  123. {
  124. $criteria_item = ltrim($criteria_array[$loop_index],"!");
  125. $countWhere .= " $column LIKE ?";
  126. }
  127. elseif (preg_match("/\-/",$criteria_array[$loop_index]))
  128. {
  129. $criteria_item = ltrim($criteria_array[$loop_index],"-");
  130. $countWhere .= " $column LIKE ?";
  131. }
  132. else
  133. {
  134. $countWhere .= " $column LIKE ?";
  135. }
  136. }
  137.  
  138. //make each question mark to inject data later
  139. $whereData[] = '%' . $criteria_item . '%';
  140.  
  141. }
  142. $loop_index++;
  143.  
  144. } // end loop
  145.  
  146. $selectMap[$column] = $columnNumber++;
  147. $selectList[] = $column;
  148. $countWhere .= ") "; // to group
  149. $whereList[] = $countWhere;
  150. } // end isset
  151.  
  152. /*
  153. * END NEW BOOLEAN CODE
  154. */
  155. }
  156.  
  157. /* Always select back title and summary */
  158. foreach (array('[GalleryItem::title]', '[GalleryItem::summary]') as $column) {
  159. if (!isset($selectMap[$column])) {
  160. $selectMap[$column] = $columnNumber++;
  161. $selectList[] = $column;
  162. }
  163. }
  164.  
  165. $storage =& $gallery->getStorage();
  166.  
  167. list ($ret, $aclIds) = GalleryCoreApi::fetchAccessListIds(
  168. 'core.view', $gallery->getActiveUserId());
  169. if ($ret) {
  170. return array($ret, null);
  171. }
  172. if (empty($aclIds)) {
  173. return array(null,
  174. array('start' => 0, 'end' => '0',
  175. 'count' => 0, 'results' => array()));
  176. }
  177. $aclMarkers = GalleryUtilities::makeMarkers(count($aclIds));
  178.  
  179. $countQuery = sprintf('
  180. SELECT
  181. COUNT([GalleryItem::id])
  182. FROM
  183. [GalleryItem], [GalleryAccessSubscriberMap]
  184. WHERE
  185. (' . implode(' OR ', $whereList) . ')
  186. AND
  187. [GalleryItem::id] = [GalleryAccessSubscriberMap::itemId]
  188. AND
  189. [GalleryAccessSubscriberMap::accessListId] IN (%s)
  190. ', $aclMarkers);
  191.  
  192. $query = sprintf('
  193. SELECT
  194. [GalleryItem::id],
  195. [GalleryUser::fullName],
  196. [GalleryUser::userName],
  197. [GalleryEntity::modificationTimestamp], ' .
  198. implode(', ', $selectList) . '
  199. FROM
  200. [GalleryItem], [GalleryAccessSubscriberMap], [GalleryEntity], [GalleryUser]
  201. WHERE
  202. (' . implode(' OR ', $whereList) . ')
  203. AND
  204. [GalleryItem::id] = [GalleryAccessSubscriberMap::itemId]
  205. AND
  206. [GalleryItem::id] = [GalleryEntity::id]
  207. AND
  208. [GalleryUser::id] = [GalleryItem::ownerId]
  209. AND
  210. [GalleryAccessSubscriberMap::accessListId] IN (%s)
  211. ORDER BY
  212. [GalleryEntity::modificationTimestamp] DESC, [GalleryItem::id] DESC
  213. ', $aclMarkers);
  214.  
  215. $data = $whereData;
  216. $data = array_merge($data, $aclIds);
  217.  
  218. /* Find the total */
  219. list ($ret, $results) = $gallery->search($countQuery, $data);
  220. if ($ret) {
  221. return array($ret, null);
  222. }
  223. $result = $results->nextResult();
  224. $numRows = (int)$result[0];
  225.  
  226. /* Get the results that we're interested in */
  227. list ($ret, $results) = $gallery->search(
  228. $query, $data, array('limit' => array('offset' => $offset, 'count' => $count)));
  229. if ($ret) {
  230. return array($ret, null);
  231. }
  232.  
  233. list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'core');
  234. if ($ret) {
  235. return array($ret, null);
  236. }
  237.  
  238. $text['description'] = $module->translate('Description');
  239. $text['keywords'] = $module->translate('Keywords');
  240. $text['summary'] = $module->translate('Summary');
  241. $text['title'] = $module->translate('Title');
  242. $text['owner'] = $module->translate('Owner');
  243.  
  244. $searchResults = array();
  245. while ($result = $results->nextResult()) {
  246. $fields = array();
  247. foreach (array('[GalleryItem::title]' => $text['title'],
  248. '[GalleryItem::summary]' => $text['summary'],
  249. '[GalleryItem::keywords]' => $text['keywords'],
  250. '[GalleryItem::description]' => $text['description'])
  251. as $columnName => $fieldText) {
  252. if (isset($selectMap[$columnName])) {
  253. /*
  254. * Remember that our field columns start at column index 4
  255. * (id, date, full name, username are columns 0-3)
  256. */
  257. $fields[] = array(
  258. 'key' => $fieldText, 'value' => $result[$selectMap[$columnName]+4]);
  259. }
  260. }
  261.  
  262. $fields[] = array('key' => $text['owner'],
  263. 'value' => !empty($result[1]) ? $result[1] : $result[2]);
  264. $searchResults[] = array('itemId' => (int)$result[0], 'fields' => $fields);
  265. }
  266.  
  267. $data = array('start' => $numRows == 0 ? 0 : $offset+1,
  268. 'end' => $numRows == 0 ? 0 : $offset + sizeof($searchResults),
  269. 'count' => $numRows,
  270. 'results' => $searchResults);
  271. return array(null, $data);
  272. }
  273. }
  274. ?>