Skip to content

Commit

Permalink
Move searchdb inside app/upload/plugins/xapian/searchdb
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Apr 28, 2015
1 parent 7127f6c commit f36a285
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 76 deletions.
18 changes: 2 additions & 16 deletions .gitignore
Expand Up @@ -17,28 +17,14 @@ courses/*
!courses/index.html

# Home
app/home/*
home/*

# User images
app/upload/users/*
!app/upload/users/index.html

# Session images
app/upload/sessions/*
!main/upload/sessions/index.html

# Course images
app/upload/courses/*
!app/upload/courses/index.html
# Upload content
app/upload/*

# Logs and databases #
*.log

# Xapian indexes directory
searchdb/*
!searchdb/index.html

# IDE settings

.idea
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -40,7 +40,7 @@ before_script:
- cp chamilo-cli-install/chamilo-cli-installer.php main/install/
- mysql -u root -e 'create database chamilo'
# install Chamilo with Chash - see reference https://github.com/sonnym/travis-ci-drupal-module-example/blob/master/.travis.yml
- sudo chmod -R 0777 app/cache courses home app/upload/ main/default_course_document/images main/inc/conf searchdb main/lang main/css
- sudo chmod -R 0777 app/config app/cache app/courses home app/upload/ main/default_course_document/images main/lang main/css
- cd main/install/
- sudo php5 chamilo-cli-installer.php -l admin -p admin -U travis -u 'http://localhost/' -X travis -L english -z 'admin@example.com' -f 'John' -g 'Doe' -b '555-5555' -c 'Test campus' -y 'Chamilo' -x 'https://chamilo.org'
- cd ../..
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -59,7 +59,7 @@ composer update

On a Debian-based system, launch:
```
sudo chown -R www-data:www-data app/cache course home searchdb app/upload/users app/upload/sessions app/upload/courses main/default_course_document/images main/lang main/css main/inc/conf
sudo chown -R www-data:www-data app/cache app/config app/course home app/upload main/default_course_document/images main/lang main/css
```

### Start the installer
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion main/admin/settings.lib.php
Expand Up @@ -656,7 +656,7 @@ function handle_search()
echo '</div>';

if ($search_enabled == 'true') {
$xapian_path = api_get_path(SYS_PATH).'searchdb';
$xapian_path = api_get_path(SYS_UPLOAD_PATH).'plugins/xapian/searchdb';

/*
@todo Test the Xapian connection
Expand Down
19 changes: 10 additions & 9 deletions main/inc/lib/search/IndexableChunk.class.php
@@ -1,12 +1,10 @@
<?php

/* For licensing terms, see /license.txt */

/**
* @package chamilo.include.search
*/
/**
* Code
*/

// some constants to avoid serialize string keys on serialized data array
define('SE_COURSE_ID', 0);
define('SE_TOOL_ID', 1);
Expand All @@ -25,7 +23,8 @@
* Class
* @package chamilo.include.search
*/
abstract class _IndexableChunk {
abstract class _IndexableChunk
{
/* struct (array)
* {
* string title; <- nombre de archivo/elemento
Expand Down Expand Up @@ -97,20 +96,22 @@ function __destruct() {
* Extension of the _IndexableChunk class to make IndexableChunk extensible.
* @package chamilo.include.search
*/
class IndexableChunk extends _IndexableChunk {
class IndexableChunk extends _IndexableChunk
{

/**
* Let add course id term
*/
public function addCourseId($course_id) {
public function addCourseId($course_id)
{
$this->addTerm($course_id, XAPIAN_PREFIX_COURSEID);
}

/**
* Let add tool id term
*/
public function addToolId($tool_id) {
public function addToolId($tool_id)
{
$this->addTerm($tool_id, XAPIAN_PREFIX_TOOLID);
}

}
85 changes: 50 additions & 35 deletions main/inc/lib/search/xapian/XapianIndexer.class.php
@@ -1,12 +1,9 @@
<?php

/* For licensing terms, see /license.txt */

/**
* @package chamilo.include.search
*/
/**
* Code
*/

require_once 'xapian.php';
require_once dirname(__FILE__) . '/../IndexableChunk.class.php';
Expand All @@ -15,7 +12,8 @@
* Abstract helper class
* @package chamilo.include.search
*/
abstract class XapianIndexer {
abstract class XapianIndexer
{
/* XapianWritableDatabase */

protected $db;
Expand All @@ -26,14 +24,24 @@ abstract class XapianIndexer {
/* XapianStem */
public $stemmer;

/**
* Class contructor
*/
function __construct()
{
$this->db = null;
$this->stemmer = null;
}

/**
* Generates a list of languages Xapian manages
*
* This method enables the definition of more matches between
* Chamilo languages and Xapian languages (through hardcoding)
* @return array Array of languages codes -> Xapian languages
*/
public final function xapian_languages() {
public final function xapian_languages()
{
/* http://xapian.org/docs/apidoc/html/classXapian_1_1Stem.html */
return array(
'none' => 'none', //don't stem terms
Expand All @@ -60,14 +68,15 @@ public final function xapian_languages() {
/**
* Connect to the database, and create it if it doesn't exist
*/
function connectDb($path = NULL, $dbMode = NULL, $lang = 'english') {
if ($this->db != NULL)
function connectDb($path = null, $dbMode = null, $lang = 'english')
{
if ($this->db != null)
return $this->db;
if ($dbMode == NULL)
if ($dbMode == null)
$dbMode = Xapian::DB_CREATE_OR_OPEN;

if ($path == NULL)
$path = api_get_path(SYS_PATH) . 'searchdb/';
if ($path == null)
$path = api_get_path(SYS_UPLOAD_PATH).'plugins/xapian/searchdb/';

try {
$this->db = new XapianWritableDatabase($path, $dbMode);
Expand All @@ -82,6 +91,7 @@ function connectDb($path = NULL, $dbMode = NULL, $lang = 'english') {
return $this->db;
} catch (Exception $e) {
Display::display_error_message($e->getMessage());

return 1;
}
}
Expand All @@ -90,7 +100,8 @@ function connectDb($path = NULL, $dbMode = NULL, $lang = 'english') {
* Simple getter for the db attribute
* @return object The db attribute
*/
function getDb() {
function getDb()
{
return $this->db;
}

Expand All @@ -99,16 +110,18 @@ function getDb() {
* @param string Chunk of text
* @return void
*/
function addChunk($chunk) {
function addChunk($chunk)
{
$this->chunks[] = $chunk;
}

/**
* Actually index the current data
*
* @return integer New Xapian document ID or NULL upon failure
* @return integer New Xapian document ID or null upon failure
*/
function index() {
function index()
{
try {
if (!empty($this->chunks)) {
foreach ($this->chunks as $chunk) {
Expand Down Expand Up @@ -148,8 +161,9 @@ function index() {
* @param int did Xapian::docid
* @return mixed XapianDocument, or false on error
*/
function get_document($did) {
if ($this->db == NULL) {
function get_document($did)
{
if ($this->db == null) {
$this->connectDb();
}
try {
Expand All @@ -167,8 +181,9 @@ function get_document($did) {
* @param XapianDocument $doc xapian document to push into the db
* @return mixed xapian document data or FALSE if error
*/
function get_document_data($doc) {
if ($this->db == NULL) {
function get_document_data($doc)
{
if ($this->db == null) {
$this->connectDb();
}
try {
Expand All @@ -191,7 +206,8 @@ function get_document_data($doc) {
* @param string $prefix Prefix used to categorize the doc (usually 'T' for title, 'A' for author)
* @return boolean false on error
*/
function update_terms($did, $terms, $prefix) {
function update_terms($did, $terms, $prefix)
{
$doc = $this->get_document($did);
if ($doc === false) {
return false;
Expand All @@ -203,6 +219,7 @@ function update_terms($did, $terms, $prefix) {
}
$this->db->replace_document($did, $doc);
$this->db->flush();

return true;
}

Expand All @@ -211,8 +228,9 @@ function update_terms($did, $terms, $prefix) {
*
* @param int did Xapian::docid
*/
function remove_document($did) {
if ($this->db == NULL) {
function remove_document($did)
{
if ($this->db == null) {
$this->connectDb();
}
if (is_numeric($did) && $did > 0) {
Expand All @@ -231,7 +249,8 @@ function remove_document($did) {
* @param XapianDocument $doc The xapian document where to add the term
* @return mixed XapianDocument, or false on error
*/
function add_term_to_doc($term, $doc) {
function add_term_to_doc($term, $doc)
{
if (!is_a($doc, 'XapianDocument')) {
return FALSE;
}
Expand All @@ -250,7 +269,8 @@ function add_term_to_doc($term, $doc) {
* @param XapianDocument $doc The xapian document where to add the term
* @return mixed XapianDocument, or false on error
*/
function remove_term_from_doc($term, $doc) {
function remove_term_from_doc($term, $doc)
{
if (!is_a($doc, 'XapianDocument')) {
return FALSE;
}
Expand All @@ -268,11 +288,12 @@ function remove_term_from_doc($term, $doc) {
* @param XapianDocument $doc xapian document to push into the db
* @param Xapian::docid $did xapian document id of the document to replace
*/
function replace_document($doc, $did) {
function replace_document($doc, $did)
{
if (!is_a($doc, 'XapianDocument')) {
return FALSE;
}
if ($this->db == NULL) {
if ($this->db == null) {
$this->connectDb();
}
try {
Expand All @@ -284,20 +305,14 @@ function replace_document($doc, $did) {
}
}

/**
* Class contructor
*/
function __construct() {
$this->db = NULL;
$this->stemmer = NULL;
}

/**
* Class destructor
*/
function __destruct() {
function __destruct()
{
unset($this->db);
unset($this->stemmer);
}

}
}
2 changes: 1 addition & 1 deletion main/inc/lib/search/xapian/XapianQuery.php
Expand Up @@ -12,7 +12,7 @@
//TODO: think another way without including specific fields here
require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php';

define('XAPIAN_DB', api_get_path(SYS_PATH) . 'searchdb/');
define('XAPIAN_DB', api_get_path(SYS_UPLOAD_PATH) . 'plugins/xapian/searchdb/');

/**
* Queries the database.
Expand Down
2 changes: 2 additions & 0 deletions main/install/update-files-1.9.0-1.10.0.inc.php
Expand Up @@ -86,6 +86,7 @@
'xhosa',
'yoruba',
);

$filesToDelete = array(
'accessibility',
'admin',
Expand Down Expand Up @@ -169,6 +170,7 @@
api_get_path(SYS_CODE_PATH).'upload/users' => api_get_path(SYS_UPLOAD_PATH).'users',
api_get_path(SYS_CODE_PATH).'upload/badges' => api_get_path(SYS_UPLOAD_PATH).'badges',
api_get_path(SYS_PATH).'courses' => api_get_path(SYS_COURSE_PATH),
api_get_path(SYS_PATH).'searchdb' => api_get_path(SYS_UPLOAD_PATH).'plugins/xapian/searchdb',
];

foreach ($movePathList as $origin => $destination) {
Expand Down

0 comments on commit f36a285

Please sign in to comment.