Skip to content

Commit

Permalink
full text search changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nczirjak-acdh committed May 14, 2021
1 parent c750a32 commit 6eaeb77
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 115 deletions.
34 changes: 1 addition & 33 deletions src/Controller/SearchViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,37 +135,5 @@ public function fulltext_search(string $metavalue = "root", string $limit = "10"
];
}

public function rest_search(string $metavalue = "root")
{
$url = 'https://arche-dev.acdh-dev.oeaw.ac.at/api/search?operator[]=@@&value[]=Ressourcen&readMode=resource';
$urlroot= 'https://arche-dev.acdh-dev.oeaw.ac.at/api/search?operator[]=@@'
. '&property[]=http://www.w3.org/1999/02/22-rdf-syntax-ns%23type'
. '&value[]=https://vocabs.acdh.oeaw.ac.at/schema%23TopCollection'
. '&readMode=resource&format=application/json';

$connection = new \Drupal\acdh_repo_gui\Helper\ArcheRestConnection();

$response = $connection->callEndpoint($url, [
'limit' => 10,
'offset' => 0,
'url_query' => [
'sort' => 'title',
]
]);




echo '<pre>';
var_dump($response);
echo '</pre>';
die();

$json = json_decode($response->getBody());

echo '<pre>';
var_dump($response->getBody());
echo '</pre>';
die();
}

}
96 changes: 14 additions & 82 deletions src/Model/SearchViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

use Drupal\acdh_repo_gui\Model\ArcheModel;
use acdhOeaw\acdhRepoLib\Repo;
use acdhOeaw\acdhRepoLib\RepoResource;
use acdhOeaw\acdhRepoLib\RepoDb;
use acdhOeaw\acdhRepoLib\SearchConfig;
use acdhOeaw\acdhRepoLib\RepoResourceInterface;
use acdhOeaw\acdhRepoLib\SearchTerm;

/**
* Description of SearchViewModel
Expand All @@ -18,21 +13,21 @@
class SearchViewModel extends ArcheModel
{
protected $repodb;
private $config;
private $repo;
protected $config;
protected $repo;
private $repolibDB;
private $sqlResult;
private $siteLang;
private $searchCfg;
private $metaObj;
private $log;
/* ordering */
private $limit;
private $offset;
private $orderby;
private $orderby_column;
private $binarySearch = false;
private $namespace;
protected $limit;
protected $offset;
protected $orderby;
protected $orderby_column;
protected $binarySearch = false;
protected $namespace;
/* ordering */

public function __construct()
Expand All @@ -58,73 +53,6 @@ private function setUpPayload(): void
}
}

/**
* Full content search
*
* @param int $limit
* @param int $page
* @param string $order
* @param object $metavalue
* @return array
*/
public function getViewData_V2(int $limit = 10, int $page = 0, string $order = "datedesc", object $metavalue = null): array
{
$result = array();
$this->metaObj = $metavalue;
$this->initPaging($limit, $page, $order);
$sqlYears = $this->formatYearsFilter_V2();
$sqlTypes = $this->formatTypeFilter_V2();
if (isset($this->metaObj->words) && (count($this->metaObj->words) > 0)) {
$sqlWords = implode(" & ", $this->metaObj->words);
} else {
$sqlWords = (string)"*";
}

$this->setUpPayload();

try {
$this->setSqlTimeout('30000');
//"select * from gui.search_full_func('Wollmilchsau', ARRAY [ 'https://vocabs.acdh.oeaw.ac.at/schema#Collection'], '%(2020|1997)%', 'en', '10', '0', 'desc', 'https://vocabs.acdh.oeaw.ac.at/schema#hasTitle');"
$query = $this->repodb->query(
"select * from gui.search_full_func(:wordStr, ".$sqlTypes.", :yearStr, :lang, :limit, :offset, :order, :order_prop, :binarySearch);",
array(
':wordStr' => (string)$sqlWords,
':yearStr' => (string)$sqlYears,
':lang' => $this->siteLang,
':limit' => $this->limit,
':offset' => $this->offset,
':order' => $this->orderby,
':order_prop' => $this->orderby_column,
':binarySearch' => $this->binarySearch
),
['allow_delimiter_in_query' => true, 'allow_square_brackets' => true]
);

$this->sqlResult = $query->fetchAll(\PDO::FETCH_CLASS);
$this->changeBackDBConnection();
} catch (\Exception $ex) {
error_log($ex->getMessage());
\Drupal::logger('acdh_repo_gui')->notice($ex->getMessage());
return array();
} catch (\Drupal\Core\Database\DatabaseExceptionWrapper $ex) {
error_log($ex->getMessage());
\Drupal::logger('acdh_repo_gui')->notice($ex->getMessage());
return array();
}

if ($this->sqlResult == null) {
$this->sqlResult = array();
}
if (isset($this->sqlResult[0]->cnt)) {
$cnt = $this->sqlResult[0]->cnt;
} else {
$cnt = 0;
}

return array('count' => $cnt, 'data' => $this->sqlResult);
}


public function getViewData(int $limit = 10, int $page = 0, string $order = "datedesc", object $metavalue = null): array
{
$result = array();
Expand All @@ -142,10 +70,10 @@ public function getViewData(int $limit = 10, int $page = 0, string $order = "dat
$this->setUpPayload();

try {
$this->setSqlTimeout('30000');
$this->setSqlTimeout('60000');
//"select * from gui.search_full_func('Wollmilchsau', ARRAY [ 'https://vocabs.acdh.oeaw.ac.at/schema#Collection'], '%(2020|1997)%', 'en', '10', '0', 'desc', 'https://vocabs.acdh.oeaw.ac.at/schema#hasTitle');"
$query = $this->repodb->query(
"select * from gui.search_full_v2_func(:wordStr, ".$sqlTypes.", :yearStr, :lang, :limit, :offset, :order, :order_prop, :binarySearch);",
"select * from gui.search_full_v3_func(:wordStr, ".$sqlTypes.", :yearStr, :lang, :limit, :offset, :order, :order_prop, :binarySearch);",
array(
':wordStr' => (string)$sqlWords,
':yearStr' => (string)$sqlYears,
Expand Down Expand Up @@ -609,4 +537,8 @@ private function initPaging(int $limit, int $page, string $order)
$this->orderby_column = "avdate";
}
}




}

0 comments on commit 6eaeb77

Please sign in to comment.