| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework 4 * 5 * LICENSE 6 * 7 * This source file is subject to the new BSD license that is bundled 8 * with this package in the file LICENSE.txt. 9 * It is also available through the world-wide-web at this URL: 10 * http://framework.zend.com/license/new-bsd 11 * If you did not receive a copy of the license and are unable to 12 * obtain it through the world-wide-web, please send an email 13 * to license@zend.com so we can send you a copy immediately. 14 * 15 * @category Zend 16 * @package Zend_Search_Lucene 17 * @subpackage Search 18 * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) 19 * @license http://framework.zend.com/license/new-bsd New BSD License 20 */ 21 22 23 /** Zend_Search_Lucene_Exception */ 24 require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Exception.php'; 25 26 27 /** 28 * @category Zend 29 * @package Zend_Search_Lucene 30 * @subpackage Search 31 * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) 32 * @license http://framework.zend.com/license/new-bsd New BSD License 33 */ 34 class Zend_Search_Lucene_Search_QueryToken 35 { 36 /** 37 * Token types. 38 */ 39 const TT_WORD = 0; // Word 40 const TT_PHRASE = 1; // Phrase (one or several quoted words) 41 const TT_FIELD = 2; // Field name in 'field:word', field:<phrase> or field:(<subquery>) pairs 42 const TT_FIELD_INDICATOR = 3; // ':' 43 const TT_REQUIRED = 4; // '+' 44 const TT_PROHIBITED = 5; // '-' 45 const TT_FUZZY_PROX_MARK = 6; // '~' 46 const TT_BOOSTING_MARK = 7; // '^' 47 const TT_RANGE_INCL_START = 8; // '[' 48 const TT_RANGE_INCL_END = 9; // ']' 49 const TT_RANGE_EXCL_START = 10; // '{' 50 const TT_RANGE_EXCL_END = 11; // '}' 51 const TT_SUBQUERY_START = 12; // '(' 52 const TT_SUBQUERY_END = 13; // ')' 53 const TT_AND_LEXEME = 14; // 'AND' or 'and' 54 const TT_OR_LEXEME = 15; // 'OR' or 'or' 55 const TT_NOT_LEXEME = 16; // 'NOT' or 'not' 56 const TT_TO_LEXEME = 17; // 'TO' or 'to' 57 const TT_NUMBER = 18; // Number, like: 10, 0.8, .64, .... 58 59 60 /** 61 * Returns all possible lexeme types. 62 * It's used for syntax analyzer state machine initialization 63 * 64 * @return array 65 */ 66 public static function getTypes() 67 { 68 return array( self::TT_WORD, 69 self::TT_PHRASE, 70 self::TT_FIELD, 71 self::TT_FIELD_INDICATOR, 72 self::TT_REQUIRED, 73 self::TT_PROHIBITED, 74 self::TT_FUZZY_PROX_MARK, 75 self::TT_BOOSTING_MARK, 76 self::TT_RANGE_INCL_START, 77 self::TT_RANGE_INCL_END, 78 self::TT_RANGE_EXCL_START, 79 self::TT_RANGE_EXCL_END, 80 self::TT_SUBQUERY_START, 81 self::TT_SUBQUERY_END, 82 self::TT_AND_LEXEME, 83 self::TT_OR_LEXEME, 84 self::TT_NOT_LEXEME, 85 self::TT_TO_LEXEME, 86 self::TT_NUMBER 87 ); 88 } 89 90 91 /** 92 * TokenCategories 93 */ 94 const TC_WORD = 0; // Word 95 const TC_PHRASE = 1; // Phrase (one or several quoted words) 96 const TC_NUMBER = 2; // Nubers, which are used with syntax elements. Ex. roam~0.8 97 const TC_SYNTAX_ELEMENT = 3; // + - ( ) [ ] { } ! || && ~ ^ 98 99 100 /** 101 * Token type. 102 * 103 * @var integer 104 */ 105 public $type; 106 107 /** 108 * Token text. 109 * 110 * @var integer 111 */ 112 public $text; 113 114 /** 115 * Token position within query. 116 * 117 * @var integer 118 */ 119 public $position; 120 121 122 /** 123 * IndexReader constructor needs token type and token text as a parameters. 124 * 125 * @param integer $tokenCategory 126 * @param string $tokText 127 * @param integer $position 128 */ 129 public function __construct($tokenCategory, $tokenText, $position) 130 { 131 $this->text = $tokenText; 132 $this->position = $position + 1; // Start from 1 133 134 switch ($tokenCategory) { 135 case self::TC_WORD: 136 if ( strtolower($tokenText) == 'and') { 137 $this->type = self::TT_AND_LEXEME; 138 } else if (strtolower($tokenText) == 'or') { 139 $this->type = self::TT_OR_LEXEME; 140 } else if (strtolower($tokenText) == 'not') { 141 $this->type = self::TT_NOT_LEXEME; 142 } else if (strtolower($tokenText) == 'to') { 143 $this->type = self::TT_TO_LEXEME; 144 } else { 145 $this->type = self::TT_WORD; 146 } 147 break; 148 149 case self::TC_PHRASE: 150 $this->type = self::TT_PHRASE; 151 break; 152 153 case self::TC_NUMBER: 154 $this->type = self::TT_NUMBER; 155 break; 156 157 case self::TC_SYNTAX_ELEMENT: 158 switch ($tokenText) { 159 case ':': 160 $this->type = self::TT_FIELD_INDICATOR; 161 break; 162 163 case '+': 164 $this->type = self::TT_REQUIRED; 165 break; 166 167 case '-': 168 $this->type = self::TT_PROHIBITED; 169 break; 170 171 case '~': 172 $this->type = self::TT_FUZZY_PROX_MARK; 173 break; 174 175 case '^': 176 $this->type = self::TT_BOOSTING_MARK; 177 break; 178 179 case '[': 180 $this->type = self::TT_RANGE_INCL_START; 181 break; 182 183 case ']': 184 $this->type = self::TT_RANGE_INCL_END; 185 break; 186 187 case '{': 188 $this->type = self::TT_RANGE_EXCL_START; 189 break; 190 191 case '}': 192 $this->type = self::TT_RANGE_EXCL_END; 193 break; 194 195 case '(': 196 $this->type = self::TT_SUBQUERY_START; 197 break; 198 199 case ')': 200 $this->type = self::TT_SUBQUERY_END; 201 break; 202 203 case '!': 204 $this->type = self::TT_NOT_LEXEME; 205 break; 206 207 case '&&': 208 $this->type = self::TT_AND_LEXEME; 209 break; 210 211 case '||': 212 $this->type = self::TT_OR_LEXEME; 213 break; 214 215 default: 216 throw new Zend_Search_Lucene_Exception('Unrecognized query syntax lexeme: \'' . $tokenText . '\''); 217 } 218 break; 219 220 case self::TC_NUMBER: 221 $this->type = self::TT_NUMBER; 222 223 default: 224 throw new Zend_Search_Lucene_Exception('Unrecognized lexeme type: \'' . $tokenCategory . '\''); 225 } 226 } 227 } 228
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |