Commit 85cb38a3 authored by Dainis Abols's avatar Dainis Abols
Browse files

Solr 8 changes - separated `child` and `subquery` in different calls

v2.9.0
parent d116aa0f
......@@ -244,10 +244,10 @@ class LuisContacts
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', 'person')
->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}')
->orderBy('surname_lv_collated', 'asc')
->limit(SolrLibrary::MAXINT);
->where('type', 'person')
->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}')
->orderBy('surname_lv_collated', 'asc')
->limit(SolrLibrary::MAXINT);
// Add letter filter
$filter = explode(",", $this->person_letter);
......@@ -265,11 +265,11 @@ class LuisContacts
$IdsString .= " OR id:". implode(" OR id:", $this->unit_sub_parent_id);
$unitIdsString .= " OR unit_ids:". implode(" OR unit_ids:", $this->unit_sub_parent_id);
}
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="(type:position AND (unit_ids:'.$unitIdsString.')) OR type:workplace"]', 'units:[subquery]']);
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="(type:position AND (unit_ids:'.$unitIdsString.')) OR type:workplace"]']);
$SolrLibrary->whereRaw('units.q', "id:{$IdsString}");
$SolrLibrary->whereStr("(unit_ids:{$unitIdsString})");
} else {
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="type:position OR type:workplace"]', 'units:[subquery]']);
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="type:position OR type:workplace"]']);
$SolrLibrary->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}');
}
......@@ -281,6 +281,9 @@ class LuisContacts
// Execute request
$result = $SolrLibrary->execute();
// Add units[subquery]
$result = $this->addLetterUnits($result);
return $result['data'];
}
......@@ -298,14 +301,14 @@ class LuisContacts
// Build the query
$SolrLibrary->select(['*', 'units:[subquery]'])
->from($this->solrCore)
->where('type', $this->request_type)
->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}')
->whereRaw('units.rows', $limit)
->whereRaw('units.fl', 'id,name')
->whereRaw('units.sort', 'name_lv_collated asc')
->orderBy('name_lv_collated', 'asc')
->limit($limit);
->from($this->solrCore)
->where('type', $this->request_type)
->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}')
->whereRaw('units.rows', $limit)
->whereRaw('units.fl', 'id,name')
->whereRaw('units.sort', 'name_lv_collated asc')
->orderBy('name_lv_collated', 'asc')
->limit($limit);
// Check if address_id requested
if ($this->unit_address_id) {
......@@ -335,10 +338,10 @@ class LuisContacts
// Build the query
$SolrLibrary->select('*')
->from($this->solrCore)
->where('type', $this->request_type)
->orderBy('name_lv_collated', 'asc')
->limit(SolrLibrary::MAXINT);
->from($this->solrCore)
->where('type', $this->request_type)
->orderBy('name_lv_collated', 'asc')
->limit(SolrLibrary::MAXINT);
// Check if parent_id requested
if ($this->unit_parent_id) {
......@@ -355,7 +358,7 @@ class LuisContacts
}
/**
* Fetch person request
* Fetch person request for unit views
*
* @return mixed
*/
......@@ -367,9 +370,9 @@ class LuisContacts
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', $this->request_type)
->orderBy('surname_lv_collated', 'asc')
->limit($limit);
->where('type', $this->request_type)
->orderBy('surname_lv_collated', 'asc')
->limit($limit);
// Check if parent_id requested
if ($this->unit_parent_id) {
......@@ -379,11 +382,11 @@ class LuisContacts
$IdsString .= " OR id:". implode(" OR id:", $this->unit_sub_parent_id);
$unitIdsString .= " OR unit_ids:". implode(" OR unit_ids:", $this->unit_sub_parent_id);
}
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="(type:position AND (unit_ids:'.$unitIdsString.')) OR type:workplace"]', 'units:[subquery]']);
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="(type:position AND (unit_ids:'.$unitIdsString.')) OR type:workplace"]']);
$SolrLibrary->whereRaw('units.q', "id:{$IdsString}");
$SolrLibrary->whereStr("(unit_ids:{$unitIdsString})");
} else {
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="type:position OR type:workplace"]', 'units:[subquery]']);
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="type:position OR type:workplace"]']);
$SolrLibrary->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}');
}
......@@ -395,6 +398,9 @@ class LuisContacts
// Execute request
$result = $SolrLibrary->execute();
// Add units[subquery]
$result = $this->addUnitviewUnits($result);
// Return response data array
return $result['data'];
}
......@@ -411,9 +417,9 @@ class LuisContacts
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', 'person')
->orderBy('surname_lv_collated', 'asc')
->limit(SolrLibrary::MAXINT);
->where('type', 'person')
->orderBy('surname_lv_collated', 'asc')
->limit(SolrLibrary::MAXINT);
// Add name filter
if ($this->searchTerm) {
......@@ -433,11 +439,11 @@ class LuisContacts
$IdsString .= " OR id:". implode(" OR id:", $this->unit_sub_parent_id);
$unitIdsString .= " OR unit_ids:". implode(" OR unit_ids:", $this->unit_sub_parent_id);
}
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="(type:position AND (unit_ids:'.$unitIdsString.')) OR type:workplace"]', 'units:[subquery]']);
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="(type:position AND (unit_ids:'.$unitIdsString.')) OR type:workplace"]']);
$SolrLibrary->whereRaw('units.q', "id:{$IdsString}");
$SolrLibrary->whereStr("(unit_ids:{$unitIdsString})");
} else {
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="type:position OR type:workplace"]', 'units:[subquery]']);
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="type:position OR type:workplace"]']);
$SolrLibrary->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}');
}
......@@ -454,6 +460,9 @@ class LuisContacts
// Execute request
$result = $SolrLibrary->execute(true);
// Add units[subquery]
$result = $this->addPersonUnits($result);
// Return response data array
return $result['success'] ? $result['data'] : $result;
}
......@@ -473,8 +482,8 @@ class LuisContacts
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', 'unit')
->limit(SolrLibrary::MAXINT);
->where('type', 'unit')
->limit(SolrLibrary::MAXINT);
// Add name filter
$search = explode(" ", trim($this->searchTerm));
......@@ -526,8 +535,8 @@ class LuisContacts
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', 'person')
->limit(0);
->where('type', 'person')
->limit(0);
// Check if parent_id requested
if ($this->unit_parent_id) {
......@@ -537,11 +546,11 @@ class LuisContacts
$IdsString .= " OR id:". implode(" OR id:", $this->unit_sub_parent_id);
$unitIdsString .= " OR unit_ids:". implode(" OR unit_ids:", $this->unit_sub_parent_id);
}
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="(type:position AND (unit_ids:'.$unitIdsString.')) OR type:workplace"]', 'units:[subquery]']);
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="(type:position AND (unit_ids:'.$unitIdsString.')) OR type:workplace"]']);
$SolrLibrary->whereRaw('units.q', "id:{$IdsString}");
$SolrLibrary->whereStr("(unit_ids:{$unitIdsString})");
} else {
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="type:position OR type:workplace"]', 'units:[subquery]']);
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="type:position OR type:workplace"]']);
$SolrLibrary->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}');
}
......@@ -576,17 +585,20 @@ class LuisContacts
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', 'person')
->where('id', $personId)
->limit(1);
->where('type', 'person')
->where('id', $personId)
->limit(1);
// Add childs
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="type:position OR type:workplace"]', 'units:[subquery]']);
$SolrLibrary->select(['*', '[child parentFilter=type:person childFilter="type:position OR type:workplace"]']);
$SolrLibrary->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}');
// Execute request
$result = $SolrLibrary->execute();
// Add units[subquery]
$result = $this->addDetailUnits($result, $personId);
// Return response data array
return ReturnPretty::json($result, 200);
}
......@@ -605,9 +617,9 @@ class LuisContacts
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', 'unit')
->where('id', $unitId)
->limit(1);
->where('type', 'unit')
->where('id', $unitId)
->limit(1);
// Execute request
$result = $SolrLibrary->execute();
......@@ -637,4 +649,237 @@ class LuisContacts
return $luisContacts->fetch();
}
/**
* Fetches units for letter views
*
* @param $previousResult
* @return mixed
*/
private function addLetterUnits($previousResult)
{
// Build solr request
$SolrLibrary = new SolrLibrary();
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', 'person')
->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}')
->orderBy('surname_lv_collated', 'asc')
->limit(SolrLibrary::MAXINT);
// Add letter filter
$filter = explode(",", $this->person_letter);
foreach ($filter as &$letter) {
$letter = "surname:".trim($letter)."*";
}
$filter = implode(" OR ", $filter);
$SolrLibrary->whereStr("($filter)");
// Check if parent_id requested
if ($this->unit_parent_id) {
$IdsString = $this->unit_parent_id;
$unitIdsString = $this->unit_parent_id;
if ($this->unit_sub_parent_id) {
$IdsString .= " OR id:". implode(" OR id:", $this->unit_sub_parent_id);
$unitIdsString .= " OR unit_ids:". implode(" OR unit_ids:", $this->unit_sub_parent_id);
}
$SolrLibrary->select(['*', 'units:[subquery]']);
$SolrLibrary->whereRaw('units.q', "id:{$IdsString}");
$SolrLibrary->whereStr("(unit_ids:{$unitIdsString})");
} else {
$SolrLibrary->select(['*', 'units:[subquery]']);
$SolrLibrary->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}');
}
// Check if address requested
if ($this->unit_address_id) {
$SolrLibrary->where('address_ids', $this->unit_address_id);
}
// Execute request
$result = $SolrLibrary->execute();
// Return response data array
if ($result['success']) {
foreach($result['data'] as &$item) {
foreach($previousResult['data'] as &$oldItem) {
// Add units to match
if($item->id == $oldItem->id) {
$oldItem['units'] = $item['units'];
}
}
}
}
return $previousResult;
}
/**
* Fetches units for person list
*
* @param $previousResult
* @return mixed
*/
private function addPersonUnits($previousResult)
{
// Build solr request
$SolrLibrary = new SolrLibrary();
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', 'person')
->orderBy('surname_lv_collated', 'asc')
->limit(SolrLibrary::MAXINT);
// Add name filter
if ($this->searchTerm) {
$search = explode(" ", trim($this->searchTerm));
if ($search) {
foreach ($search as $item) {
$SolrLibrary->whereStr("(name:".trim($item)." OR surname:".trim($item).")");
}
}
}
// Check if parent_id requested
if ($this->unit_parent_id) {
$IdsString = $this->unit_parent_id;
$unitIdsString = $this->unit_parent_id;
if ($this->unit_sub_parent_id) {
$IdsString .= " OR id:". implode(" OR id:", $this->unit_sub_parent_id);
$unitIdsString .= " OR unit_ids:". implode(" OR unit_ids:", $this->unit_sub_parent_id);
}
$SolrLibrary->select(['*', 'units:[subquery]']);
$SolrLibrary->whereRaw('units.q', "id:{$IdsString}");
$SolrLibrary->whereStr("(unit_ids:{$unitIdsString})");
} else {
$SolrLibrary->select(['*', 'units:[subquery]']);
$SolrLibrary->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}');
}
// Check if person IDs requested
if ($this->person_ids) {
$SolrLibrary->where('id', "(".implode(" ", $this->person_ids).")");
}
// Check if address requested
if ($this->unit_address_id) {
$SolrLibrary->where('address_ids', $this->unit_address_id);
}
// Execute request
$result = $SolrLibrary->execute(true);
// Return response data array
if ($result['success']) {
foreach($result['data']['docs'] as &$item) {
foreach($previousResult['data']['docs'] as &$oldItem) {
// Add units to match
if($item->id == $oldItem->id) {
$oldItem['units'] = $item['units'];
}
}
}
}
return $previousResult;
}
/**
* Fetches units for person detail view
*
* @param $previousResult
* @return mixed
*/
private function addUnitviewUnits($previousResult)
{
// Build solr request
$SolrLibrary = new SolrLibrary();
$limit = SolrLibrary::MAXINT;
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', $this->request_type)
->orderBy('surname_lv_collated', 'asc')
->limit($limit);
// Check if parent_id requested
if ($this->unit_parent_id) {
$IdsString = $this->unit_parent_id;
$unitIdsString = $this->unit_parent_id;
if ($this->unit_sub_parent_id) {
$IdsString .= " OR id:". implode(" OR id:", $this->unit_sub_parent_id);
$unitIdsString .= " OR unit_ids:". implode(" OR unit_ids:", $this->unit_sub_parent_id);
}
$SolrLibrary->select(['*', 'units:[subquery]']);
$SolrLibrary->whereRaw('units.q', "id:{$IdsString}");
$SolrLibrary->whereStr("(unit_ids:{$unitIdsString})");
} else {
$SolrLibrary->select(['*', 'units:[subquery]']);
$SolrLibrary->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}');
}
// Check if address requested
if ($this->unit_address_id) {
$SolrLibrary->where('address_ids', $this->unit_address_id);
}
// Execute request
$result = $SolrLibrary->execute();
// Return response data array
if ($result['success']) {
foreach($result['data'] as &$item) {
foreach($previousResult['data'] as &$oldItem) {
// Add units to match
if($item->id == $oldItem->id) {
$oldItem['units'] = $item['units'];
}
}
}
}
return $previousResult;
}
/**
* Fetches units for person detail view
*
* @param $previousResult
* @param $personId
* @return mixed
*/
private function addDetailUnits($previousResult, $personId)
{
// Build solr request
$SolrLibrary = new SolrLibrary();
// Build the query
$SolrLibrary->from($this->solrCore)
->where('type', 'person')
->where('id', $personId)
->limit(1);
// Add childs
$SolrLibrary->select(['*', 'units:[subquery]']);
$SolrLibrary->whereRaw('units.q', '{!terms f=id v=$row.unit_ids}');
// Execute request
$result = $SolrLibrary->execute();
// Return response data array
if ($result['success']) {
foreach($result['data'] as &$item) {
foreach($previousResult['data'] as &$oldItem) {
// Add units to match
if($item->id == $oldItem->id) {
$oldItem['units'] = $item['units'];
}
}
}
}
return $previousResult;
}
}
......@@ -164,8 +164,15 @@ foreach ($xml as $node) {
// Load extra data (currently person consultation)
$ExtraData = @file_get_contents('https://luis.lu.lv/pls/lu/JC_XML.persona?p_ckods='.$old_id, false, $extraContext);
if ($ExtraData) {
$use_errors = libxml_use_internal_errors(true);
$ExtraXml = simplexml_load_string($ExtraData);
if (!empty($ExtraXml->konsultacijas)) {
if ($ExtraXml === false) {
@mail(
"dainisa@lu.lv",
"Cron error <https://luis.lu.lv/pls/lu/JC_XML.persona?p_ckods=$old_id>",
$ExtraData
);
} else if (!empty($ExtraXml->konsultacijas)) {
$tmp['consultation'] = [];
foreach ($ExtraXml->konsultacijas as $konsultacija) {
$tmp['consultation'][] = trim((string)$konsultacija->konsultacija['apraksts']);
......
{
"name": "luitd/lu-api",
"version": "2.8.2",
"version": "2.9.0",
"description": "REST API Integration for TYPO3",
"type": "typo3-cms-extension",
"keywords": [
......
......@@ -14,7 +14,7 @@ $EM_CONF[$_EXTKEY] = [
'title' => 'LU API',
'description' => 'REST API Integration for TYPO3',
'category' => 'plugin',
'version' => '2.8.2',
'version' => '2.9.0',
'dependencies' => 'typo3',
'state' => 'stable',
'clearCacheOnLoad' => true,
......
......@@ -4,7 +4,7 @@
## Version
2.8.2
2.9.0
## Dependencies
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment