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ć (IMG:
style_emoticons/default/questionmark.gif) (IMG:
style_emoticons/default/questionmark.gif)
zlączam też cały kod wyszukiwarki
<?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
GalleryCoreApi::requireOnce('modules/search/classes/GallerySearchInterface_1_0.class');
/**
* This is an implementation of the search module's SearchInterface_1_0
* @package GalleryCore
* @subpackage Classes
* @author Bharat Mediratta <bharat@menalto.com>
* @version $Revision: 17580 $
*/
class GalleryCoreSearch extends GallerySearchInterface_1_0 {
/**
* @see GallerySearchInterface_1_0.getSearchModuleInfo
*/
function getSearchModuleInfo() {
list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'core');
if ($ret) {
return array($ret, null); }
$info = array('name' => $module->translate('Gallery Core'), 'description' => $module->translate('Gallery Core Module'),
'description' => $module->translate('Search descriptions'),
'enabled' => 1),
'description' => $module->translate('Search keywords'),
'enabled' => 1),
'description' => $module->translate('Search summaries'),
'enabled' => 1),
'titles' => array('description' => $module->translate('Search titles'), 'enabled' => 1)));
return array(null, $info); }
/**
* @see GallerySearchInterface_1_0.search
*/
function search($options, $criteria, $offset=0, $count=-1) {
$columnNumber = 0;
foreach (array('descriptions' => '[GalleryItem::description]', 'keywords' => '[GalleryItem::keywords]',
'summaries' => '[GalleryItem::summary]',
'titles' => '[GalleryItem::title]')
as $key => $column) {
/* Replace it with this part
* IT ADDS A BASIC BOOLEAN SEARCH
* START NEW CODE
*/
if (isset($options[$key])) {
$criteria_array = explode(" ", $criteria); $total_items = count($criteria_array); $loop_index = 0;
$countWhere = "("; // to group for AND start
while ($loop_index < $total_items) {
$criteria_item =
trim($criteria_array[$loop_index]);
if (strlen($criteria_item) > 0
) {
if (($total_items > 1) and ($loop_index > 0))
{ // more words so AND or OR needed
/* checks if advanced search parameters are entered
* such as + for AND, - for AND NOT and translates them in SQL
* then removes the used special characters for search
* @author Francois Voisard <francois.voisard<at>gmx.ch>
*/
if (preg_match("/\!/",$criteria_array[$loop_index])) {
$criteria_item = ltrim($criteria_array[$loop_index],"!"); $countWhere .= "OR $column LIKE ?";
}
elseif (preg_match("/\-/",$criteria_array[$loop_index])) {
$criteria_item = ltrim($criteria_array[$loop_index],"-"); $countWhere .= "AND $column NOT LIKE ?";
}
else
{
$countWhere .= "AND $column LIKE ?";
}
}
else
{
if (preg_match("/\!/",$criteria_array[$loop_index])) {
$criteria_item = ltrim($criteria_array[$loop_index],"!"); $countWhere .= " $column LIKE ?";
}
elseif (preg_match("/\-/",$criteria_array[$loop_index])) {
$criteria_item = ltrim($criteria_array[$loop_index],"-"); $countWhere .= " $column LIKE ?";
}
else
{
$countWhere .= " $column LIKE ?";
}
}
//make each question mark to inject data later
$whereData[] = '%' . $criteria_item . '%';
}
$loop_index++;
} // end loop
$selectMap[$column] = $columnNumber++;
$selectList[] = $column;
$countWhere .= ") "; // to group
$whereList[] = $countWhere;
} // end isset
/*
* END NEW BOOLEAN CODE
*/
}
/* Always select back title and summary */
foreach (array('[GalleryItem::title]', '[GalleryItem::summary]') as $column) { if (!isset($selectMap[$column])) { $selectMap[$column] = $columnNumber++;
$selectList[] = $column;
}
}
$storage =& $gallery->getStorage();
list ($ret, $aclIds) = GalleryCoreApi::fetchAccessListIds(
'core.view', $gallery->getActiveUserId());
if ($ret) {
return array($ret, null); }
array('start' => 0, 'end' => '0', 'count' => 0, 'results' => array())); }
$aclMarkers = GalleryUtilities
::makeMarkers(count($aclIds));
SELECT
COUNT([GalleryItem::id])
FROM
[GalleryItem], [GalleryAccessSubscriberMap]
WHERE
(' . implode(' OR ', $whereList) . ') AND
[GalleryItem::id] = [GalleryAccessSubscriberMap::itemId]
AND
[GalleryAccessSubscriberMap::accessListId] IN (%s)
', $aclMarkers);
SELECT
[GalleryItem::id],
[GalleryUser::fullName],
[GalleryUser::userName],
[GalleryEntity::modificationTimestamp], ' .
FROM
[GalleryItem], [GalleryAccessSubscriberMap], [GalleryEntity], [GalleryUser]
WHERE
(' . implode(' OR ', $whereList) . ') AND
[GalleryItem::id] = [GalleryAccessSubscriberMap::itemId]
AND
[GalleryItem::id] = [GalleryEntity::id]
AND
[GalleryUser::id] = [GalleryItem::ownerId]
AND
[GalleryAccessSubscriberMap::accessListId] IN (%s)
ORDER BY
[GalleryEntity::modificationTimestamp] DESC, [GalleryItem::id] DESC
', $aclMarkers);
$data = $whereData;
/* Find the total */
list ($ret, $results) = $gallery->search($countQuery, $data);
if ($ret) {
return array($ret, null); }
$result = $results->nextResult();
$numRows = (int)$result[0];
/* Get the results that we're interested in */
list ($ret, $results) = $gallery->search(
$query, $data, array('limit' => array('offset' => $offset, 'count' => $count))); if ($ret) {
return array($ret, null); }
list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'core');
if ($ret) {
return array($ret, null); }
$text['description'] = $module->translate('Description');
$text['keywords'] = $module->translate('Keywords');
$text['summary'] = $module->translate('Summary');
$text['title'] = $module->translate('Title');
$text['owner'] = $module->translate('Owner');
$searchResults = array(); while ($result = $results->nextResult()) {
foreach (array('[GalleryItem::title]' => $text['title'], '[GalleryItem::summary]' => $text['summary'],
'[GalleryItem::keywords]' => $text['keywords'],
'[GalleryItem::description]' => $text['description'])
as $columnName => $fieldText) {
if (isset($selectMap[$columnName])) { /*
* Remember that our field columns start at column index 4
* (id, date, full name, username are columns 0-3)
*/
'key' => $fieldText, 'value' => $result[$selectMap[$columnName]+4]);
}
}
$fields[] = array('key' => $text['owner'], 'value' => !empty($result[1
]) ?
$result[1
] : $result[2
]); $searchResults[] = array('itemId' => (int
)$result[0], 'fields' => $fields); }
$data = array('start' => $numRows == 0 ? 0
: $offset+1, 'end' => $numRows == 0 ? 0
: $offset + sizeof($searchResults), 'count' => $numRows,
'results' => $searchResults);
return array(null, $data); }
}
?>