[CON-1988] Ihre Suche nach 'für' hat ....

Gesperrt
lunsen_de
Beiträge: 295
Registriert: Mo 17. Okt 2005, 20:26
Wohnort: Weimar
Kontaktdaten:

[CON-1988] Ihre Suche nach 'für' hat ....

Beitrag von lunsen_de » Mo 17. Nov 2014, 16:58

Hallo, bei dem Modul Search_output besteht bei mir ein Problem.

Findet die Suche Treffer und im Suchwort ist ein Umlaut steht da:
Ihre Suche nach 'für' hat 6 Treffer ergeben.
Dann folgen die Treffer, hier ist für richtig.

Findet die Suche keine Treffer ist der Umlaut richtig:
Ihre Suche nach 'ändern' hat leider keine Treffer ergeben.

Was muss man im Output ändern? Jemand eine Idee?

Code: Alles auswählen

<?php
/**
 * Module-Output: Search_Output
 *
 * NOTES:
 * System properties in use:
 * - Type: searchrange, Name: include, contains comma-separated list of categories to be included into search (sub-cats are included automatically)
 * - Type: searchrange, Name: include_categories, contains additional comma-separated list of categories to be included into search (sub-cats are not included automatically)
 * - Type: searchrange, Name: include_articles, contains additional comma-separated list of articles to be included into search
 * - Type: searchrange, Name: searchable_articles, contains comma-separated list of articles to use for search (note: overwrites 'include', 'include_categories' and 'include_articles')
 * Logical combination of search terms with AND or OR
 *
 * @author     Willi Man, Murat Purc <murat@purc.de>
 * @copyright  four for business AG <www.4fb.de>
 * @version    1.0.1
 *
 * $Id: Search_Output_output.php 14 2013-01-03 16:08:10Z murat $
 */

// #################################################################################################
// INITIALIZATION

cInclude('includes', 'functions.api.string.php');

if (!is_object($tpl)) {
    $tpl = new Template();
}
$tpl->reset();

$modContext = new stdClass();

$modContext->oApiClient = new cApiClient($client);
$modContext->oUrl = Contenido_Url::getInstance();

$modContext->dbSearchOptions = array('regexp', 'like', 'exact');

$modContext->combineOptions = array('and', 'or', '');

$modContext->defaultCmsOptions = 'head,html,htmlhead,htmltext,text';

$modContext->defaultEmphasizeWith = '<strong>,</strong>';

// Some simple templates
$modContext->tplPageNavItemCurrent = '<span style="white-space:nowrap;">&nbsp;<strong>%s</strong>&nbsp;</span>';
$modContext->tplPageNavItem = '<span style="white-space:nowrap;">&nbsp;<a href="%s" title="%s. ' . mi18n("Ergebnisseite anzeigen") . '">%s</a>&nbsp;</span>';
$modContext->tplNextPage = '&nbsp;<a style="margin-left:30px;" href="%s" title="' . mi18n("nächste Ergebnisseite anzeigen") . '">' . mi18n("vor") . '</a>';
$modContext->tplPreviousPage = '<a style="margin-right:30px;" href="%s" title="' . mi18n("vorherige Ergebnisseite anzeigen") . '">' . mi18n("zur&uuml;ck") . '</a>&nbsp;';


// #################################################################################################
// SETTINGS

// (bool) Enable debugging
$modContext->debug = false;

// (array) List of category tree ids to limit the search
$modContext->cfgCategoryTree = $modContext->oApiClient->getProperty('searchrange', 'include');
if (!empty($modContext->cfgCategoryTree)) {
    $modContext->cfgCategoryTree = explode(',', $modContext->cfgCategoryTree);
} else {
    $modContext->cfgCategoryTree = null;
}

// (array) List of additional category ids to limit the search (in addition to 'cfgCategoryTree')
$modContext->cfgCategories = $modContext->oApiClient->getProperty('searchrange', 'include_categories');
if (!empty($modContext->cfgCategories)) {
    $modContext->cfgCategories = explode(',', $modContext->cfgCategories);
} else {
    $modContext->cfgCategories = null;
}

// (array) List of additional articles ids to limit the search (in addition to 'cfgCategoryTree')
$modContext->cfgArticles = $modContext->oApiClient->getProperty('searchrange', 'include_articles');
if (!empty($modContext->cfgArticles)) {
    $modContext->cfgArticles = explode(',', $modContext->cfgArticles);
} else {
    $modContext->cfgArticles = null;
}

// (array) List of article ids which should be searchable.
//         NOTE: Overwrites settings 'cfgCategoryTree', 'cfgCategories' and 'cfgArticles'
$modContext->cfgSearchableArticles = $modContext->oApiClient->getProperty('searchrange', 'searchable_articles');
if (!empty($modContext->cfgSearchableArticles)) {
    $modContext->cfgSearchableArticles = explode(',', $modContext->cfgSearchableArticles);
} else {
    $modContext->cfgSearchableArticles = null;
}

// (int) Number of search results to display per page
$modContext->cfgItemsPerPage = "CMS_VALUE[1]";
if ((int) $modContext->cfgItemsPerPage < 1) {
    $modContext->cfgItemsPerPage = 10;
}

// (int) Max length of text to display (headline, subheadline and teasertext)
$modContext->cfgMaxLengthTeasertext = "CMS_VALUE[2]";
if ((int) $modContext->cfgMaxLengthTeasertext < 1) {
    $modContext->cfgMaxLengthTeasertext = 200;
}

// (string) Type of db search, feasible values are 'regexp', 'like' or 'exact'
$modContext->cfgDbSearchOption = "CMS_VALUE[3]";
if (!in_array($modContext->dbSearchOption, $modContext->dbSearchOptions)) {
    $modContext->cfgDbSearchOption = 'regexp';
}

// (string) Specify and/or search, if searchterm contains more than one word.
$modContext->cfgCombine = "CMS_VALUE[4]";
if (!in_array($modContext->combine, $modContext->combineOptions)) {
    $modContext->cfgCombine = '';
}

// (bool) Searchrange specified in 'categoryTree', 'cfgCategories' and 'cfgArticles' is excluded, otherwise included (exclusive)
$modContext->cfgExclude = ("CMS_VALUE[5]" == "1") ? true : false;

// (bool) Search offline articles or articles in categories which are offline.
//        If eanbled, it searches only in items with active 'visible' and 'online' state.
$modContext->cfgDontShowOfflineArticles = ("CMS_VALUE[6]" == "1") ? true : false;

// (bool) Don't search articles or articles in categories which are offline or protected.
//        If eanbled, it overwrites the setting 'dontShowOfflineArticles'.
$modContext->cfgProtected = ("CMS_VALUE[7]" == "1") ? true : false;

// (array) Search only in these cms-types (entries in lower case and without the 'cms_' prefix)
$modContext->cfgCmsOptions = "CMS_VALUE[8]";
if (empty($modContext->cfgCmsOptions)) {
    $modContext->cfgCmsOptions = $modContext->defaultCmsOptions;
}
$modContext->cfgCmsOptions = explode(',', $modContext->cfgCmsOptions);

// (array) HTML tags (start and end) to emphasize the located searchterm in search results
$modContext->cfgEmphasizeWith = "CMS_VALUE[9]";
if (empty($modContext->cfgEmphasizeWith)) {
    $modContext->cfgEmphasizeWith = $modContext->defaultEmphasizeWith;
}
$modContext->cfgEmphasizeWith = explode(',', $modContext->cfgEmphasizeWith);


// #################################################################################################
// MISC

if (!function_exists('module_searchOutput_getArticleSpecification')) {
    /**
     * Get specification of an article
     * @param  int  $articleId  Article id
     * @param  int  $langId  Language id
     * @return  int|bool  Id of article specification or false
     */
    function module_searchOutput_getArticleSpecification($articleId, $langId) {
        global $db, $cfg;
        $sql = "SELECT artspec FROM " . $cfg['tab']['art_lang'] . " WHERE"
             . " idart = " . (int) $articleId . " AND idlang = " . (int) $langId;
        $db->query($sql);
        return ($db->next_record()) ? $db->f('artspec') : false;
    }
}


// #################################################################################################
// PROCESSING / OUTPUT


if ($modContext->debug) {
    echo '<pre>Settings: ';
    foreach ($modContext as $var => $value) {
        if (0 === strpos($var, 'cfg')) {
            echo "$var: " . print_r($value, true) . "\n";
        }
    }
    echo '</pre>';
}

// Get search term and pre-process it
$searchTerm = '';
if (!empty($_GET['searchterm'])) {
    $searchTerm = urldecode(conHtmlentities(strip_tags(stripslashes($_GET['searchterm']))));
} elseif (!empty($_POST['searchterm'])) {
    $searchTerm = urldecode(conHtmlentities(strip_tags(stripslashes($_POST['searchterm']))));
}
$searchTerm = str_replace(' + ', ' AND ', $searchTerm);
$searchTerm = str_replace(' - ', ' NOT ', $searchTerm);
$searchTermDisplay = $searchTerm;

// Get all article specs
$sql = "SELECT idartspec, artspec FROM " . $cfg['tab']['art_spec'] . " WHERE "
        . "client = $client AND lang = $lang AND online = 1";
$db->query($sql);
$aArtSpecs = array();
while ($db->next_record()) {
    $aArtSpecs[] = $db->f('idartspec');
}
$aArtSpecs[] = 0;

if (strlen(trim($searchTerm)) > 0) {
    // Parse search term and set search options
    $searchTerm = conHtmlEntityDecode($searchTerm);

    if (empty($modContext->cfgCombine)) {
        $modContext->cfgCombine = (stristr($searchTerm, ' or ') === false) ? 'and' : 'or';
    }

    $searchTerm = str_replace(' and ', ' ', strtolower($searchTerm));
    $searchTerm = str_replace(' or ', ' ', strtolower($searchTerm));

    // Instantiate search with some options
    $options = array(
        'db' => $modContext->cfgDbSearchOption,
        'combine' => $modContext->cfgCombine,
        'exclude' => $modContext->cfgExclude,
        'cat_tree' => $modContext->cfgCategoryTree,
        'categories' => $modContext->cfgCategories,
        'articles' => $modContext->cfgArticles,
        'searchable_articles' => $modContext->cfgSearchableArticles,
        'artspecs' => $aArtSpecs, // array of article specifications => search only articles with these artspecs
        'protected' => $modContext->cfgProtected,
        'dontshowofflinearticles' => $modContext->cfgDontShowOfflineArticles
    );
    $search = new Search($options);

    $search->setCmsOptions($modContext->cfgCmsOptions);

    // Execute search
    $aSearchResults = $search->searchIndex($searchTerm, '');

    // Build results page
    if (count($aSearchResults) > 0) {
        $tpl->set('s', 'result_page', mi18n("Ergebnis-Seite") . ':');

        // Build meessage
        $message = sprintf("%s '%s' %s:", mi18n("Ihre Suche nach"), conHtmlSpecialChars(strip_tags($searchTermDisplay)), mi18n("hat $$$ Treffer ergeben"));
        $message = str_replace('$$$', count($aSearchResults), $message);
        $tpl->set('s', 'MESSAGE', $message);

        // Get search results, number of results per page and pages
        $oSearchResults = new SearchResult($aSearchResults, $modContext->cfgItemsPerPage);
        $iNumberOfResults = $oSearchResults->getNumberOfResults();
        $iNumberOfPages = $oSearchResults->getNumberOfPages();
        $oSearchResults->setReplacement($modContext->cfgEmphasizeWith[0], $modContext->cfgEmphasizeWith[1]);

        // Get current result page
        $page = (!empty($_GET['page']) && (int) $_GET['page'] > 0) ? $_GET['page'] : 1;
        $aResPage = $oSearchResults->getSearchResultPage($page);

        // Build result pages navigation
        $pagesNav = '';
        for ($i = 1; $i <= $iNumberOfPages; $i++) {
            // This is just for sample client - modify to your needs!
            if ($cfg['url_builder']['name'] == 'front_content' || $cfg['url_builder']['name'] == 'MR') {
                $aParams = array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchTermDisplay, 'page' => ($i . $sArtSpecs));
            } else {
                $aParams = array(
                    'search' => array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchTermDisplay, 'page' => ($i . $sArtSpecs)),
                    'idcat' => $idcat, // needed to build category path
                    'lang' => $lang, // needed to build category path
                    'level' => 1 // needed to build category path
                );
            }
            try {
                $url = $modContext->oUrl->build($aParams);
            } catch (InvalidArgumentException $e) {
                $url = $sess->url('front_content.php?idcat=' . $idcat . '&idart=' . $idart . '&searchterm=' . $searchTermDisplay . '&page=' . $i . $sArtSpecs);
            }
            if ($i == $page) {
                $pagesNav .= sprintf($modContext->tplPageNavItemCurrent, $i);
            } else {
                $pagesNav .= sprintf($modContext->tplPageNavItem, $url, $i, $i);
            }
        }
        $tpl->set('s', 'PAGES', $pagesNav);

        // Build link to next result page
        if ($page < $iNumberOfPages) {
            $n = $page + 1;
            // This is just for sample client - modify to your needs!
            if ($cfg['url_builder']['name'] == 'front_content' || $cfg['url_builder']['name'] == 'MR') {
                $aParams = array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchTermDisplay, 'page' => ($n . $sArtSpecs));
            } else {
                $aParams = array(
                    'search' => array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchTermDisplay, 'page' => ($n . $sArtSpecs)),
                    'idcat' => $idcat, // needed to build category path
                    'lang' => $lang, // needed to build category path
                    'level' => 1 // needed to build category path
                );
            }
            try {
                $url = $modContext->oUrl->build($aParams);
            } catch (InvalidArgumentException $e) {
                $url = $sess->url('front_content.php?idcat=' . $idcat . '&idart=' . $idart . '&searchterm=' . $searchTerm . '&page=' . $n . $sArtSpecs);
            }
            $nextpage .= sprintf($modContext->tplNextPage, $url);
            $tpl->set('s', 'NEXT', $nextpage);
        } else {
            $tpl->set('s', 'NEXT', '<span style="color:#4989C4; margin-left:30px;">&rsaquo;</span>');
        }

        // Build link to previous result page
        if ($page > 1) {
            $p = $page - 1;
            // This is just for sample client - modify to your needs!
            if ($cfg['url_builder']['name'] == 'front_content' || $cfg['url_builder']['name'] == 'MR') {
                $aParams = array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchTermDisplay, 'page' => ($p . $sArtSpecs));
            } else {
                $aParams = array(
                    'search' => array('lang' => $lang, 'idcat' => $idcat, 'idart' => $idart, 'searchterm' => $searchTermDisplay, 'page' => ($p . $sArtSpecs)),
                    'idcat' => $idcat, // needed to build category path
                    'lang' => $lang, // needed to build category path
                    'level' => 1 // needed to build category path
                );
            }
            try {
                $url = $modContext->oUrl->build($aParams);
            } catch (InvalidArgumentException $e) {
                $url = $sess->url('front_content.php?idcat=' . $idcat . '&idart=' . $idart . '&searchterm=' . $searchTerm . '&page=' . $p . $sArtSpecs);
            }
            $prevpage .= sprintf($modContext->tplPreviousPage, $url);
            $tpl->set('s', 'PREV', $prevpage);
        } else {
            $tpl->set('s', 'PREV', '<span style="color:#4989C4; margin-right:30px;">&lsaquo;</span>');
        }

        if (count($aResPage) > 0) {
            $i = 1;
            // Build single search result on result page
            foreach ($aResPage as $key => $val) {
                $num = $i + (($page - 1) * $modContext->cfgItemsPerPage);
                $oArt = new Article($key, $client, $lang);
                // Get publishing date of article
                $sPublished = $oArt->getField('published');
                $sPublishedBy = trim(strip_tags($oArt->getContent('HEAD', 90)));
                if ($sPublishedBy != '') {
                    $sPublishedDate = '[' . $sPublishedBy . ']';
                } else {
                    $sPublishedDate = '';
                    if ($sPublished[8] != '0') {
                        $sPublishedDate .= $sPublished[8];
                    }
                    $sPublishedDate .= $sPublished[9] . '.';
                    if ($sPublished[5] != '0') {
                        $sPublishedDate .= $sPublished[5];
                    }
                    $sPublishedDate .= $sPublished[6] . '.' . $sPublished[0] . $sPublished[1] . $sPublished[2] . $sPublished[3] . ']';
                    $sPublishedDate = '[' . $sPublishedDate;
                }

                // Get text and headline of current article
                $iCurrentArtSpec = module_searchOutput_getArticleSpecification($key, $lang);
                $aHeadline = $oSearchResults->getSearchContent($key, 'HTMLHEAD', 1);
                $aSubheadline = $oSearchResults->getSearchContent($key, 'HTMLHEAD', 2);
                $aText = $oSearchResults->getSearchContent($key, 'HTML', 1);
                $sText = capiStrTrimAfterWord($aText[0], $modContext->cfgMaxLengthTeasertext);

                $sHeadline = capiStrTrimAfterWord($aHeadline[0], $modContext->cfgMaxLengthTeasertext); # lars conflict with capiStrTrimAfterWord and setReplacement('<strong>', '</strong>')
                $sSubHeadline = capiStrTrimAfterWord($aSubheadline[0], $modContext->cfgMaxLengthTeasertext);

                $iCategoryId = $oSearchResults->getArtCat($key);
                $fSimilarity = sprintf('%.0f', $oSearchResults->getSimilarity($key));

                // Send output to template
                // This is just for sample client - modify to your needs!
                if ($cfg['url_builder']['name'] == 'front_content' || $cfg['url_builder']['name'] == 'MR') {
                    $aParams = array('lang' => $lang, 'idcat' => $iCategoryId, 'idart' => $key);
                } else {
                    $aParams = array(
                        'search' => array('lang' => $lang, 'idcat' => $iCategoryId, 'idart' => $key),
                        'idcat' => $idcat, // needed to build category path
                        'lang' => $lang, // needed to build category path
                        'level' => 1  // needed to build category path
                    );
                }
                try {
                    $sHref = $modContext->oUrl->build($aParams);
                } catch (InvalidArgumentException $e) {
                    $sHref = $sess->url("front_content.php?idcat=$iCategoryId&idart=$key");
                }
                $tpl->set('d', 'more', mi18n("mehr"));
                $tpl->set('d', 'HREF', $sHref);
                $tpl->set('d', 'TITLE', mi18n("Link zu Suchergebnis") . ' ' . $i);
                $tpl->set('d', 'NUM', $num);
                $tpl->set('d', 'CATNAME', $sHeadline);
                $tpl->set('d', 'HEADLINE', $sText);
                $tpl->set('d', 'SUBHEADLINE', $sSubHeadline);
                $tpl->set('d', 'SIMILARITY', $fSimilarity);
                $tpl->set('d', 'TARGET', '_self');
                $tpl->set('d', 'PUB_DATE', $sPublishedDate);
                $tpl->next();
                $i++;
            }
            $tpl->generate('templates/search_output.html');
        }
    } else {
        // No results
        $tpl->set('s', 'MESSAGE', mi18n("Ihre Suche nach") . " '" . conHtmlSpecialChars(strip_tags($searchTerm)) . "' " . mi18n("hat leider keine Treffer ergeben") . '.');
        $tpl->set('s', 'NEXT', '');
        $tpl->set('s', 'PREV', '');
        $tpl->set('s', 'PAGES', '');
        $tpl->set('s', 'result_page', '');
        $tpl->generate('templates/search_output.html');
    }
} else {
    echo '<div id="searchResults">';
    echo '<h1>' . mi18n("Keine Suchergebnisse - Bitte suchen Sie &uuml;ber das Sucheingabefeld!") . '</h1>';
    echo '</div>';
}

unset($modContext);

?>
Danke.
lunsen_de

frederic.schneider_4fb
Beiträge: 967
Registriert: Do 15. Apr 2004, 17:12
Wohnort: Eschborn-Niederhöchstadt
Kontaktdaten:

Re: Ihre Suche nach 'f&uuml;r' hat ....

Beitrag von frederic.schneider_4fb » Do 4. Dez 2014, 14:27

Vielen Dank, das ist eindeutig ein Fehler in CONTENIDO. Ich habe hierzu ein Ticket angelegt, sodass wir uns darum kümmern werden: https://issues.contenido.org/browse/CON-1988
Frederic Schneider
Entwickler bei der four for business AG

berkel
Beiträge: 10
Registriert: So 12. Apr 2015, 18:01
Kontaktdaten:

Re: [CON-1988] Ihre Suche nach 'f&uuml;r' hat ....

Beitrag von berkel » Mo 13. Apr 2015, 10:03

Ich habe ein ähnliches Problem in der Version 4.9.7, frische Installation mit dem Beispielmandanten. Gebe ich in der Suche z.B. 'für' ein, so wird ein Treffer gefunden. Klickt man dann auf die Seitenzahl/-navigation wird kein Treffer mehr gefunden weil der Umlaut umgewandelt wurde:
Ihre Suche nach 'f&uuml;r' hat leider keine Treffer ergeben.

McHubi
Beiträge: 1209
Registriert: Do 18. Nov 2004, 23:06
Wohnort: Mettmann
Kontaktdaten:

Re: [CON-1988] Ihre Suche nach 'f&uuml;r' hat ....

Beitrag von McHubi » Di 14. Apr 2015, 10:32

Hallo berkel,

die onboard-Suche der Version 4.9. hat leider ohnehin einen kleinen "Hau" (siehe z. B. hier http://forum.contenido.org/viewtopic.php?f=92&t=34513). Alternativ kannst Du die hier verwenden: http://forum.contenido.org/viewtopic.php?f=89&t=35456

VG,

Markus
seamless-design.de
"Geht nicht!" wohnt in der "Will nicht!"-Strasse.

Das Handbuch zur Version 4.10: CONTENIDO für Einsteiger (4.10)

Das Handbuch zur Version 4.9: CONTENIDO für Einsteiger (4.9)

berkel
Beiträge: 10
Registriert: So 12. Apr 2015, 18:01
Kontaktdaten:

Re: [CON-1988] Ihre Suche nach 'f&uuml;r' hat ....

Beitrag von berkel » Di 14. Apr 2015, 13:59

Hallo Markus,

danke für deine Antwort. Ich werde mir dein Suchmodul mal ansehen. Eigentlich reicht mir eine einfache Suchfunktion aus, da die Website relativ wenig Inhalt und eine klare Struktur hat, aber funktionieren sollte die Suche schon.

Probleme hatte ich zuerst bei der Suche in der russischen Sprachversion festgestellt (keine Indexierung und keine Suche möglich), das konnte ich durch ein Update von 4.9.6 auf 4.9.7 und PHP 5.4 beheben (da stimmt die Angabe bei den Systemvoraussetzungen nicht). Von 4.9.6 auf 4.9.7 wurde auch nochmal am Suchmodul geschraubt. Bestehen bleibt das Problem mit der Umlautumwandlung beim Klick auf die Seitennavigation.

[EDIT]
Ich habe ein neues Thema dazu unter 4.9.x angelegt: http://forum.contenido.org/viewtopic.php?f=92&t=36206

Gesperrt