Changeset 10529
- Timestamp:
- 07/31/08 07:12:36 (2 years ago)
- Files:
-
- plugins/sfSearchPlugin/trunk/lib/lexer/lucene/xfLexemeLucene.class.php (modified) (3 diffs)
- plugins/sfSearchPlugin/trunk/lib/lexer/xfLexeme.class.php (modified) (1 diff)
- plugins/sfSearchPlugin/trunk/lib/lexer/xfLexemeBuilder.class.php (modified) (1 diff)
- plugins/sfSearchPlugin/trunk/test/unit/lexer/lucene/xfLexemeLuceneTest.php (added)
- plugins/sfSearchPlugin/trunk/test/unit/lexer/lucene/xfLexerLuceneTest.php (modified) (3 diffs)
- plugins/sfSearchPlugin/trunk/test/unit/lexer/xfLexemeBuilderTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfSearchPlugin/trunk/lib/lexer/lucene/xfLexemeLucene.class.php
r10409 r10529 9 9 10 10 /** 11 * A Lexeme that follows Lucene rules.11 * A Lexeme with Lucene types. 12 12 * 13 13 * @package sfSearch … … 15 15 * @author Carl Vondrick 16 16 */ 17 class xfLexemeLucene extends xfLexeme17 final class xfLexemeLucene extends xfLexeme 18 18 { 19 const WORD = 1; 20 const SYNTAX = 2; 19 21 const PHRASE = 3; 20 22 const NUMBER = 4; 21 23 const FIELD = 5; 24 const WILDCARD = 6; 25 const RANGE_START_INCLUSIVE = 100; 26 const RANGE_START_EXCLUSIVE = 101; 27 const RANGE_END_INCLUSIVE = 102; 28 const RANGE_END_EXCLUSIVE = 103; 29 const RANGE_SEPARATOR = 104; 22 30 23 31 /** … … 26 34 public function setType($type) 27 35 { 36 $lexeme = strtolower($this->getLexeme()); 37 38 if ($type == self::SYNTAX) 39 { 40 if ($lexeme == '[') 41 { 42 $type = self::RANGE_START_INCLUSIVE; 43 } 44 elseif ($lexeme == '{') 45 { 46 $type = self::RANGE_START_EXCLUSIVE; 47 } 48 elseif ($lexeme == ']') 49 { 50 $type = self::RANGE_END_INCLUSIVE; 51 } 52 elseif ($lexeme == '}') 53 { 54 $type = self::RANGE_END_EXCLUSIVE; 55 } 56 } 57 elseif ($type == self::WORD) 58 { 59 if ($lexeme == 'to') 60 { 61 $type = self::RANGE_SEPARATOR; 62 } 63 elseif ($lexeme == 'and') 64 { 65 $type = self::SYNTAX; 66 } 67 elseif ($lexeme == 'or') 68 { 69 $type = self::SYNTAX; 70 } 71 elseif ($lexeme == 'not') 72 { 73 $type = self::SYNTAX; 74 } 75 elseif (false !== strpos($lexeme, '*') || false !== strpos($lexeme, '?')) 76 { 77 $type = self::WILDCARD; 78 } 79 } 80 28 81 parent::setType($type); 29 82 } plugins/sfSearchPlugin/trunk/lib/lexer/xfLexeme.class.php
r10409 r10529 17 17 class xfLexeme 18 18 { 19 const WORD = 1;20 const SYNTAX = 2;21 22 19 /** 23 20 * The type plugins/sfSearchPlugin/trunk/lib/lexer/xfLexemeBuilder.class.php
r10409 r10529 97 97 $this->position++; 98 98 99 if ( isset($this->characters[$this->position]))99 if (array_key_exists($this->position, $this->characters)) 100 100 { 101 101 return $this->characters[$this->position]; 102 102 } 103 103 104 104 return false; 105 105 } plugins/sfSearchPlugin/trunk/test/unit/lexer/lucene/xfLexerLuceneTest.php
r10409 r10529 24 24 require 'parser/xfParserException.class.php'; 25 25 26 $t = new xfLexerTester(new lime_test(1 62, new lime_output_auto), new xfLexerLucene);26 $t = new xfLexerTester(new lime_test(182, new lime_output_auto), new xfLexerLucene); 27 27 28 28 $t->pass('', array()); … … 85 85 $t->pass('\\+boo', array(array('+boo', xfLexemeLucene::WORD))); 86 86 87 87 88 $t->pass('\\&', array(array('&', xfLexemeLucene::WORD))); 88 89 … … 98 99 99 100 $t->fail('a | b', 'A | must follow a | character.'); 101 102 $t->pass('[1 to 30]', array(array('[', xfLexemeLucene::RANGE_START_INCLUSIVE), 103 array('1', xfLexemeLucene::WORD), 104 array('to', xfLexemeLucene::RANGE_SEPARATOR), 105 array('30', xfLexemeLucene::WORD), 106 array(']', xfLexemeLucene::RANGE_END_INCLUSIVE))); 107 108 $t->pass('m*n', array(array('m*n', xfLexemeLucene::WILDCARD))); 109 110 $t->pass('m?n', array(array('m?n', xfLexemeLucene::WILDCARD))); 111 112 $t->pass('t*s?', array(array('t*s?', xfLexemeLucene::WILDCARD))); 100 113 101 114 $t->pass('(+a || \\b) && f: c && ("foo bar"~2 || (y && +x))^2.5', array(array('(', xfLexemeLucene::SYNTAX), plugins/sfSearchPlugin/trunk/test/unit/lexer/xfLexemeBuilderTest.php
r10409 r10529 13 13 require 'util/xfException.class.php'; 14 14 15 $t = new lime_test( 17, new lime_output_color);15 $t = new lime_test(20, new lime_output_color); 16 16 17 17 $b = new xfLexemeBuilder('symfony pròject'); … … 74 74 $b->commit(); 75 75 $t->is($b->count(), 3, '->commit() does not create a new lexeme if the text is empty'); 76 77 $b = new xfLexemeBuilder('102'); 78 $t->is($b->next(), 1, '->next() works on numbers'); 79 $t->is($b->next(), 0, '->next() works on numbers'); 80 $t->is($b->next(), 2, '->next() works on numbers');

