Download & Extend

Improvement in code logic and search results

Project:Multisite Search
Version:6.x-2.0
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Hello folks

I try to use the 1.1 version and works but with some issues for my perspective, for this reason I create a new version with this improvements.

1. New install to create tables with current Drupal installation prefix.
2. New Menu location, now is located in Site Configuration as other modules.
3. New site property to separate local site and Drupal external sites.
4. Added new function to general URL friendly URL for Drupal external sites, using the correct path alias for each Drupal installation

I decide to use the version 1.1 instead of 2 dev do most people will download the stable version if earthday47 push the 2 dev as 2 stable and he likes my changes and I can redo my version against 2 dev

Enjoy it

AttachmentSize
multisite_search.zip15.71 KB
multisite_search-1.1-dev.patch35.77 KB

Comments

#1

Thanks enzo. I can _FINALLY_ look at this again!

The 6.x-2.x-dev version is, in my opinion, more "stable" than the 6.x-1.x version, but I didn't want to make an official release without testing it more. I'm now at a crossroads - the current implementation makes it impossible to use separate databases - only table prefixing.

Which is bad news since I switched my site from table prefixing to database prefixing!

So I'll look at your code, and expect some commits to -dev soon.

Interested in co-maintaining?

#2

Version:6.x-1.1» 6.x-2.0
Status:needs review» fixed

Thanks for your code, -enzo-. I've committed most of it to the 6.x-2.0 version.

I committed the TTL cron variable as-is.

I liked your idea for looking up the path alias, but I simplified your implementation. Your code was like so:

<?php
function multisite_search_get_path_alias($path, $path_language = '',$prefix) {
 
$result = $path;
  if (
$alias = multisite_search_lookup_path('alias', $path, $path_language,$prefix)) {
   
$result = $alias;
  }
  return
$result;
}

function
multisite_search_lookup_path($action, $path = '', $path_language = '',$prefix ='') {
  global
$language;
 
// $map is an array with language keys, holding arrays of Drupal paths to alias relations
 
static $map = array(), $no_src = array(), $count;

 
$path_language = $path_language ? $path_language : $language->language;

 
// Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
 
if (!isset($count)) {
   
$count = db_result(db_query('SELECT COUNT(pid) FROM ' . $prefix . 'url_alias'));
  }

  if (
$action == 'wipe') {
   
$map = array();
   
$no_src = array();
   
$count = NULL;
  }
  elseif (
$count > 0 && $path != '') {
    if (
$action == 'alias') {
      if (isset(
$map[$path_language][$path])) {
        return
$map[$path_language][$path];
      }
     
// Get the most fitting result falling back with alias without language
      //drupal_set_message(sprint_f("SELECT dst FROM " . $prefix . "url_alias WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC, pid DESC", $path, $path_language));
     
$alias = db_result(db_query("SELECT dst FROM " . $prefix . "url_alias WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC, pid DESC", $path, $path_language));
     
$map[$path_language][$path] = $alias;
      return
$alias;
    }
   
// Check $no_src for this $path in case we've already determined that there
    // isn't a path that has this alias
   
elseif ($action == 'source' && !isset($no_src[$path_language][$path])) {
     
// Look for the value $path within the cached $map
     
$src = '';
      if (!isset(
$map[$path_language]) || !($src = array_search($path, $map[$path_language]))) {
       
// Get the most fitting result falling back with alias without language
       
if ($src = db_result(db_query("SELECT src FROM " . $prefix . "url_alias WHERE dst = '%s' AND language IN('%s', '') ORDER BY language DESC, pid DESC", $path, $path_language))) {
         
$map[$path_language][$src] = $path;
        }
        else {
         
// We can't record anything into $map because we do not have a valid
          // index and there is no need because we have not learned anything
          // about any Drupal path. Thus cache to $no_src.
         
$no_src[$path_language][$path] = TRUE;
        }
      }
      return
$src;
    }
  }

  return
FALSE;
}
?>

$language is untested and isn't really used. It seemed the static variables were not declared correctly and weren't really useful. Also, the $action parameter appeared to only use 'alias'. So I removed all the extra calls.

My code:

<?php
/**
* _multisite_search_get_path_alias()
*
* Helper function - manually searchs the path table and retrieves the path alias,
* if there is one.
*/
function _multisite_search_get_path_alias($path, $path_language = '', $prefix) {
 
$result = $path;
  if (
$alias = _multisite_search_lookup_path('alias', $path, $path_language, $prefix)) {
   
$result = $alias;
  }
  return
$result;
}
/**
* _multisitie_search_lookup_path()
*
* Helper function - search path table.
*/
function _multisite_search_lookup_path($action, $path = '', $path_language = '', $prefix = '') {
  global
$language;

 
$path_language = $path_language ? $path_language : $language->language;

  if (isset(
$map[$path_language][$path])) {
    return
$map[$path_language][$path];
  }
 
// Get the most fitting result falling back with alias without language
 
$alias = db_result(db_query("SELECT dst FROM " . $prefix . "url_alias WHERE src = '%s' AND language IN('%s', '') ORDER BY language DESC, pid DESC", $path, $path_language));

  return
$alias;
}
?>

I have not tested this with an i18n website, so I have no idea if it breaks. If it does, we can put in an issue and add it later.

#3

Hello earthday47 and everybody

This is my second version for 1.1

With :

1. New Features and Fixes
2. New install to create fields to enable sort results by date
3. New Menu location, now is located in Site Configuration as other modules.
4. New site property to separate local site and Drupal external sites.
5. Enabled several DB with same prefix.
6. DB Enabled to connection read from Drupal Settings.
7. Updated search to sort results based in configuration Date or Weight.
8. Added new function to general URL friendly URL for Drupal external sites, using the correct path alias for each Drupal installation

If you want I can share you a site with this new features, send me an email to enzo at anexusit dot com.

Please check and let me know if you think is a good a idea to include in version 2.0 when will be official.

Sure I can try to help you as a co-maintainer

enzo.

AttachmentSize
multisite_search-1.1-2_dev.patch 53.07 KB
multiside_search.zip 16.69 KB

#4

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#5

Would you mind basing this off of the 6.x-2.0 version?

I'm not sure if some of your changes are in line with what I was thinking for this module. I want to keep it as simple as possible. BUT I haven't looked closely at your code so I couldn't say.

I think some things have been changed/fixed in the 6.x-2.0 version so if you base it off that, we can more clearly evaluate.

Thanks again for helping out!

#6

Hello earthday47

Sure take a look and let me know.

My idea is take advance from drupal multi DB settings and be flexible in term multi DB with same prefix, check and let me know I can update my changes to version 2.0 when this version will be official.

Regards,

enzo

#7

2.0 is official now, I put 6.x-2.0 as the "Recommended release" on the project homepage: http://drupal.org/project/multisite_search
and put 1.1 under "other" releases, but not recommended.

#8

Hello Earth

What stuffs do you like to include in version 2.0 from my big patch, in order to prepare a path with a list of features you recommend.

Regards,

enzo

nobody click here