Skip to content

Instantly share code, notes, and snippets.

@sminnee
Created January 18, 2010 01:31
Show Gist options
  • Select an option

  • Save sminnee/279717 to your computer and use it in GitHub Desktop.

Select an option

Save sminnee/279717 to your computer and use it in GitHub Desktop.
Index: sphinx/code/SphinxVariants.php
===================================================================
--- sphinx/code/SphinxVariants.php (revision 97051)
+++ sphinx/code/SphinxVariants.php (working copy)
@@ -61,11 +61,22 @@
static function alterSearch(&$indexes, &$search) {
foreach (self::variant_handlers() as $variantclass) singleton($variantclass)->alterSearch($indexes, $search);
}
+
+ /**
+ * Alter the search fields that SphinxSearch index, based on some variant-specific logic
+ * @param $class string - The class being indexes
+ * @param $searchFields - An array of search fields as defined by SphinxSearchable::sphinxFields()
+ * @return none
+ */
+ static function alterSphinxFields($class, &$searchFields) {
+ foreach (self::variant_handlers() as $variantclass) singleton($variantclass)->alterSphinxFields($class, $searchFields);
+ }
}
interface SphinxVariant {
function alterIndexes($class, &$indexes);
function alterSearch(&$indexes, &$search);
+ function alterSphinxFields($class, &$searchFields);
}
class SphinxVariant_Versioned extends Object implements SphinxVariant {
@@ -97,13 +108,16 @@
unset($index);
}
}
+
+ function alterSphinxFields($class, &$searchFields) {
+ }
}
class SphinxVariant_Subsite extends Object implements SphinxVariant {
static $name = 'Sub';
function alterIndexes($class, &$indexes) {
- foreach ($indexes as $index) {
+ foreach ($indexes as $class => $index) {
$index->Sources[0]->qry->where = array_filter(
$index->Sources[0]->qry->where,
create_function('$str', 'return strpos($str, "SubsiteID") === false;')
@@ -136,6 +150,17 @@
$search['exclude']["{$base}SubsiteDoesntMatch"] = 1;
}
}
+
+ function alterSphinxFields($class, &$searchFields) {
+ $base = ClassInfo::baseDataClass($class);
+ if (Object::has_extension($base, 'SiteTreeSubsites')
+ || Object::has_extension($base, 'GroupSubsites')
+ || Object::has_extension($base, 'FileSubsites')) {
+ if(!isset($searchFields['SubsiteID'])) {
+ $searchFields['SubsiteID'] = array($base, "ForeignKey",true,null,null,null);
+ }
+ }
+ }
}
class SphinxVariant_Delta extends Object implements SphinxVariant {
@@ -158,7 +183,7 @@
$base = $inst->baseTable();
$join = $flagTable == $base ? "" : "LEFT JOIN `$base` on $flagTable.ID=$base.ID";
- $index->Sources[0]->prequery = "UPDATE $flagTable $join SET SphinxPrimaryIndexed = true WHERE " . $index->Sources[0]->qry->getFilter();
+ $index->Sources[0]->prequery = "UPDATE $flagTable $join SET $flagTable.SphinxPrimaryIndexed = true WHERE " . $index->Sources[0]->qry->getFilter();
// Set delta index's source to only collect items not yet in main index
$deltaIndex->Sources[0]->qry->where($flagTable . '.SphinxPrimaryIndexed = false');
@@ -174,5 +199,8 @@
foreach ($more as $index) $indexes[] = $index;
$search['exclude']["_dirty"] = 1;
}
+
+ function alterSphinxFields($class, &$searchFields) {
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment