Commit a35407c9 authored by Dainis Abols's avatar Dainis Abols
Browse files

Sort otder additions and changes

v.2.8.0
parent 015832d4
......@@ -7,6 +7,8 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class SolrLibrary
*
* https://solr.apache.org/guide/6_6/the-standard-query-parser.html
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @version 1.0
......
......@@ -56,6 +56,13 @@ class SolrNames
*/
private $solrCore = '';
/**
* Mandatory fields
*
* @var array
*/
private $mandatory = [];
/**
* Set parent IDs
*
......@@ -79,6 +86,14 @@ class SolrNames
}
}
/**
* @param array $mandatory
*/
public function setMandatory(array $mandatory): void
{
$this->mandatory = $mandatory;
}
/**
* Sets filters
*
......@@ -182,6 +197,13 @@ class SolrNames
->where('*', '*')
->limit($SolrLibrary::MAXINT);
// Set mandatory fields
if ($this->mandatory) {
foreach($this->mandatory as $mandatory) {
$SolrLibrary->where($mandatory ,'[* TO *]');
}
}
// Build request with filters and types
if (!empty($this->filters)) {
$SolrLibrary->whereStr("(".implode(" OR ", $this->filters).")");
......@@ -221,7 +243,7 @@ class SolrNames
// Set sort
if ($this->sort) {
foreach($this->sort as $sortField => $sortOrder) {
$SolrLibrary->sort($sortField, $sortOrder);
$SolrLibrary->sort($sortField.'_sort', $sortOrder);
}
}
......
......@@ -22,6 +22,13 @@ class SolrSearch
*/
private $conf = [];
/**
* Request language
*
* @var string
*/
private $language = 'all';
/**
* Filter request
*
......@@ -108,6 +115,18 @@ class SolrSearch
}
}
/**
* @param string $language
*/
public function setLanguage(string $language): void
{
if ($language != 'all') {
$this->language = "(all OR {$language})";;
} else {
$this->language = 'all';
}
}
/**
* Sets filters
*
......@@ -222,12 +241,21 @@ class SolrSearch
// Build solr request
$SolrLibrary = new SolrLibrary();
// Execute request
// Build request
$SolrLibrary->select(['*'])
->from($this->solrCore)
->where('*', '*')
->limit($SolrLibrary::MAXINT);
// Always require valid title
$SolrLibrary->where('title', '[* TO *]');
// Check language settings
if ($this->language != 'all') {
$SolrLibrary->where('language', $this->language);
} else {
$SolrLibrary->where('*', '*');
}
// Check sorting request
if ($this->order != 'default') {
$SolrLibrary->orderBy('date_published', $this->order == 'asc' ? 'asc' : 'desc');
......@@ -306,6 +334,10 @@ class SolrSearch
$SolrLibrary->limit($this->limit);
$SolrLibrary->offset($this->offset);
if (isset($_REQUEST['showQuery'])) {
dd($SolrLibrary->dumpQuery());
}
// Fetch results
$result = $SolrLibrary->execute($fullReponse);
$data = !empty($result['data']) ? $result['data'] : [];
......
{
"name": "luitd/lu-api",
"version": "2.7.3",
"version": "2.8.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.7.3',
'version' => '2.8.0',
'dependencies' => 'typo3',
'state' => 'stable',
'clearCacheOnLoad' => true,
......
......@@ -4,7 +4,7 @@
## Version
2.7.3
2.8.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