Koha/admin/searchengine/solr/indexes.pl
Jonathan Druart 623f3a2c84 Bug 8233 : SearchEngine: Add a Koha::SearchEngine module
First draft introducing solr into Koha :-)

List of files :
  $ tree t/searchengine/
  t/searchengine
  |-- 000_conn
  |   `-- conn.t
  |-- 001_search
  |   `-- search_base.t
  |-- 002_index
  |   `-- index_base.t
  |-- 003_query
  |   `-- buildquery.t
  |-- 004_config
  |   `-- load_config.t
  `-- indexes.yaml
  just do `prove -r t/searchengine/**/*.t`

  t/lib
  |-- Mocks
  |   `-- Context.pm
  `-- Mocks.pm
  provide a mock to SearchEngine syspref (set_zebra and set_solr).

  $ tree Koha/SearchEngine
  Koha/SearchEngine
  |-- Config.pm
  |-- ConfigRole.pm
  |-- FacetsBuilder.pm
  |-- FacetsBuilderRole.pm
  |-- Index.pm
  |-- IndexRole.pm
  |-- QueryBuilder.pm
  |-- QueryBuilderRole.pm
  |-- Search.pm
  |-- SearchRole.pm
  |-- Solr
  |   |-- Config.pm
  |   |-- FacetsBuilder.pm
  |   |-- Index.pm
  |   |-- QueryBuilder.pm
  |   `-- Search.pm
  |-- Solr.pm
  |-- Zebra
  |   |-- QueryBuilder.pm
  |   `-- Search.pm
  `-- Zebra.pm

How to install and configure Solr ?
  See the wiki page: http://wiki.koha-community.org/wiki/SearchEngine_Layer_RFC

http://bugs.koha-community.org/show_bug.cgi?id=8233
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
2012-07-06 16:51:58 +02:00

103 lines
3.3 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2012 BibLibre SARL
#
# This file is part of Koha.
#
# Koha 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 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use CGI;
use C4::Koha;
use C4::Output;
use C4::Auth;
use Koha::SearchEngine;
my $input = new CGI;
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{
template_name => 'admin/searchengine/solr/indexes.tt',
query => $input,
type => 'intranet',
# authnotrequired => 0,
# flagsrequired => { reserveforothers => "place_holds" }, #TODO
}
);
my $ressource_type = $input->param('ressource_type') || 'biblio';
my $se = Koha::SearchEngine->new;
my $se_config = $se->config;
my $indexes;
if ( $input->param('op') and $input->param('op') eq 'edit' ) {
my @code = $input->param('code');
my @label = $input->param('label');
my @type = $input->param('type');
my @sortable = $input->param('sortable');
my @facetable = $input->param('facetable');
my @mandatory = $input->param('mandatory');
my @ressource_type = $input->param('ressource_type');
my @mappings = $input->param('mappings');
my @indexes;
my @errors;
for ( 0 .. @code-1 ) {
my $icode = $code[$_];
my @current_mappings = split /\r\n/, $mappings[$_];
if ( not @current_mappings ) {
@current_mappings = split /\n/, $mappings[$_];
}
if ( not @current_mappings ) {
push @errors, { type => 'no_mapping', value => $icode};
}
push @indexes, {
code => $icode,
label => $label[$_],
type => $type[$_],
sortable => scalar(grep(/^$icode$/, @sortable)),
facetable => scalar(grep(/^$icode$/, @facetable)),
mandatory => $mandatory[$_] eq '1' ? '1' : '0',
ressource_type => $ressource_type[$_],
mappings => \@current_mappings,
};
for my $m ( @current_mappings ) {
push @errors, {type => 'malformed_mapping', value => $m}
if not $m =~ /^\d(\d|\*|\.){2}\$.$/;
}
}
$indexes = \@indexes if @errors;
$template->param( errors => \@errors );
$se_config->indexes(\@indexes) if not @errors;
}
my $ressource_types = $se_config->ressource_types;
$indexes //= $se_config->indexes;
my $indexloop;
for my $rt ( @$ressource_types ) {
my @indexes = map {
$_->{ressource_type} eq $rt ? $_ : ();
} @$indexes;
push @$indexloop, {
ressource_type => $rt,
indexes => \@indexes,
}
}
$template->param(
indexloop => $indexloop,
);
output_html_with_http_headers $input, $cookie, $template->output;