Permalink
Browse files

site search url detection rewritten

  • Loading branch information...
1 parent cee964f commit ca1fddb4f42417241877de673798598f66a1d3fb @BeezyT committed Mar 18, 2011
Showing with 22 additions and 45 deletions.
  1. +4 −11 Archive.php
  2. +6 −23 Controller.php
  3. +8 −7 SiteSearch.php
  4. +2 −2 lang/de.php
  5. +2 −2 lang/en.php
View
@@ -120,20 +120,13 @@ public static function displayColumns($view, $columns) {
/** Extend logging of an action */
public static function logAction($action, $idSite, $site, $resultCount=false) {
$parameter = $site['sitesearch_parameter'];
-
- if ($parameter == '/') {
- // search urls don't use a get parameter. instead, the search term
- // follows the search url directly. (e.g. drupal)
- $url = $site['sitesearch_url'];
- $url = str_replace('%', '', $url); // remove wildcards
- $regex = '/'.preg_quote($url, '/').'(.*?)$/i';
- } else {
- $regex = '/'.preg_quote($parameter, '/').'=(.*?)(&|$)/i';
- }
+ $regex = '/(&|\?)'.preg_quote($parameter, '/').'=(.*?)(&|$)/i';
$hit = preg_match($regex, $action['name'], $match);
+
if ($hit) {
- $searchTerm = strtolower(urldecode($match[1]));
+ $searchTerm = strtolower(urldecode($match[2]));
+
$id = self::getSearchTermId($searchTerm, $idSite, $resultCount);
$bind = array(':searchTerm' => $id);
Piwik_SiteSearch_Db::query('
View
@@ -267,28 +267,9 @@ private function analyzeSite($idSite) {
return;
}
- $url = $site['main_url'];
-
- // make sure, main url has a trailing slash
- if (substr($url, -1) != '/') {
- $url .= '/';
- }
-
- // make sure, sitesearch url has no leading slash
- if (substr($site['sitesearch_url'], 0, 1) == '/') {
- $site['sitesearch_url'] = substr($site['sitesearch_url'], 1);
- }
-
- // wildcards
- if (substr($site['sitesearch_url'], 0, 1) == '*') {
- $site['sitesearch_url'] = '%'.substr($site['sitesearch_url'], 1);
- }
- if (substr($site['sitesearch_url'], -1) == '*') {
- // wildcard at the end is default, just remove the *
- $site['sitesearch_url'] = substr($site['sitesearch_url'], 0, -1);
- }
-
- $url .= $site['sitesearch_url'];
+ // this is only a rough filter, Piwik_SiteSearch_Archive::logAction
+ // will do a more precise check
+ $url = '%'.$site['sitesearch_url'].'%'.$site['sitesearch_parameter'].'=%';
$sql = '
SELECT
@@ -306,8 +287,10 @@ private function analyzeSite($idSite) {
action.type = 1 AND
action.name LIKE :name AND
visit.idsite = :idSite
+ GROUP BY
+ action.idaction
';
- $bind = array(':name' => $url.'%', ':idSite' => intval($idSite));
+ $bind = array(':name' => $url, ':idSite' => intval($idSite));
$result = Piwik_SiteSearch_Db::fetchAll($sql, $bind);
foreach ($result as $action) {
View
@@ -175,22 +175,23 @@ public function logResults($notification) {
ON action.idaction = link.idaction_url
WHERE
action.idaction = '.intval($idaction).'
+ GROUP BY
+ site.idsite
';
$result = Piwik_FetchAll($sql);
$site = $result[0];
if (!empty($site['sitesearch_url']) && !empty($site['sitesearch_parameter'])) {
- $url = $site['main_url'];
- if (substr($url, -1) != '/') {
- $url .= '/';
- }
- $url .= $site['sitesearch_url'];
- $parameter = $site['sitesearch_parameter'];
+ // check whether action is a site search
+ $url = preg_quote($site['sitesearch_url'], '/');
+ $param = preg_quote($site['sitesearch_parameter'], '/');
+ $regex = '/'.$url.'(.*)(&|\?)'.$param.'=(.*?)(&|$)/i';
+
$actionUrl = $action->getActionUrl();
- if (substr($actionUrl, 0, strlen($url)) == $url) {
+ if (preg_match($regex, $actionUrl, $matches)) {
require_once PIWIK_INCLUDE_PATH .'/plugins/SiteSearch/Archive.php';
require_once PIWIK_INCLUDE_PATH .'/plugins/SiteSearch/Db.php';
Piwik_SiteSearch_Archive::logAction(array(
View
@@ -23,9 +23,9 @@
'SiteSearch_AdminDescription4' => 'Bei großen Datenbanken kann das einige Zeit in Anspruch nehmen.',
'SiteSearch_Website' => 'Webseite',
'SiteSearch_SearchURL' => 'Such-URL',
- 'SiteSearch_SearchURLDescription' => 'Die URL (relativ zum Stammverzeichnis der Webseite) der Suchergebnisseite.<br />Du kannst * als Wildcard am Anfang und/oder Ende der URL verwenden.',
+ 'SiteSearch_SearchURLDescription' => 'Der Teil der URL, mit dem die Suchergebnisseite identifiziert werden kann.<br />Es ist sinnvoll, die URL so genau wie m&ouml;glich zu w&auml;hlen, es reicht aber z.B. auch /, dann werden<br />alle URLs auf das Vorkommen des Parameters untersucht (die Performance leidet darunter allerdings).<br />Beispiel: Suchergebnisseite ist http://www.example.com/suche.php?q=searchterm => Gute Such-URL ist /suche.php',
'SiteSearch_SearchParameter' => 'Suchparameter',
- 'SiteSearch_SearchParameterDescription' => 'Der Name des GET Parameters, der den Suchbegriff enth&auml;lt.<br />Verwende /, wenn der Suchbegriff direkt auf die URL folgt (z.B. suche/dersuchbegriff)',
+ 'SiteSearch_SearchParameterDescription' => 'Der Name des GET Parameters, der den Suchbegriff enth&auml;lt.',
'SiteSearch_AnalyzeURLsNow' => 'URLs jetzt analysieren',
'SiteSearch_Save' => 'Speichern',
'SiteSearch_Keyword' => 'Suchbegriff',
View
@@ -23,9 +23,9 @@
'SiteSearch_AdminDescription4' => 'Depending on the size of your database, this might take a while.',
'SiteSearch_Website' => 'Website',
'SiteSearch_SearchURL' => 'Search URL',
- 'SiteSearch_SearchURLDescription' => 'The URL (relative to the website root) of the search results page.<br />You may use * as a wildcard at the beginning and/or the end of the URL.',
+ 'SiteSearch_SearchURLDescription' => 'The part of the URL, that identifies the search results page.<br />For performance reasons, you should choose the search url as specific as possible.<br />Nevertheless, you may use / to check all urls for the occurence of the search parameter.<br />Example: The search results page is http://www.example.com/search.php?q=searchterm => a good search url is /search.php',
'SiteSearch_SearchParameter' => 'Search Parameter',
- 'SiteSearch_SearchParameterDescription' => 'The name of the GET parameter, that holds the search term.<br /> You may use /, if the search term follows the search URL directly (e.g. search/thesearchterm)',
+ 'SiteSearch_SearchParameterDescription' => 'The name of the GET parameter, that holds the search term.',
'SiteSearch_AnalyzeURLsNow' => 'Analyze URLs now',
'SiteSearch_Save' => 'Save',
'SiteSearch_Keyword' => 'Keyword',

0 comments on commit ca1fddb

Please sign in to comment.