Commit bc2fd9d8d29acc9a74e03d561c0f9bb190d54b19

Authored by conradverm
1 parent ea3a0ad5

KTS-2875

"Create a hooking mechanism for new searchable fields to be part of the general text search"
Fixed.

Committed By: Conrad Vermeulen
Reviewed By: Jalaloedien Abrahams

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7953 c91229c3-7414-0410-bfa2-8a42b809f60b
search2/search/fieldRegistry.inc.php
... ... @@ -70,6 +70,8 @@ class ExprFieldRegistry
70 70  
71 71 private $display;
72 72  
  73 + private $general;
  74 +
73 75 /**
74 76 * Initialise the registry.
75 77 * This is private and class must be obtained via the get() method.
... ... @@ -136,8 +138,17 @@ class ExprFieldRegistry
136 138 else
137 139 {
138 140 $this->display[] = $field->getAlias();
  141 +
  142 + if (isset($field->general_op))
  143 + {
  144 + $this->general[] = get_class($field);
  145 + }
139 146 }
  147 + }
140 148  
  149 + function getGeneralTextClasses()
  150 + {
  151 + return $this->general;
141 152 }
142 153  
143 154 public function resolveAlias($alias)
... ...
search2/search/fields/AnyMetadataField.inc.php
... ... @@ -38,6 +38,9 @@
38 38  
39 39 class AnyMetadataField extends DBFieldExpr
40 40 {
  41 + public $general_op = ExprOp::CONTAINS;
  42 +
  43 +
41 44 public function __construct()
42 45 {
43 46 parent::__construct('value', 'document_fields_link', _kt('Any Metadata'));
... ...
search2/search/fields/DocumentIdField.inc.php
... ... @@ -38,6 +38,8 @@
38 38  
39 39 class DocumentIdField extends DBFieldExpr
40 40 {
  41 + public $general_op = ExprOp::IS;
  42 +
41 43 public function __construct()
42 44 {
43 45 parent::__construct('id', 'documents', _kt('Document ID'));
... ...
search2/search/fields/FilenameField.inc.php
... ... @@ -38,6 +38,9 @@
38 38  
39 39 class FilenameField extends DBFieldExpr
40 40 {
  41 + public $general_op = ExprOp::CONTAINS;
  42 +
  43 +
41 44 public function __construct()
42 45 {
43 46 parent::__construct('filename', 'document_content_version', _kt('Filename'));
... ...
search2/search/fields/GeneralTextField.inc.php
... ... @@ -54,7 +54,6 @@ class GeneralTextField extends SearchableText
54 54 return DefaultOpCollection::validateParent($this, DefaultOpCollection::$contains);
55 55 }
56 56  
57   -
58 57 public function rewrite(&$left, &$op, &$right)
59 58 {
60 59 // note the grouping of the db queries
... ... @@ -62,17 +61,28 @@ class GeneralTextField extends SearchableText
62 61 $left = new OpExpr(new DocumentTextField(), ExprOp::CONTAINS, $right);
63 62  
64 63 $op = ExprOp::OP_OR;
  64 + $value = $right;
  65 + $right=null;
  66 +
  67 + $registry = ExprFieldRegistry::getRegistry();
  68 + $classes = $registry->getGeneralTextClasses();
  69 +
  70 + while (!empty($classes))
  71 + {
  72 + $classname = array_pop($classes);
  73 + $obj = new $classname();
  74 + $exprop = $obj->general_op;
  75 + $newexpr = new OpExpr($obj, $exprop, $value);
  76 + if (empty($right))
  77 + {
  78 + $right = $newexpr;
  79 + }
  80 + else
  81 + {
  82 + $right = new OpExpr($right, ExprOp::OP_OR, $newexpr);
  83 + }
  84 + }
65 85  
66   - $right = new OpExpr(
67   - new OpExpr(new FilenameField(), ExprOp::CONTAINS, $right),
68   - ExprOp::OP_OR,
69   - new OpExpr(
70   - new OpExpr(
71   - new TitleField(), ExprOp::CONTAINS, $right),
72   - ExprOp::OP_OR,
73   - new OpExpr(new AnyMetadataField(), ExprOp::CONTAINS, $right)
74   - )
75   - );
76 86 }
77 87  
78 88  
... ...
search2/search/fields/TitleField.inc.php
... ... @@ -38,6 +38,8 @@
38 38  
39 39 class TitleField extends DBFieldExpr
40 40 {
  41 + public $general_op = ExprOp::CONTAINS;
  42 +
41 43 public function __construct()
42 44 {
43 45 parent::__construct('name', 'document_metadata_version', _kt('Title'));
... ...