[open-ils-commits] r16904 - in trunk/Open-ILS: examples src/perlmods/OpenILS/Application/Search src/perlmods/OpenILS/Application/Storage/Driver/Pg src/sql/Pg src/sql/Pg/upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Jul 11 19:35:01 EDT 2010
Author: miker
Date: 2010-07-11 19:35:00 -0400 (Sun, 11 Jul 2010)
New Revision: 16904
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0330.schema.facet_entry_table.sql
Modified:
trunk/Open-ILS/examples/fm_IDL.xml
trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/030.schema.metabib.sql
Log:
break facets out to a separate table for speed
Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml 2010-07-09 21:58:33 UTC (rev 16903)
+++ trunk/Open-ILS/examples/fm_IDL.xml 2010-07-11 23:35:00 UTC (rev 16904)
@@ -2156,26 +2156,10 @@
<link field="metarecord" reltype="has_a" key="id" map="" class="mmr"/>
</links>
</class>
- <class id="mfae" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="metabib::facet_entry" reporter:label="Combined Facet Entry View" oils_persist:readonly="true">
- <oils_persist:source_definition>
- SELECT * FROM (
- SELECT * FROM metabib.author_field_entry
- UNION ALL
- SELECT * FROM metabib.keyword_field_entry
- UNION ALL
- SELECT * FROM metabib.identifier_field_entry
- UNION ALL
- SELECT * FROM metabib.title_field_entry
- UNION ALL
- SELECT * FROM metabib.subject_field_entry
- UNION ALL
- SELECT * FROM metabib.series_field_entry
- )x
- WHERE x.index_vector = ''
- </oils_persist:source_definition>
- <fields>
- <field name="field" reporter:datatype="link"/>
+ <class id="mfae" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="metabib::facet_entry" oils_persist:tablename="metabib.facet_entry" reporter:label="Combined Facet Entry" oils_persist:readonly="true">
+ <fields oils_persist:primary="id" oils_persist:sequence="metabib.facet_entry_id_seq">
<field name="id" reporter:datatype="id" />
+ <field name="field" reporter:datatype="link"/>
<field name="source" reporter:datatype="link"/>
<field name="value" reporter:datatype="text"/>
</fields>
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm 2010-07-09 21:58:33 UTC (rev 16903)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm 2010-07-11 23:35:00 UTC (rev 16904)
@@ -1359,12 +1359,10 @@
},
from => {
mfae => {
- cmf => { field => 'id', fkey => 'field' },
mmrsm => { field => 'source', fkey => 'source' }
}
},
where => {
- '+cmf' => 'facet_field',
'+mmrsm' => { $count_field => $results }
}
}
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm 2010-07-09 21:58:33 UTC (rev 16903)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm 2010-07-11 23:35:00 UTC (rev 16904)
@@ -650,7 +650,7 @@
my $table = $node->table;
my $talias = $node->table_alias;
- $from .= "\n\tJOIN (\n\t\tSELECT * /* facet */\n\t\t FROM $table\n\t\t WHERE index_vector = ''::TSVECTOR AND ".
+ $from .= "\n\tJOIN (\n\t\tSELECT * /* facet */\n\t\t FROM metabib.facet_entry\n\t\t WHERE ".
"SUBSTRING(value,1,1024) IN (" . join(",", map { $self->QueryParser->quote_value($_) } @{$node->values}) . ")".
"\n\t\t\tAND field IN (SELECT id FROM config.metabib_field WHERE field_class = ". $self->QueryParser->quote_value($node->classname) ." AND facet_field";
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-07-09 21:58:33 UTC (rev 16903)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-07-11 23:35:00 UTC (rev 16904)
@@ -68,7 +68,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0329'); -- dbs
+INSERT INTO config.upgrade_log (version) VALUES ('0330'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/030.schema.metabib.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/030.schema.metabib.sql 2010-07-09 21:58:33 UTC (rev 16903)
+++ trunk/Open-ILS/src/sql/Pg/030.schema.metabib.sql 2010-07-11 23:35:00 UTC (rev 16904)
@@ -125,6 +125,17 @@
CREATE INDEX metabib_series_field_entry_source_idx ON metabib.series_field_entry (source);
+CREATE TABLE metabib.facet_entry (
+ id BIGSERIAL PRIMARY KEY,
+ source BIGINT NOT NULL,
+ field INT NOT NULL,
+ value TEXT NOT NULL
+);
+CREATE INDEX metabib_facet_entry_field_idx ON metabib.facet_entry (field);
+CREATE INDEX metabib_facet_entry_value_idx ON metabib.facet_entry (SUBSTRING(value,1,1024));
+CREATE INDEX metabib_facet_entry_source_idx ON metabib.facet_entry (source);
+
+
CREATE TABLE metabib.rec_descriptor (
id BIGSERIAL PRIMARY KEY,
record BIGINT,
@@ -736,29 +747,29 @@
DECLARE
fclass RECORD;
ind_data metabib.field_entry_template%ROWTYPE;
- ind_vector TSVECTOR;
BEGIN
FOR fclass IN SELECT * FROM config.metabib_class LOOP
-- RAISE NOTICE 'Emptying out %', fclass.name;
EXECUTE $$DELETE FROM metabib.$$ || fclass.name || $$_field_entry WHERE source = $$ || bib_id;
END LOOP;
+ DELETE FROM metabib.facet_entry WHERE source = bib_id;
+
FOR ind_data IN SELECT * FROM biblio.extract_metabib_field_entry( bib_id ) LOOP
IF ind_data.field < 0 THEN
- ind_vector = '';
ind_data.field = -1 * ind_data.field;
+ INSERT INTO metabib.facet_entry (field, source, value)
+ VALUES (ind_data.field, ind_data.source, ind_data.value);
ELSE
- ind_vector = NULL;
+ EXECUTE $$
+ INSERT INTO metabib.$$ || ind_data.field_class || $$_field_entry (field, source, value)
+ VALUES ($$ ||
+ quote_literal(ind_data.field) || $$, $$ ||
+ quote_literal(ind_data.source) || $$, $$ ||
+ quote_literal(ind_data.value) ||
+ $$);$$;
END IF;
- EXECUTE $$
- INSERT INTO metabib.$$ || ind_data.field_class || $$_field_entry (field, source, value, index_vector)
- VALUES ($$ ||
- quote_literal(ind_data.field) || $$, $$ ||
- quote_literal(ind_data.source) || $$, $$ ||
- quote_literal(ind_data.value) || $$, $$ ||
- COALESCE(quote_literal(ind_vector),'NULL'::TEXT) ||
- $$);$$;
END LOOP;
RETURN;
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0330.schema.facet_entry_table.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0330.schema.facet_entry_table.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0330.schema.facet_entry_table.sql 2010-07-11 23:35:00 UTC (rev 16904)
@@ -0,0 +1,73 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0330');
+
+CREATE TABLE metabib.facet_entry (
+ id BIGSERIAL PRIMARY KEY,
+ source BIGINT NOT NULL,
+ field INT NOT NULL,
+ value TEXT NOT NULL
+);
+
+INSERT INTO metabib.facet_entry (source, field, value)
+ SELECT source, field, value FROM (
+ SELECT source, field, value FROM metabib.author_field_entry
+ UNION ALL
+ SELECT source, field, value FROM metabib.keyword_field_entry
+ UNION ALL
+ SELECT source, field, value FROM metabib.identifier_field_entry
+ UNION ALL
+ SELECT source, field, value FROM metabib.title_field_entry
+ UNION ALL
+ SELECT source, field, value FROM metabib.subject_field_entry
+ UNION ALL
+ SELECT source, field, value FROM metabib.series_field_entry
+ )x
+ WHERE x.index_vector = '';
+
+DELETE FROM metabib.author_field_entry WHERE index_vector = '';
+DELETE FROM metabib.keyword_field_entry WHERE index_vector = '';
+DELETE FROM metabib.identifier_field_entry WHERE index_vector = '';
+DELETE FROM metabib.title_field_entry WHERE index_vector = '';
+DELETE FROM metabib.subject_field_entry WHERE index_vector = '';
+DELETE FROM metabib.series_field_entry WHERE index_vector = '';
+
+CREATE INDEX metabib_facet_entry_field_idx ON metabib.facet_entry (field);
+CREATE INDEX metabib_facet_entry_value_idx ON metabib.facet_entry (SUBSTRING(value,1,1024));
+CREATE INDEX metabib_facet_entry_source_idx ON metabib.facet_entry (source);
+
+CREATE OR REPLACE FUNCTION metabib.reingest_metabib_field_entries( bib_id BIGINT ) RETURNS VOID AS $func$
+DECLARE
+ fclass RECORD;
+ ind_data metabib.field_entry_template%ROWTYPE;
+BEGIN
+ FOR fclass IN SELECT * FROM config.metabib_class LOOP
+ -- RAISE NOTICE 'Emptying out %', fclass.name;
+ EXECUTE $$DELETE FROM metabib.$$ || fclass.name || $$_field_entry WHERE source = $$ || bib_id;
+ END LOOP;
+
+ DELETE FROM metabib.facet_entry WHERE source = bib_id;
+
+ FOR ind_data IN SELECT * FROM biblio.extract_metabib_field_entry( bib_id ) LOOP
+ IF ind_data.field < 0 THEN
+ ind_data.field = -1 * ind_data.field;
+ INSERT INTO metabib.facet_entry (field, source, value)
+ VALUES (ind_data.field, ind_data.source, ind_data.value);
+ ELSE
+ EXECUTE $$
+ INSERT INTO metabib.$$ || ind_data.field_class || $$_field_entry (field, source, value)
+ VALUES ($$ ||
+ quote_literal(ind_data.field) || $$, $$ ||
+ quote_literal(ind_data.source) || $$, $$ ||
+ quote_literal(ind_data.value) ||
+ $$);$$;
+ END IF;
+
+ END LOOP;
+
+ RETURN;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+COMMIT;
+
More information about the open-ils-commits
mailing list