Not signed in (Sign In)

Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorchewbears
    • CommentTimeMar 15th 2011 edited
     
    I have added the ability to "exact phrase match" along with multiple phrases, and and like statements. It is a revision on the + search created by sidtheduck.

    Edits all go in plog-functions.

    YOU WILL HAVE TO CHANGE THE FIELDS TO REFLECT THE FIELDS YOU WANT TO SEARCH!!! DO not think that my fields exist in your database.

    FIRST edit your search function to look something like this:

    <code>function plogger_init_search($arr) {
    $arr['searchterms'] = trim($arr['searchterms']);

    if (strstr($arr['searchterms'],'*+'))
    {
    $terms = explode('*+*',substr($arr['searchterms'],1,-1));
    $case = "AND";
    }
    else if (strstr($arr['searchterms'],'*'))
    {
    $terms = explode('* *',substr($arr['searchterms'],1,-1));
    $case = " OR";
    }
    else
    {
    $terms = explode(" ",$arr['searchterms']);
    $case = " OR";
    }

    $from = 0;
    $limit = 20;

    if (isset($arr['from']) && $arr['from'] > 0) {
    $from = $arr['from'];
    }

    // enforce hard-coded max limit
    if (isset($arr['limit']) && $arr['limit'] > 0 && $arr['limit'] <= 100) {
    $limit = $arr['limit'];
    }

    $query = " FROM `".TABLE_PREFIX."pictures` p LEFT JOIN `".TABLE_PREFIX."comments` c
    ON p.`id` = c.`parent_id` ";

    if ((count($terms) != 1) || ($terms[0] != '')){
    $query .= " WHERE ";
    foreach ((array)$terms as $term) {
    $query .= " (";
    $term = mysql_real_escape_string($term);
    $multi_term = explode("+",$term);
    if (count($multi_term)>1) {
    $path = implode("%' AND `path` LIKE '%",$multi_term);
    $description = implode("%' AND `description` LIKE '%",$multi_term);
    $comment = implode("%' AND `comment` LIKE '%",$multi_term);
    $caption = implode("%' AND `caption` LIKE '%",$multi_term);
    $EXIF_subj_ref = implode("%' AND `EXIF_subj_ref` LIKE '%",$multi_term);
    $EXIF_cont_loc_name = implode("%' AND `EXIF_cont_loc_name` LIKE '%",$multi_term);
    $EXIF_city = implode("%' AND `EXIF_city` LIKE '%",$multi_term);
    $EXIF_state = implode("%' AND `EXIF_state` LIKE '%",$multi_term);
    $EXIF_country = implode("%' AND `EXIF_country` LIKE '%",$multi_term);
    $EXIF_credit = implode("%' AND `EXIF_credit` LIKE '%",$multi_term);
    $EXIF_source = implode("%' AND `EXIF_source` LIKE '%",$multi_term);
    $EXIF_contact = implode("%' AND `EXIF_contact` LIKE '%",$multi_term);
    $EXIF_caption = implode("%' AND `EXIF_caption` LIKE '%",$multi_term);
    $EXIF_make = implode("%' AND `EXIF_make` LIKE '%",$multi_term);
    $EXIF_model = implode("%' AND `EXIF_model` LIKE '%",$multi_term);
    $EXIF_copyright = implode("%' AND `EXIF_copyright` LIKE '%",$multi_term);
    $EXIF_artist = implode("%' AND `EXIF_artist` LIKE '%",$multi_term);
    $EXIF_lat_ref = implode("%' AND `EXIF_lat_ref` LIKE '%",$multi_term);
    $EXIF_long_ref = implode("%' AND `EXIF_long_ref` LIKE '%",$multi_term);
    $EXIF_lat = implode("%' AND `EXIF_lat` LIKE '%",$multi_term);
    $EXIF_long = implode("%' AND `EXIF_long` LIKE '%",$multi_term);
    $EXIF_date_time_dig = implode("%' AND `EXIF_date_time_dig` LIKE '%",$multi_term);
    $EXIF_date_time_orig = implode("%' AND `EXIF_date_time_orig` LIKE '%",$multi_term);
    $EXIF_img_hist = implode("%' AND `EXIF_img_hist` LIKE '%",$multi_term);
    $EXIF_usr_comment = implode("%' AND `EXIF_usr_comment` LIKE '%",$multi_term);
    $EXIF_comment = implode("%' AND `EXIF_comment` LIKE '%",$multi_term);
    $EXIF_keyword = implode("%' AND `EXIF_keyword` LIKE '%",$multi_term);
    } else {
    $path = $description = $comment = $caption = $EXIF_subj_ref = $EXIF_cont_loc_name = $EXIF_city = $EXIF_state = $EXIF_country = $EXIF_credit = $EXIF_source = $EXIF_contact = $EXIF_caption = $EXIF_make = $EXIF_model = $EXIF_copyright = $EXIF_artist = $EXIF_lat_ref = $EXIF_long_ref = $EXIF_lat = $EXIF_long = $EXIF_date_time_dig = $EXIF_date_time_orig = $EXIF_img_hist = $EXIF_usr_comment = $EXIF_comment =$EXIF_keyword = $term;
    } $query .= "
    `path` LIKE '%$path%' OR
    `description` LIKE '%$description%' OR
    `comment` LIKE '%$comment%' OR
    `caption` LIKE '%$caption%' OR
    `EXIF_subj_ref` LIKE '%$EXIF_subj_ref%' OR
    `EXIF_cont_loc_name` LIKE '%$EXIF_cont_loc_name%' OR
    `EXIF_city` LIKE '%$EXIF_city%' OR
    `EXIF_state` LIKE '%$EXIF_state%' OR
    `EXIF_country` LIKE '%$EXIF_country%' OR
    `EXIF_credit` LIKE '%$EXIF_credit%' OR
    `EXIF_source` LIKE '%$EXIF_source%' OR
    `EXIF_contact` LIKE '%$EXIF_contact%' OR
    `EXIF_caption` LIKE '%$EXIF_caption%' OR
    `EXIF_make` LIKE '%$EXIF_make%' OR
    `EXIF_model` LIKE '%$EXIF_model%' OR
    `EXIF_copyright` LIKE '%$EXIF_copyright%' OR
    `EXIF_artist` LIKE '%$EXIF_artist%' OR
    `EXIF_lat_ref` LIKE '%$EXIF_lat_ref%' OR
    `EXIF_long_ref` LIKE '%$EXIF_long_ref%' OR
    `EXIF_lat` LIKE '%$EXIF_lat%' OR
    `EXIF_long` LIKE '%$EXIF_long%' OR
    `EXIF_date_time_dig` LIKE '%$EXIF_date_time_dig%' OR
    `EXIF_date_time_orig` LIKE '%$EXIF_date_time_orig%' OR
    `EXIF_img_hist` LIKE '%$EXIF_img_hist%' OR
    `EXIF_usr_comment` LIKE '%$EXIF_usr_comment%' OR
    `EXIF_comment` LIKE '%$EXIF_comment%' OR
    `EXIF_keyword` LIKE '%$EXIF_keyword%' ) $case";
    }
    $query = substr($query, 0, strlen($query) - 5) .") ";
    } else {
    // no search terms? no results either
    $query .= " WHERE 1 = 0";
    }

    $sort_fields = array('date_submitted','id');
    $sortby = 'date_submitted';

    if (isset($arr['sortby']) && in_array($arr['sortby'],$sort_fields)) {
    $sortby = $arr['sortby'];
    }

    $sortdir = ' ASC';

    if (isset($arr['sortdir']) && 'desc' == $arr['sortdir']) {
    $sortdir = ' DESC';
    }

    $result = run_query("SELECT COUNT(DISTINCT p.`id`) AS cnt " . $query);
    $row = mysql_fetch_assoc($result);

    $GLOBALS["total_pictures"] = $row["cnt"];
    // and I need sort order here as well
    // from and limit too
    $result = run_query("SELECT p.*,c.`comment`,
    UNIX_TIMESTAMP(`date_submitted`) AS `unix_date_submitted` ".$query .
    " GROUP BY p.`id` ORDER BY `$sortby` $sortdir LIMIT $from,$limit");

    $GLOBALS["available_pictures"] = mysql_num_rows($result);
    $GLOBALS["picture_counter"] = 0;
    $GLOBALS["picture_dbh"] = $result;

    }
    </code>
    • CommentAuthorchewbears
    • CommentTimeMar 15th 2011
     
    So what we have done is said use *'s to represent searches. This is because "'s break in the url making. But do not worry we will string replace the * to be " so that someone can type "Chewbears search" and find that exact phrase.

    <code>plogger_init_search(array(
    'searchterms' => str_replace('"','*', $_GET['searchterms']),
    'from' => $from,
    'limit' => $lim));
    } else if ($GLOBALS["plogger_level"] == "album") {
    plogger_init_pictures(array(
    'type' => 'album',
    'value' => $id,
    'from' => $from,
    'limit' => $lim,
    'sortby' => isset($_SESSION['plogger_sortby']) ? $_SESSION['plogger_sortby'] : '',
    'sortdir' => isset($_SESSION['plogger_sortdir']) ? $_SESSION['plogger_sortdir'] : ''));
    } else if ($GLOBALS["plogger_level"] == "collection") {
    plogger_init_albums(array(
    'from' => $from,
    'limit' => $lim,
    'collection_id' => $id,
    'sortby' => !empty($config['album_sortby']) ? $config['album_sortby'] : 'id',
    'sortdir' => !empty($config['album_sortdir']) ? $config['album_sortdir'] : 'DESC'));
    } else if ($GLOBALS["plogger_level"] == "picture") {
    // first lets load the thumbnail of the picture at the correct size
    plogger_init_picture(array('id' => $id));
    } else {
    // Show all of the collections
    plogger_init_collections(array(
    'from' => $from,
    'limit' => $lim,
    'sortby' => !empty($config['collection_sortby']) ? $config['collection_sortby'] : 'id',
    'sortdir' => !empty($config['collection_sortdir']) ? $config['collection_sortdir'] : 'DESC'));
    }
    }</code>

    and



    <code>function plogger_pagination_control() {
    global $config;

    if ($GLOBALS['plogger_mode'] != 'slideshow') {
    $page = isset($_GET["plog_page"]) ? intval($_GET["plog_page"]) : 1;

    if ($GLOBALS['plogger_level'] == "search") {
    $EXIFterms = urlencode($_GET["searchterms"]);
    $p_url = $config['baseurl']."?level=search&amp;searchterms=".str_replace('"', '*', str_replace('+','%2B',$_GET['searchterms']))."&amp;id=".$GLOBALS["plogger_id"];
    }
    else {
    if ($GLOBALS['plogger_level']) {
    $p_url = generate_url($GLOBALS['plogger_level'], $GLOBALS['plogger_id']);
    if ($config["use_mod_rewrite"]) {
    $p_url .= "/";
    }
    }
    else {
    $p_url = $config["baseurl"];
    }
    }

    switch($GLOBALS['plogger_level']) {
    case 'search':
    $num_items = $GLOBALS["total_pictures"];
    break;

    case 'album':
    $num_items = plogger_album_picture_count();
    break;

    case 'collection':
    $num_items = plogger_collection_album_count();
    break;

    default:
    $num_items = plogger_count_collections();
    break;
    }

    return generate_pagination($p_url, $page, $num_items, $config["thumb_num"]);
    }

    }
    </code>

    and


    <code>function plogger_slideshow_link() {

    global $config;
    $id = $GLOBALS["plogger_id"];
    $ss_tag = "";
    if ($GLOBALS['plogger_mode'] != "slideshow") {
    if ($GLOBALS['plogger_level'] == "album") {
    $ss_url = generate_url('album',$GLOBALS['plogger_id'],array('mode' => 'slideshow'));
    $ss_tag = "<a href=\"$ss_url\">" . plog_tr('View as Slideshow') . "</a>";
    }

    if ($GLOBALS['plogger_level'] == "search") {
    $ss_url = $config['baseurl'] . '?level=search&amp;searchterms=' . str_replace('"', '*', str_replace('+','%2B',$_GET['searchterms']));
    $ss_url .= "&amp;mode=slideshow";
    $ss_tag = "<a href=\"$ss_url\">" . plog_tr('View as Slideshow') . "</a>";
    }

    }
    return $ss_tag;
    }</code>

    So I fixed the * to " issue in the pagination (page generation), the slideshow, and the search url creation. YOU MAY SEE :

    YOU SEARCHED FOR *Chewbears Search* even though you typed "Chewbears Search". You can chance that or live with it. I didn't see the need to fix it since it worked!

    I can not provide much support for this feature, but it is working on the version before RC 1 but should work in later versions as the PHP is up to date. Your functions might just be a little different. SO AGAIN take what you need out of the above and run with it. The last 3 bits of code are mere string replaces to make " into * so the url can be read easier. The search function itself I added 2 variables for OR and AND and created a *exact phrase match* using those asterisks. ENJOY!!!