Zend Framework Source Code Snippets

Zend_Search_Lucene simple index script

Bookmark and Share
1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
29
3031
32
33
34
3536
37
38
39
4041
42
43
44
4546
47
48
49
5051
52
// Foreach snippet
 
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application/'));
 
set_include_path(    APPLICATION_PATH . '/../library'
    . PATH_SEPARATOR . get_include_path()
);
 
require_once "Zend/Loader.php";Zend_Loader::registerAutoload();
 
try {
    require '../application/bootstrap.php';
} catch (Exception $exception) {    echo 'Bootstrapping failed' . $exception->getMessage();
    exit(1);
}
 
 require_once APPLICATION_PATH . '/models/Snippet.php';
$model = new Model_Snippet;
$model->setUsePaginator(false);
 
$client = new Zend_Http_Client();$client->setConfig(array(
    'maxredirects' => 0,
    'timeout'      => 30));
 
if (is_file(APPLICATION_PATH . '/data/search/index')) {    $index = Zend_Search_Lucene::open(APPLICATION_PATH . '/../data/search/index');
} else {
    $index = Zend_Search_Lucene::create(APPLICATION_PATH . '/../data/search/index');
}
 foreach($model->fetch() as $snip) {
    $url = Zend_Registry::get('configuration')->app->url . 'snippets/view/id/' . $snip->snippet_id;
    $client->setUri($url);
    $response = $client->request();
     if ($response->isSuccessful()) {
        $doc = Zend_Search_Lucene_Document_Html::loadHTML($response->getBody());
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('indexed', time())); 
        $doc->addField(Zend_Search_Lucene_Field::UnIndexed('id', $snip->snippet_id));
         $index->addDocument($doc);
    }
}
 
$index->commit(); 
echo $index->count(), " Documents indexed.", PHP_EOL;

Comments

You must login before commenting on a snippet. If you do not have an account, please register.

Snippet description

This is the script I knocked up for the coming soon site search.

Snippet details

Created:
davedevelopment davedevelopment
2 years ago
Edited:
davedevelopment davedevelopment
2 years ago
Revision Id:
87
Edit Message:
Initial Release
Tags:
search script Zend_Search_Lucene
Comments:
0
Views:
1171
Points:
1 (1 votes)

History

r87

Initial Release

davedevelopment davedevelopment
2 years ago