Commit 614901b4 authored by Dainis Abols's avatar Dainis Abols
Browse files

LU Search integration

v2.6.1
parent a5af7609
......@@ -15,6 +15,7 @@ use Lu\LuApi\Models\Namedays;
use Lu\LuApi\Models\Programs;
use Lu\LuApi\Models\ProgramsContinue;
use Lu\LuApi\Models\Purchases;
use Lu\LuApi\Models\Search;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
......
......@@ -7,7 +7,7 @@ use Lu\LuApi\Helpers\ReturnPretty;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class LUContractsList
* Class LuisContracts
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
......
......@@ -7,7 +7,7 @@ use GuzzleHttp\Client as Guzzle;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class LuisLessons. Notice: This gathers and returns ONLY Tornakalns 1st building lessons!!
* Class LuisLessons
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
......
......@@ -7,7 +7,7 @@ use Lu\LuApi\Helpers\ReturnPretty;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class LUPurchasesList
* Class LuisPurchases
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
......
......@@ -145,6 +145,34 @@ class SolrLibrary
*/
private $useQuotes = false;
/**
* Highlist status
*
* @var string
*/
private $hl = "";
/**
* Highlist status
*
* @var string
*/
private $hlQuery = "";
/**
* Highlight pre string
*
* @var string
*/
private $hlSimplePre = "";
/**
* Highlight post string
*
* @var string
*/
private $hlSimplePost = "";
/**
* SolrLibrary constructor.
*
......@@ -308,7 +336,7 @@ class SolrLibrary
}
/**
* Set fiklter query
* Set filter query
*
* @param $fq
*/
......@@ -317,6 +345,46 @@ class SolrLibrary
$this->fq[] = $fq;
}
/**
* Set highlight status
*
* @param $hl
*/
public function highlight($hl)
{
$this->hl = $hl;
}
/**
* Set highlight query
*
* @param $hlQuery
*/
public function highlightQuery($hlQuery)
{
$this->hlQuery = $hlQuery;
}
/**
* Set highlight pre string
*
* @param $hlSimplePre
*/
public function highlightSimplePre($hlSimplePre)
{
$this->hlSimplePre = $hlSimplePre;
}
/**
* Set highlight post string
*
* @param $hlSimplePost
*/
public function highlightSimplePost($hlSimplePost)
{
$this->hlSimplePost = $hlSimplePost;
}
/**
* Add more complicated request to query
*
......@@ -402,15 +470,13 @@ class SolrLibrary
public function execute($fullResponse = false)
{
// Initiate client
$SolrClient = new \SolrClient(
[
$SolrClient = new \SolrClient([
'secure' => $this->solr_secure,
'hostname' => $this->solr_hostname,
'port' => $this->solr_port,
'path' => $this->solr_path.$this->core,
'wt' => 'json',
]
);
]);
// Get the request
$request = $this->getRequestString();
......@@ -424,7 +490,10 @@ class SolrLibrary
$response = $queryResponse->getResponse();
if ($fullResponse) {
if (!$this->distinct) {
if ($this->hl == "on") {
$response = $response;
}
else if (!$this->distinct) {
$response = $response->response;
}
} else {
......@@ -464,8 +533,10 @@ class SolrLibrary
// Build the query
$SolrQuery = new \SolrQuery();
foreach ($this->select as $item) {
if (!empty($item)) {
$SolrQuery->addField($item);
}
}
$SolrQuery->setStart($this->offset);
$SolrQuery->setRows($this->limit);
......@@ -504,11 +575,23 @@ class SolrLibrary
}
}
// Add raw entries
foreach ($this->queryRaw as $item) {
$SolrQuery->addParam($item['param'], $item['value']);
}
// Add highlight
if ($this->hl == "on") {
$SolrQuery->setHighlight(true);
$SolrQuery->addHighlightField("*");
$SolrQuery->setHighlightSimplePre($this->hlSimplePre);
$SolrQuery->setHighlightSimplePost($this->hlSimplePost);
$SolrQuery->setHighlightFragsize(1000);
// @TODO: Add 'hl.q='.$this->hlQuery'`to this
}
// Add sort
if ($this->sort_field) {
$SolrQuery->addSortField($this->sort_field, $this->sort_order);
}
......@@ -557,6 +640,7 @@ class SolrLibrary
*/
private function getRequestString()
{
// Make query
$query = implode(' AND ', $this->query);
if ($this->queryStr) {
if ($this->query) {
......
......@@ -6,7 +6,7 @@ use Lu\LuApi\Helpers\ReturnPretty;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class LuisProgrammes
* Class SolrRegulations
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
......@@ -91,7 +91,7 @@ class SolrRegulations
*
* @param string $statusName
*/
public function hideStatus(string $statusName = '') {
public function hideStatus(string $statusName = null) {
if ($statusName) {
$this->hiddenStatus = $statusName;
}
......
<?php
namespace Lu\LuApi\DataSources;
use Lu\LuApi\Helpers\ReturnPretty;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class LuisProgrammes
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @version 2.6.0
* @since 03.09.2020
*/
class SolrSearch
{
/**
* Extension configuration
*
* @array
*/
private $conf = [];
/**
* Filter request
*
* @var array
*/
private $filters = [];
/**
* Types request
*
* @var array
*/
private $types = [];
/**
* Solr cores
*
* @var string
*/
private $solrCore = '';
/**
* Facet switcher
*
* @var bool
*/
private $facet = false;
/**
* Highlist status
*
* @var string
*/
private $highlight = "";
/**
* Highlight pre string
*
* @var string
*/
private $highlightPre = "";
/**
* Highlight post string
*
* @var string
*/
private $highlightPost = "";
/**
* Set parent IDs
*
* @var array
*/
private $parentIDs = [];
/**
* SolrRegulations constructor.
*
* Gathers and sets connection data from environmental values. Prepares and opens connection.
*/
public function __construct()
{
// Read config file
$this->conf = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get('lu_api');
// Set Solr Core
if ($this->conf) {
$this->solrCore = $this->conf['solrDatabase']['search'];
}
}
/**
* Sets filters
*
* @param array $filters
*/
public function setFilters(array $filters)
{
$this->filters = $filters;
}
/**
* Set limit
*
* @param int $limit
*/
public function setLimit($limit)
{
$this->limit = $limit;
}
/**
* Set parent IDs
*
* @param int $parentIDs
*/
public function setParentIDs($parentIDs)
{
$this->parentIDs = $parentIDs;
}
/**
* Set offset
*
* @param int $offset
*/
public function setOffset($offset)
{
$this->offset = $offset;
}
/**
* Sets types
*
* @param array $types
*/
public function setTypes(array $types)
{
$this->types = $types;
}
/**
* Sets weather to use or not use facets
*
* @param bool $facet
*/
public function useFacets(bool $facet)
{
$this->facet = $facet;
}
/**
* Set highlight options diveded by |
* If non provided default <em>|</em> is used
*
* @param null $highlight
*/
public function setHighlight($highlight = null)
{
$this->highlight = "on";
if ($highlight != null) {
$simple = explode("|", $highlight);
$this->highlightPre = $simple[0];
$this->highlightPost = $simple[1];
} else {
$this->highlightPre = '<em>';
$this->highlightPost = '</em>';
}
}
/**
* Fetch data from provided endpoint
*
* Return [Programme Object, Catalogue Object]
*
* @param bool $fullReponse
*
* @return string
*/
public function fetch($fullReponse = false)
{
// Build solr request
$SolrLibrary = new SolrLibrary();
// Execute request
// $SolrLibrary->select(['*'])
$SolrLibrary->select(['*'])
->from($this->solrCore)
->where('*', '*')
// ->orderBy('date_published', 'desc')
->limit($SolrLibrary::MAXINT);
// Build request with filters and types
if (!empty($this->filters) && !empty($this->types)) {
$SolrLibrary->whereStr("(".implode(" OR ", $this->filters).")");
$SolrLibrary->whereStr("(".implode(" OR ", $this->types).")");
}
// Add parent IDs
if (!empty($this->parentIDs)) {
$SolrLibrary->whereStr("parent_id:(".implode(" OR ", $this->parentIDs).")");
}
// // Filter acceptance date
// if (!empty($this->filters['accepted_date_from']) || !empty($this->filters['accepted_date_till'])) {
// $dateFilter = '[';
// if (!empty($this->filters['accepted_date_from'])) {
// $dateFrom = new \DateTime($this->filters['accepted_date_from']);
// $dateFilter .= $dateFrom->format('Y-m-d').'T00:00:00Z';
// } else {
// $dateFilter .= '*';
// }
// $dateFilter .= ' TO ';
// if (!empty($this->filters['accepted_date_till'])) {
// $dateTill = new \DateTime($this->filters['accepted_date_till']);
// $dateFilter .= $dateTill->format('Y-m-d').'T23:59:59Z';
// } else {
// $dateFilter .= '*';
// }
// $dateFilter .= ']';
// $SolrLibrary->where('date_accepted', $dateFilter);
// }
// // Check facet request
// if ($this->facet) {
// // Set facet usage
// $SolrLibrary->facet([
// 'field' => [
// 'rikojuma_dokum',
// 'document_type',
// 'issuer',
// ],
// 'limit' => -1,
// ]);
// }
//
// // Add facet where
// if (!empty($this->filters['facet_field'])) {
// foreach ($this->filters['facet_field'] as $field=>$value) {
// $SolrLibrary->fq($field.':"'.$value.'"');
// }
// }
// Set highlights
if ($this->highlight == "on") {
$SolrLibrary->highlight("on");
if (!empty($this->highlightPre)) {
$SolrLibrary->highlightSimplePre($this->highlightPre);
$SolrLibrary->highlightSimplePost($this->highlightPost);
$SolrLibrary->highlightQuery(implode(" OR ", $this->filters));
}
}
// Set limit
$SolrLibrary->limit($this->limit);
$SolrLibrary->offset($this->offset);
// Fetch results
$result = $SolrLibrary->execute($fullReponse);
$data = !empty($result['data']) ? $result['data'] : [];
// Return back to the request
return ReturnPretty::json($data, 200);
}
}
{
"name": "luitd/lu-api",
"version": "2.5.0",
"version": "2.6.1",
"description": "REST API Integration for TYPO3",
"type": "typo3-cms-extension",
"keywords": [
......
......@@ -16,6 +16,9 @@ extraImagesStorage =
# cat=Ctypes/set; type=string; label=Contracts List Url
endPoints.ContractsList = http://luis.lu.lv/luis/LU_uznl.html
# cat=SOLR/set; type=string; label=LU Search DB
solrDatabase.search = lusearch
# cat=SOLR/set; type=string; label=Programme catalogue DB
solrDatabase.programmeCatalogue = kursu_katal_program_dati
......
......@@ -14,7 +14,7 @@ $EM_CONF[$_EXTKEY] = [
'title' => 'LU API',
'description' => 'REST API Integration for TYPO3',
'category' => 'plugin',
'version' => '2.5.0',
'version' => '2.6.1',
'dependencies' => 'typo3',
'state' => 'stable',
'clearCacheOnLoad' => true,
......
......@@ -4,11 +4,11 @@
## Version
2.4.0
2.6.1
## Dependencies
TYPO3 7.x+
TYPO3 9.5+
## Author
......@@ -61,11 +61,13 @@ return [
| | | |
| cTypes | endPoints.ContractsList | Contracts List Url |
| | | |
| SOLR | solrDatabase.search | Main search DB |
| SOLR | solrDatabase.programmeCatalogue | Programme catalogue DB |
| SOLR | solrDatabase.programmeCatalogueContinuing | Programme catalogue (continuing) DB |
| SOLR | solrDatabase.courseCatalogue | Course catalogue DB |
| SOLR | solrDatabase.courseCatalogueContinuing | Course catalogue (continuing) DB |
| SOLR | solrDatabase.contactsList | Contacts list DB |
| SOLR | solrDatabase.regulations | Regulations (NAS) DB |
## Notes
......
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