Commit bc2fd9d8d29acc9a74e03d561c0f9bb190d54b19
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
Showing
6 changed files
with
42 additions
and
11 deletions
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
search2/search/fields/DocumentIdField.inc.php
search2/search/fields/FilenameField.inc.php
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