Skip to content

Commit

Permalink
[TASK] Use solarium to build queries for Solr (#2067)
Browse files Browse the repository at this point in the history
In EXT:solr 9.0.0 we want to use the solarium php api instead of the old SolrPhpClient

Since this is a huge task, we splitted it into multiple parts. In this part we change EXT:solr
in order to use as much from solarium as we can to build the Solr queries.

In a later issue/pr we will also use the solarium client, to perform the http requests to solr
and along with that drop the SolrPhpClient.

This pr contains several changes that require changes on you code when you use the EXT:solr api:

* The ParameterBuilder classes (Domain\Search\Query\ParameterBuilder), no get the QueryBuilder passed in the build() method, instead of the Query itself.
* The Query class now inherits from Solarium\QueryType\Select\Query\Query and the QueryBuilder and all ParameterBuilders need to initialize the Query object with the solarium api.
* In non composer mode the solarium api and it's dependecies get loaded from Resources\Private\Php\ComposerLibraries, in composer mode solarium is installed by composer.

Fixes: #2068
  • Loading branch information
timohund committed Aug 7, 2018
1 parent fe103b8 commit 7bb24ba
Show file tree
Hide file tree
Showing 75 changed files with 2,330 additions and 2,485 deletions.
5 changes: 4 additions & 1 deletion Build/Release/ter_tag_uploader.sh
Expand Up @@ -28,8 +28,11 @@ if [ -n "$TRAVIS_TAG" ] && [ -n "$TYPO3_ORG_USERNAME" ] && [ -n "$TYPO3_ORG_PASS
pwd

git reset --hard HEAD && git clean -fx

composer run-script extension-build

echo "Files in this package"
ls -l
ls -lRa

TAG_MESSAGE=`git tag -n10 -l $TRAVIS_TAG | sed 's/^[0-9.]*[ ]*//g'`
echo "Uploading release ${TRAVIS_TAG} to TER"
Expand Down
75 changes: 9 additions & 66 deletions Classes/Domain/Search/Query/ExtractingQuery.php
Expand Up @@ -24,13 +24,14 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use Solarium\QueryType\Extract\Query as SolariumExtractQuery;

/**
* Specialized query for content extraction using Solr Cell
*
*/
class ExtractingQuery extends Query
class ExtractingQuery extends SolariumExtractQuery
{
protected $file;
protected $multiPartPostDataBoundary;

/**
Expand All @@ -40,10 +41,10 @@ class ExtractingQuery extends Query
*/
public function __construct($file)
{
parent::__construct('');

$this->file = $file;
parent::__construct();
$this->setFile($file);
$this->multiPartPostDataBoundary = '--' . md5(uniqid(time()));
$this->addParam('extractFormat', 'text');
}

/**
Expand All @@ -56,36 +57,14 @@ public function getMultiPartPostDataBoundary()
return $this->multiPartPostDataBoundary;
}

/**
* Gets the absolute path to the file to extract content and meta data from.
*
* @return string Absolute path to the file to extract content and meta data from.
*/
public function getFile()
{
return $this->file;
}

/**
* Sets the absolute path to the file to extract content and meta data from.
*
* @param string $file Absolute path to the file to extract content and meta data from.
*/
public function setFile($file)
{
if (is_file($file)) {
$this->file = $file;
}
}

/**
* Gets the filename portion of the file.
*
* @return string The filename.
*/
public function getFileName()
{
return basename($this->file);
return basename($this->getFile());
}

/**
Expand All @@ -101,11 +80,9 @@ public function getRawPostFileData($boundary = '')
$boundary = $this->multiPartPostDataBoundary;
}

$fileData = file_get_contents($this->file);
$fileData = file_get_contents($this->getFile());
if ($fileData === false) {
throw new \Apache_Solr_InvalidArgumentException(
'Could not retrieve content from file ' . $this->file
);
throw new \Apache_Solr_InvalidArgumentException('Could not retrieve content from file ' . $this->getFile());
}

$data = "--{$boundary}\r\n";
Expand All @@ -117,38 +94,4 @@ public function getRawPostFileData($boundary = '')

return $data;
}

/**
* En / Disables extraction only
*
* @param bool $extractOnly If TRUE, only extracts content from the given file without indexing
*/
public function setExtractOnly($extractOnly = true)
{
if ($extractOnly) {
$this->queryParametersContainer->set('extractOnly', 'true');
} else {
$this->queryParametersContainer->remove('extractOnly');
}
}

/**
* Builds an array of query parameters to use for the search query.
*
* @return array An array ready to use with query parameters
*/
public function getQueryParameters()
{
$filename = basename($this->file);

// TODO create an Apache Solr patch to support Apache Tika's -m (and -l) options
$extractingParameters = [
'resource.name' => $filename,
'extractFormat' => 'text',
// Matches the -t command for the tika CLI app.
];

$this->queryParametersContainer->merge($extractingParameters);
return $this->queryParametersContainer->toArray();
}
}
112 changes: 0 additions & 112 deletions Classes/Domain/Search/Query/Helper/Pagination.php

This file was deleted.

0 comments on commit 7bb24ba

Please sign in to comment.