Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions config/api_resources/nodes_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,33 @@ resources:
description: |
Get available NodesSources archives (years and months) based on their `publishedAt` field

# api_nodes_sources_search:
# class: ApiPlatform\Metadata\GetCollection
# method: 'GET'
# uriTemplate: '/nodes_sources/search'
# controller: RZ\Roadiz\SolrBundle\Controller\NodesSourcesSearchController
# read: false
# normalizationContext:
# groups:
# - get
# - nodes_sources_base
# - nodes_sources_default
# - urls
# - tag_base
# - translation_base
# - document_display
# openapi:
# summary: Search NodesSources resources
# description: |
# Search all website NodesSources resources using **Solr** full-text search engine
# parameters:
# - type: string
# name: search
# in: query
# required: true
# description: Search pattern
# schema:
# type: string
api_nodes_sources_search:
class: ApiPlatform\Metadata\GetCollection
method: 'GET'
uriTemplate: '/nodes_sources/search'
controller: RZ\Roadiz\SolrBundle\Controller\NodesSourcesSearchController
read: false
normalizationContext:
groups:
- get
- nodes_sources_base
- nodes_sources_default
- urls
- tag_base
- translation_base
- document_display
openapi:
summary: Search NodesSources resources
description: |
Search all website NodesSources resources using **Solr** full-text search engine
parameters:
- type: string
name: search
in: query
required: true
description: Search pattern
schema:
type: string

# ApiPlatform\Metadata\Get:
# method: 'GET'
Expand Down
4 changes: 4 additions & 0 deletions config/packages/roadiz_solr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
roadiz_solr:
search:
fuzzy_proximity: 2
fuzzy_min_term_length: 3
13 changes: 13 additions & 0 deletions docs/developer/first-steps/use_apache_solr.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,23 @@ nelmio_solarium:
adapter_timeout: 5
```

Then configure fuzzy search options in `config/packages/roadiz_solr.yaml`:

```yaml
# config/packages/roadiz_solr.yaml
roadiz_solr:
search:
fuzzy_proximity: 2
fuzzy_min_term_length: 3
```

You can use Solr in 2 ways: as a core or as a collection:
- If you are using Solr as a single core, you can set the `SOLR_CORE_NAME` environment variable.
- If you are using _SolrCloud mode_, you can set the `SOLR_COLLECTION_NAME`

Fuzzy search options are configured in `roadiz_solr.search`.
For backward compatibility, `roadiz_core.solr.search` is still read as a fallback during migration.

::: info
When using _SolrCloud mode_ you will need to set the `SOLR_COLLECTION_NUM_SHARDS` and
`SOLR_COLLECTION_REPLICATION_FACTOR` variables to configure your collection and execute
Expand Down
2 changes: 1 addition & 1 deletion lib/Documents/src/Console/DocumentSizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

private function updateDocumentSize(DocumentInterface $document): void
{
if (!($document instanceof SizeableInterface)) {
if (!$document instanceof SizeableInterface) {
return;
}
$mountPath = $document->getMountPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ public function getSearchFeed(string $searchTerm, ?string $author = null, int $m
}

return $this->downloadFeedFromAPI($url);
} else {
throw new APINeedsAuthentificationException('YoutubeEmbedFinder needs a Google server key, create a “google_server_id” setting.', 1);
}
throw new APINeedsAuthentificationException('YoutubeEmbedFinder needs a Google server key, create a “google_server_id” setting.', 1);
}

/**
Expand Down
38 changes: 14 additions & 24 deletions lib/Documents/src/Models/BaseDocumentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,36 +153,32 @@ trait BaseDocumentTrait
'image/heif',
];

#[
Serializer\Groups(['document_mount']),
Serializer\SerializedName('mountPath'),
]
#[Serializer\Groups(['document_mount']),
Serializer\SerializedName('mountPath'),]
public function getMountPath(): ?string
{
if (null === $relativePath = $this->getRelativePath()) {
return null;
}
if ($this->isPrivate()) {
return 'private://'.$relativePath;
} else {
return 'public://'.$relativePath;
}

return 'public://'.$relativePath;
}

/**
* Get short type name for current document Mime type.
*/
#[
Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
Serializer\SerializedName('type'),
]
#[Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
Serializer\SerializedName('type'),]
public function getShortType(): string
{
if (null !== $this->getMimeType() && isset(static::$mimeToIcon[$this->getMimeType()])) {
return static::$mimeToIcon[$this->getMimeType()];
} else {
return 'unknown';
}

return 'unknown';
}

/**
Expand Down Expand Up @@ -251,32 +247,26 @@ public function isWebp(): bool
return 'image/webp' === $this->getMimeType();
}

#[
Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
Serializer\SerializedName('relativePath'),
]
#[Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
Serializer\SerializedName('relativePath'),]
public function getRelativePath(): ?string
{
return $this->isLocal() ? $this->getFolder().'/'.$this->getFilename() : null;
}

#[
Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
#[Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
Serializer\SerializedName('processable'),
ApiProperty(
description: 'Document can be processed as an image for resampling and other image operations.',
writable: false,
)
]
)]
public function isProcessable(): bool
{
return !$this->isPrivate() && $this->isImage() && in_array($this->getMimeType(), static::$processableMimeTypes, true);
}

#[
Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
Serializer\SerializedName('alt'),
]
#[Serializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute']),
Serializer\SerializedName('alt'),]
public function getAlternativeText(): ?string
{
return null;
Expand Down
8 changes: 3 additions & 5 deletions lib/Documents/src/Models/DocumentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

trait DocumentTrait
{
#[
Serializer\Ignore
]
#[Serializer\Ignore]
public function getMountFolderPath(): ?string
{
$folder = $this->getFolder();
Expand All @@ -20,9 +18,9 @@ public function getMountFolderPath(): ?string
}
if ($this->isPrivate()) {
return 'private://'.$folder;
} else {
return 'public://'.$folder;
}

return 'public://'.$folder;
}

protected function initDocumentTrait(): void
Expand Down
2 changes: 1 addition & 1 deletion lib/Documents/src/Renderer/AbstractImageRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected function additionalAssignation(BaseDocumentInterface $document, array
$assignation['height'] = $options['height'] = $this->getImageHeight($options);
}

if (!($document instanceof AdvancedDocumentInterface)) {
if (!$document instanceof AdvancedDocumentInterface) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Documents/src/Renderer/ChainRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(array $renderers)
* @var RendererInterface $renderer
*/
foreach ($renderers as $renderer) {
if (!($renderer instanceof RendererInterface)) {
if (!$renderer instanceof RendererInterface) {
throw new \InvalidArgumentException('Document Renderer must implement RendererInterface');
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Documents/src/Renderer/EmbedRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function supports(BaseDocumentInterface $document, array $options): bool
&& true === $options['embed']
) {
return true;
} else {
return false;
}

return false;
}

#[\Override]
Expand Down
4 changes: 2 additions & 2 deletions lib/Documents/src/SvgSizeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
/**
* @return array|null [$x, $y, $width, $height]
*/
protected function getViewBoxAttributes(): ?array
private function getViewBoxAttributes(): ?array
{
try {
$viewBox = $this->getSvgNodeAttributes()->getNamedItem('viewBox');
Expand All @@ -36,7 +36,7 @@ protected function getViewBoxAttributes(): ?array
return null;
}

protected function getIntegerAttribute(string $name): ?int
private function getIntegerAttribute(string $name): ?int
{
try {
$attribute = $this->getSvgNodeAttributes()->getNamedItem($name);
Expand Down
34 changes: 17 additions & 17 deletions lib/Documents/src/TwigExtension/DocumentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public function getEmbedFinder(?BaseDocumentInterface $document = null): ?EmbedF
if (null === $document) {
if ($this->throwExceptions) {
throw new RuntimeError('Document can’t be null to get its EmbedFinder.');
} else {
return null;
}

return null;
}

try {
Expand All @@ -85,9 +85,9 @@ public function getEmbedFinder(?BaseDocumentInterface $document = null): ?EmbedF
} catch (InvalidEmbedId $embedException) {
if ($this->throwExceptions) {
throw new RuntimeError($embedException->getMessage());
} else {
return null;
}

return null;
}

return null;
Expand All @@ -101,9 +101,9 @@ public function display(?BaseDocumentInterface $document = null, ?array $options
if (null === $document) {
if ($this->throwExceptions) {
throw new RuntimeError('Document can’t be null to be displayed.');
} else {
return '';
}

return '';
}
if (null === $options) {
$options = [];
Expand All @@ -113,9 +113,9 @@ public function display(?BaseDocumentInterface $document = null, ?array $options
} catch (InvalidEmbedId $embedException) {
if ($this->throwExceptions) {
throw new RuntimeError($embedException->getMessage());
} else {
return '<p>'.$embedException->getMessage().'</p>';
}

return '<p>'.$embedException->getMessage().'</p>';
} catch (InvalidArgumentException $e) {
throw new RuntimeError($e->getMessage(), -1, null, $e);
}
Expand All @@ -135,9 +135,9 @@ public function getImageOrientation(?SizeableInterface $document = null): ?strin
if (null === $document) {
if ($this->throwExceptions) {
throw new RuntimeError('Document can’t be null to get its orientation.');
} else {
return null;
}

return null;
}
$size = $this->getImageSize($document);

Expand All @@ -154,12 +154,12 @@ public function getImageSize(?SizeableInterface $document = null): array
if (null === $document) {
if ($this->throwExceptions) {
throw new RuntimeError('Document can’t be null to get its size.');
} else {
return [
'width' => 0,
'height' => 0,
];
}

return [
'width' => 0,
'height' => 0,
];
}

return [
Expand All @@ -176,9 +176,9 @@ public function getImageRatio(?SizeableInterface $document = null): float
if (null === $document) {
if ($this->throwExceptions) {
throw new RuntimeError('Document can’t be null to get its ratio.');
} else {
return 0.0;
}

return 0.0;
}

if (null !== $document && null !== $ratio = $document->getImageRatio()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public function getUrl(bool $absolute = false): string
$publicUrl = $this->documentsStorage->publicUrl($mountPath);
if ($absolute && \str_starts_with($publicUrl, '/')) {
return $this->urlHelper->getAbsoluteUrl($publicUrl);
} else {
return $publicUrl;
}

return $publicUrl;
}

return $this->getProcessedDocumentUrlByArray($absolute);
Expand Down
Loading