Support » Plugin: Relevanssi - A Better Search » Filter Request (with solution): Don't log bots

  • Hey Mikko,

    I see that in relevanssi_update_log(), you’re not logging searches that come from Google. What would be awesome would be a filter that could let us specify our own useragents to skip logging – my site gets hit by tons of unique bots, and I’ve already got a pretty comprehensive list that I’ve put together for the wp-useronline plugin. Below is some code I’ve adapted from that plugin which I think could work nicely for Relevanssi (or something similar, if you’d have a different design preference – and are willing to incorporate it, of course ;)):

    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $bots = array('google','msnbot','bingbot', ...);
    $bots = apply_filters( 'relevanssi_bots', $bots );
    $bot_found = false;
    foreach ( $bots as $bot )
      if ( stristr( $user_agent, $bot ) !== false )
        $bot_found = true;
    if($bot_found) return;

    Thanks in advance! 🙂

Viewing 1 replies (of 1 total)
  • As an addendum to this: if it’s not too tough, I think it might be a really good idea to actually log the useragent too.

    I’ve been having a look at my logs, and it looks like I’m getting a lot of duplicate hits for terms I myself tested a short time before; you might recall that awhile back, I discovered something similar was happening because of Google Analytics. Whenever I searched for something, Google Analytics would access the same URL, causing each search to be logged twice. By recording the useragent responsible for a log, users could much more easily determine if a given log was even real or if it was i.e. just a crawler trying URLs – and then exclude bad-behaving bots from being logged via the filter I suggested above 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Filter Request (with solution): Don't log bots’ is closed to new replies.