<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>
},
from => {
mfae => {
- cmf => { field => 'id', fkey => 'field' },
mmrsm => { field => 'source', fkey => 'source' }
}
},
where => {
- '+cmf' => 'facet_field',
'+mmrsm' => { $count_field => $results }
}
}
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";
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,
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,
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;
--- /dev/null
+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;
+