Example SRW Query
EXAMPLE JUNIT TEST QUERY
public void testQuery2() { final int startRecord = 1; final int pageSize = 20; final String expectedRoot = "attribution"; final int expectedNumOfRecs = 5008;
this.setCql("echase_alinari.information_carrier.attribution.actor.name = \"*Alinari*\" or echase_alinari.information_carrier.description = \"*Small*\""); this.setXpath("/information_carrier/attribution | /information_carrier/attribution/*"); this.setSchema("echase_alinari"); this.setStartRecord(startRecord); this.setPageSize(pageSize);
SearchRetrieveRequest request = this.buildSearchRetrieveRequest(); SearchRetrieveResponse response = this.runStandardSRWTest();
// check general response details according to request checkResponse(request, response); // check number of records is as expected checkNumberOfRecords(response, expectedNumOfRecs); // check that the records are packed as expected checkRecords(request, response, expectedRoot); }
NON-CONTENT QUERY
CREATE TEMPORARY TABLE `tempresultset` ( `resultsetid` varchar(32) NOT NULL default , `id` varchar(255) NOT NULL default , `distance` double default '0', `position` int(11) NOT NULL auto_increment,PRIMARY KEY (`position`))
ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
INSERT INTO tempresultset (resultsetid, id)
SELECT DISTINCT
"19722d835d27b82402effa230758024b" as resultsetid,
info_carr_attr.id as info_carr_attr__id
FROM attribution as info_carr_attr
LEFT OUTER JOIN information_carrier as information_carrier on information_carrier.id = info_carr_attr.information_carrier_id
LEFT OUTER JOIN actor as info_carr_attr_acto on info_carr_attr.actor_id = info_carr_attr_acto.id
WHERE info_carr_attr_acto.name LIKE "%Alinari%" OR information_carrier.description LIKE "%Small%"
ORDER BY info_carr_attr__id;
INSERT INTO resultset (resultsetid, id, distance, position) SELECT * FROM tempresultset;
INSERT INTO savedresultsets (resultsetid, time) VALUES ('19722d835d27b82402effa230758024b', now());
CREATE TEMPORARY TABLE results
SELECT DISTINCT
resultset.position as resultset__position,
info_carr_attr.id as info_carr_attr__id,
info_carr_attr_acto.id as info_carr_attr_acto__id,
info_carr_attr_acto.name as info_carr_attr_acto__name,
info_carr_attr_time.id as info_carr_attr_time__id
FROM attribution as info_carr_attr
LEFT OUTER JOIN time_span as info_carr_attr_time on info_carr_attr.date_id = info_carr_attr_time.id
LEFT OUTER JOIN actor as info_carr_attr_acto on info_carr_attr.actor_id = info_carr_attr_acto.id
INNER JOIN resultset on resultset.id = info_carr_attr.id
WHERE (resultset.position > 20 AND resultset.position <= 40 AND
resultset.resultsetid = '19722d835d27b82402effa230758024b');
SELECT * FROM results ORDER BY resultset__position;
SELECT COUNT(DISTINCT id) FROM resultset WHERE resultsetid = '19722d835d27b82402effa230758024b';
DROP TABLE tempresultset;
DROP TABLE results;
EXAMPLE CONTENT QUERY
CREATE TEMPORARY TABLE `tempresultset` ( `resultsetid` varchar(32) NOT NULL default , `id` varchar(255) NOT NULL default , `distance` double default '0', `position` int(11) NOT NULL auto_increment, PRIMARY KEY (`position`))
ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
CREATE TEMPORARY TABLE content_query
SELECT DISTINCT
info_carr_attr.id as info_carr_attr__id,
representation.id as rep_id
-- the representation.id as rep_id are named according to the result of getRepresentationId(Schema_maping) in SchemaMappingUtils
FROM attribution as info_carr_attr
LEFT OUTER JOIN information_carrier as information_carrier on information_carrier.id = info_carr_attr.information_carrier_id
LEFT OUTER JOIN actor as info_carr_attr_acto on info_carr_attr.actor_id = info_carr_attr_acto.id
--JOIN representation table to root table (in this example attribution) here
--Use getRepresentationId(Schema_maping) in SchemaMappingUtils to find the rep id column element
WHERE info_carr_attr_acto.name LIKE "%Alinari%" OR information_carrier.description LIKE "%Small%";
-- Pass list of rep_ids to media engine for sorting
-- Join returned list of rep_ids and distances to content_query
-- Insert the result of this join into tempresultset ordering by distance INSERT INTO tempresultset (resultsetid, id) SELECT DISTINCT "19722d835d27b82402effa230758024b" as resultsetid, info_carr_attr__id, rep_id, distance FROM content_query_results ORDER BY distance;
INSERT INTO resultset (resultsetid, id, distance, position)
SELECT * FROM tempresultset;
INSERT INTO savedresultsets (resultsetid, time) VALUES ('19722d835d27b82402effa230758024b', now());
CREATE TEMPORARY TABLE results
SELECT DISTINCT
resultset.position as resultset__position,
info_carr_attr.id as info_carr_attr__id,
info_carr_attr_acto.id as info_carr_attr_acto__id,
info_carr_attr_acto.name as info_carr_attr_acto__name,
info_carr_attr_time.id as info_carr_attr_time__id,
-- add these 2 in if required
representationid,
distance
FROM attribution as info_carr_attr
LEFT OUTER JOIN time_span as info_carr_attr_time on info_carr_attr.date_id = info_carr_attr_time.id
LEFT OUTER JOIN actor as info_carr_attr_acto on info_carr_attr.actor_id = info_carr_attr_acto.id
INNER JOIN resultset on resultset.id = info_carr_attr.id
WHERE (resultset.position > 20 AND resultset.position <= 40 AND
resultset.resultsetid = '19722d835d27b82402effa230758024b');
SELECT * FROM results ORDER BY resultset__position;
SELECT COUNT(DISTINCT id) FROM resultset WHERE resultsetid = '19722d835d27b82402effa230758024b';
DROP TABLE tempresultset;
DROP TABLE results;