-
Notifications
You must be signed in to change notification settings - Fork 1
/
push.php
39 lines (29 loc) · 942 Bytes
/
push.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require_once dirname(__FILE__) . '/lib/SwiSolr.php';
SwiSolr::autoload('SolrSimpleDocument');
SwiSolr::autoload('SolrSimpleField');
// $solr = SwiSolr::connect('http://127.0.0.1:8080/solr');
$solr = SwiSolr::connect('http://127.0.0.1:9080/solr1/');
$doc = new SolrSimpleDocument(array(
new SolrSimpleField('id', 'blog-6'),
new SolrSimpleField('contentType', 'post'),
new SolrSimpleField('dbId', '6'),
new SolrSimpleField('title', 'this is'),
new SolrSimpleField('content', 'that is')
));
try {
$solr->add($doc);
$solr->commit();
} catch (Exception $e) {
echo $e;
}
/*
* delete the previous data. there is also another function named deleteByQuery.
* but deleteById is safer
*/
// $solr->deleteById('blog-4');
$solr->commit();
/* now optimize the index */
// $solr->optimize();
echo "Successfully added the document";
?>