Created
January 20, 2011 17:08
-
-
Save harikt/788198 to your computer and use it in GitHub Desktop.
Located at models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\models; | |
use \Zend_Search_Lucene, | |
\Zend_Search_Lucene_Document, | |
\Zend_Search_Lucene_Field; | |
class Search extends \lithium\data\Model { | |
public $validates = array(); | |
public $index; | |
public $localUrl = 'http://lithium.local/docs/'; | |
public function makeindex() { | |
$this->index = new Zend_Search_Lucene( __DIR__ . '/../data/search', true); | |
$this->buildsearch("lithium\\"); | |
$this->index->commit(); | |
} | |
public function buildsearch( $name ) { | |
$docFile = 'readme.wiki'; | |
$lib = 'lithium'; | |
$extractor = 'li3_docs\extensions\docs\Extractor'; | |
$options = array('namespaceDoc' => $docFile); | |
$object = $extractor::get($lib, $name, $options); | |
$meta = array(); | |
if (strpos($name, '::') !== false) { | |
list($class, $method) = explode('::', $name, 2); | |
$meta = $extractor::get($lib, $class); | |
} | |
if( is_array( $object['children'] ) ) { | |
foreach( $object['children'] as $key => $value ) { | |
$this->buildsearch( $key ); | |
} | |
} | |
if( $object['type'] == 'class' ) { | |
foreach( $object['methods'] as $method ) { | |
$this->buildsearch( $name . '::' . $method->name . "()"); | |
} | |
if( is_array( $object['properties'] ) ) { | |
foreach( $object['properties'] as $property ) { | |
$this->buildsearch( $name . '::$' . $property['name'] ); | |
} | |
} | |
} | |
if( $object['type'] == 'method' ) { | |
$doc = new Zend_Search_Lucene_Document(); | |
$doc->addField(Zend_Search_Lucene_Field::Keyword( | |
'url', | |
$this->localUrl . str_replace('\\','/',$name) | |
) | |
); | |
$doc->addField(Zend_Search_Lucene_Field::Text( | |
'text', | |
$this->sanitize($object['text']) | |
) | |
); | |
$doc->addField(Zend_Search_Lucene_Field::Text( | |
'description', | |
$object['description'] | |
) | |
); | |
$this->index->addDocument($doc); | |
return; | |
} | |
if( $object['type'] == 'property' ) { | |
$doc = new Zend_Search_Lucene_Document(); | |
$doc->addField(Zend_Search_Lucene_Field::Keyword( | |
'url', | |
$this->localUrl . str_replace('\\','/',$name) | |
) | |
); | |
$doc->addField(Zend_Search_Lucene_Field::Text( | |
'text', | |
$this->sanitize($object['text']) | |
) | |
); | |
$doc->addField(Zend_Search_Lucene_Field::Text( | |
'description', | |
$this->sanitize($object['description']) | |
) | |
); | |
$this->index->addDocument($doc); | |
return; | |
} | |
} | |
public function sanitize($input) { | |
return htmlentities(strip_tags( $input )); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment