All pastes #495175 Raw Edit

Unnamed

public php v1 · immutable
·published 2007-05-18 16:40 UTC
rendered paste body
<?phpclass PageModel {	public static function updateIndex( $link, $title, $contents, $id ) {		$index = new Zend_Search_Lucene(fConfig::getInstance()->search_index_location,!file_exists( fConfig::getInstance()->search_index_location . '/segments' ));		$doc = new Zend_Search_Lucene_Document();		$doc->addField(Zend_Search_Lucene_Field::Keyword('pagina', 'p'.$id));		$doc->addField(Zend_Search_Lucene_Field::Keyword('link', $link));		$doc->addField(Zend_Search_Lucene_Field::Text('title', $title));		$doc->addField(Zend_Search_Lucene_Field::Unstored('contents', $contents));		$index->addDocument( $doc );		$index->commit();	}		public function deleteFromIndex($id) {		$index = new Zend_Search_Lucene(fConfig::getInstance()->search_index_location);		$hits = $index->find('pagina:"p'.$id.'"');		foreach ( $hits as $hit ) {			$index->delete($hit->id);			$index->commit();		}	}}if ( isset( $params['index'] ) ) {	$res = $db->query( 'SELECT * FROM paginas' );	while( $rec = $res->fetchRow() ) {		Page::updateIndex($rec->friendly_url,$rec->titel,$rec->inhoud, $rec->id);	}} if ( isset( $params['delete'] ) ) {	Page::deleteFromIndex($params['delete']);}$index = new Zend_Search_Lucene(fConfig::getInstance()->search_index_location);$query = 'a';$hits = $index->find($query);echo "Index contains ".$index->count()." documents.<br/><br/>";echo "Search for '".$query."' returned " .count($hits). " hits<br/><br/>";foreach ($hits as $hit) {	?>	<div style="border-bottom:1px solid black;">	<?php		echo "<h5 style='margin:0;padding:0;'>".$hit->title."</h5><br/>";		echo "\tScore: ".sprintf('%.2f', $hit->score)."<br/>";		//echo "\t".$hit->link."\n\n";		echo '<a href="?delete='.urlencode( $hit->pagina ).'">delete</a>'; 		?>	</div>	<?php}?>