Skip to content

Instantly share code, notes, and snippets.

View prateeksachan's full-sized avatar
🖖

Prateek Sachan prateeksachan

🖖
View GitHub Profile
@prateeksachan
prateeksachan / pre-commit
Created January 13, 2017 05:31 — forked from chelmertz/pre-commit
pre-commit hook for git, running php lint
#!/usr/bin/php
<?php
// copied from http://phpadvent.org/2008/dont-commit-that-error-by-travis-swicegood
// authored by Travis Swicegood
$output = array();
$return = 0;
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return);
$against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
<?php
require_once( 'bootstrap.php' );//solr connection settings
//This is the running solr server at 127.0.0.1:8983 as defined in bootstrap.php
$options = array( 'hostname' => SOLR_SERVER_HOSTNAME );
// Try to connect to the named server, port, and url
$client = new SolrClient($options);
if (!$client->ping()) {
exit ('Solr service not responding.');
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@prateeksachan
prateeksachan / globalsearch_testcase.php
Last active December 23, 2015 03:39
PHP Unit test for globalsearch
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
<?php
$url = search_curl_url(); // returns SOLR_SERVER_HOSTNAME . ':' . SOLR_SERVER_PORT . '/solr/update/extract?'
$url .= 'literal.id=' . 'forum_file_' . $id . '&literal.module=forum&literal.type=3&literal.courseid=' . $post->course;
$params = array();
$params[$id] = $file; // adds the $file stdClass object into $params array
$curl->post($url, $params); // sets CURLOPT_POST = 1
// sets CURLOPT_POSTFIELDS = array ($id => '@' . $filepath) via add_to_curl_request
// finally posts this curl request
?>
<?php
//get a chapter's records for each chapter id
$chapter = $DB->get_record('book_chapters', array('id' => $id), '*', MUST_EXIST);
//get book record for that chapter
$book = $DB->get_record('book', array('id' => $chapter->bookid), '*', MUST_EXIST);
$doc = new SolrInputDocument();
$doc->addField('id', 'book_' . $chapter->id);
$doc->addField('name', $book->name);
<?php
foreach ($mods as $key => $name) {
set_config($name . '_indexingstart', 0, 'search');
set_config($name . '_indexingend', 0, 'search');
set_config($name . '_lastindexrun', 0, 'search');
set_config($name . '_docsignored', 0, 'search');
set_config($name . '_docsprocessed', 0, 'search');
set_config($name . '_recordsprocessed', 0, 'search');
}
?>
<?php
function mod_get_search_iterator($from = 0) {
global $DB;
$sql = "SELECT id, modified FROM {mod_table} WHERE modified >= ? ORDER BY modified ASC";
return $DB->get_recordset_sql($sql, array($from));
}
?>
$s = '';
$s.= '<add>';
for ($id = 1; $id <=1000; $id++){
$s.= '<doc>';
$s.= '<field name="id">' . $id . '</field>';
$s.= '<field name="courseid" update="set">2</field>';
$s.= '</doc>';
}
$s.= '</add>';
[response] => SolrObject Object
(
[numFound] => 3
[start] => 0
[docs] => Array
(
[0] => SolrObject Object
(
[id] => 1
[title] => Array