@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function autocomplete(string $search, int $maxResults = 10): array { |
| 68 | 68 | $words = array(); |
| 69 | - foreach($this->index as $doc) { |
|
| 70 | - foreach($doc->getFields() as $content) { |
|
| 71 | - if(is_string($content)) { |
|
| 69 | + foreach ($this->index as $doc) { |
|
| 70 | + foreach ($doc->getFields() as $content) { |
|
| 71 | + if (is_string($content)) { |
|
| 72 | 72 | $words = array_merge($words, explode(' ', $content)); |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -92,10 +92,10 @@ discard block |
||
| 92 | 92 | $facets = new FacetSetAdapter(); |
| 93 | 93 | |
| 94 | 94 | $hits = array(); |
| 95 | - foreach($this->index as $key => $doc) { |
|
| 96 | - foreach($doc->getFields() as $content) { |
|
| 97 | - if(is_string($content) && stripos($content, $term) !== false) { |
|
| 98 | - if(!isset($hits[$key])) { |
|
| 95 | + foreach ($this->index as $key => $doc) { |
|
| 96 | + foreach ($doc->getFields() as $content) { |
|
| 97 | + if (is_string($content) && stripos($content, $term) !== false) { |
|
| 98 | + if (!isset($hits[$key])) { |
|
| 99 | 99 | $hits[$key] = 0; |
| 100 | 100 | } |
| 101 | 101 | $hits[$key] = $hits[$key] + 1; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | arsort($hits); |
| 106 | 106 | $results = array(); |
| 107 | - foreach(array_keys($hits) as $docId) { |
|
| 107 | + foreach (array_keys($hits) as $docId) { |
|
| 108 | 108 | $doc = $this->index[$docId]; |
| 109 | 109 | $facets->addFacetValue(FacetSet::FACET_ENTITY_TYPE, $doc->getEntityClass()); |
| 110 | 110 | $facets->addFacetValue(FacetSet::FACET_AUTHOR, (string)$doc->getFieldValue(Document::FIELD_AUTHOR)); |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $id = $document->getEntityClass(); |
| 132 | 132 | $id .= '#'; |
| 133 | 133 | $entityId = $document->getEntityId(); |
| 134 | - if(is_scalar($entityId)) { |
|
| 134 | + if (is_scalar($entityId)) { |
|
| 135 | 135 | $id .= $entityId; |
| 136 | 136 | } else { |
| 137 | 137 | $id .= md5(serialize($entityId)); |
@@ -33,10 +33,10 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public function addFacetValue(string $key, string $label, $value = null, int $increaseCounterBy = 1) : void { |
| 35 | 35 | $value = $value ?? $label; |
| 36 | - if(!isset($this->facets[$key])) { |
|
| 36 | + if (!isset($this->facets[$key])) { |
|
| 37 | 37 | $this->facets[$key] = array(); |
| 38 | 38 | } |
| 39 | - if(!isset($this->facets[$key][$label])) { |
|
| 39 | + if (!isset($this->facets[$key][$label])) { |
|
| 40 | 40 | $this->facets[$key][$label] = array( |
| 41 | 41 | 'value' => $value, |
| 42 | 42 | 'count' => 0, |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @see \StingerSoft\EntitySearchBundle\Model\Result\FacetSet::getFacet() |
| 53 | 53 | */ |
| 54 | 54 | public function getFacet(string $key): ?array { |
| 55 | - if(isset($this->facets[$key])) { |
|
| 55 | + if (isset($this->facets[$key])) { |
|
| 56 | 56 | return $this->facets[$key]; |
| 57 | 57 | } |
| 58 | 58 | return null; |
@@ -36,14 +36,14 @@ |
||
| 36 | 36 | public function getEntity(Document $document): ?object { |
| 37 | 37 | $clazz = $document->getEntityClass(); |
| 38 | 38 | |
| 39 | - if($clazz === null) { |
|
| 39 | + if ($clazz === null) { |
|
| 40 | 40 | return null; |
| 41 | 41 | } |
| 42 | - if(!$document->getEntityId()) { |
|
| 42 | + if (!$document->getEntityId()) { |
|
| 43 | 43 | return null; |
| 44 | 44 | } |
| 45 | 45 | $manager = $this->managerRegistry->getManagerForClass($clazz); |
| 46 | - if($manager === null) { |
|
| 46 | + if ($manager === null) { |
|
| 47 | 47 | return null; |
| 48 | 48 | } |
| 49 | 49 | return $manager->getRepository($clazz)->find($document->getEntityId()); |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | |
| 25 | 25 | public static function getRequiredBundles(string $env, array &$requiredBundles = []): array { |
| 26 | 26 | |
| 27 | - if(isset($requiredBundles['StingerSoftEntitySearchBundle'])) { |
|
| 27 | + if (isset($requiredBundles['StingerSoftEntitySearchBundle'])) { |
|
| 28 | 28 | return $requiredBundles; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | $this->searchService = $searchService; |
| 72 | 72 | $this->entityToDocumentMapper = $mapper; |
| 73 | 73 | // Detect upload path |
| 74 | - if(!self::$defaultUploadPath) { |
|
| 74 | + if (!self::$defaultUploadPath) { |
|
| 75 | 75 | $root = $kernel->getProjectDir(); |
| 76 | - self::$defaultUploadPath = $root . '/../web/uploads'; |
|
| 76 | + self::$defaultUploadPath = $root.'/../web/uploads'; |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | // Get the entity argument |
| 114 | 114 | $entity = $input->getArgument('entity'); |
| 115 | 115 | |
| 116 | - if($entity === 'all') { |
|
| 116 | + if ($entity === 'all') { |
|
| 117 | 117 | /** |
| 118 | 118 | * @var EntityManager $entityManager |
| 119 | 119 | */ |
@@ -124,12 +124,12 @@ discard block |
||
| 124 | 124 | /** |
| 125 | 125 | * @var ClassMetadata $m |
| 126 | 126 | */ |
| 127 | - foreach($meta as $m) { |
|
| 127 | + foreach ($meta as $m) { |
|
| 128 | 128 | |
| 129 | - if($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) { |
|
| 129 | + if ($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) { |
|
| 130 | 130 | continue; |
| 131 | 131 | } |
| 132 | - if(!$this->entityToDocumentMapper->isClassIndexable($m->getReflectionClass()->getName())) { |
|
| 132 | + if (!$this->entityToDocumentMapper->isClassIndexable($m->getReflectionClass()->getName())) { |
|
| 133 | 133 | continue; |
| 134 | 134 | } |
| 135 | 135 | $this->indexEntity($input, $output, $m->getReflectionClass()->getName()); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | try { |
| 164 | 164 | // Get repository for the given entity type |
| 165 | 165 | $repository = $entityManager->getRepository($entity); |
| 166 | - } catch(Exception $e) { |
|
| 166 | + } catch (Exception $e) { |
|
| 167 | 167 | $output->writeln(sprintf('<error>No repository found for "%s", check your input</error>', $entity)); |
| 168 | 168 | return; |
| 169 | 169 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $useBatch = !($entityManager->getConnection()->getDatabasePlatform() instanceof SQLServerPlatform); |
| 177 | 177 | $iterableResult = $useBatch ? $queryBuilder->getQuery()->iterate() : $queryBuilder->getQuery()->getResult(); |
| 178 | - if($entityCount === 0) { |
|
| 178 | + if ($entityCount === 0) { |
|
| 179 | 179 | $output->writeln('<comment>No entities found for indexing</comment>'); |
| 180 | 180 | return; |
| 181 | 181 | } |
@@ -185,25 +185,25 @@ discard block |
||
| 185 | 185 | $entitiesIndexed = 0; |
| 186 | 186 | |
| 187 | 187 | // Index each entity separate |
| 188 | - foreach($iterableResult as $row) { |
|
| 188 | + foreach ($iterableResult as $row) { |
|
| 189 | 189 | $entity = $useBatch ? $row[0] : $row; |
| 190 | 190 | $progressBar->advance(); |
| 191 | - if($this->entityToDocumentMapper->isIndexable($entity)) { |
|
| 191 | + if ($this->entityToDocumentMapper->isIndexable($entity)) { |
|
| 192 | 192 | $document = $this->entityToDocumentMapper->createDocument($entityManager, $entity); |
| 193 | - if($document === null) { |
|
| 193 | + if ($document === null) { |
|
| 194 | 194 | continue; |
| 195 | 195 | } |
| 196 | 196 | try { |
| 197 | - if($this->getEventDispatcher()) { |
|
| 197 | + if ($this->getEventDispatcher()) { |
|
| 198 | 198 | $event = new DocumentPreSaveEvent($document); |
| 199 | 199 | $this->getEventDispatcher()->dispatch($event, DocumentPreSaveEvent::NAME); |
| 200 | 200 | } |
| 201 | 201 | $this->searchService->saveDocument($document); |
| 202 | 202 | $entitiesIndexed++; |
| 203 | - } catch(Exception $e) { |
|
| 204 | - $output->writeln('<error>Failed to index entity with ID ' . $document->getEntityId() . '</error>'); |
|
| 203 | + } catch (Exception $e) { |
|
| 204 | + $output->writeln('<error>Failed to index entity with ID '.$document->getEntityId().'</error>'); |
|
| 205 | 205 | } |
| 206 | - if($entitiesIndexed % 50 === 0) { |
|
| 206 | + if ($entitiesIndexed % 50 === 0) { |
|
| 207 | 207 | $entityManager->flush(); |
| 208 | 208 | } |
| 209 | 209 | } |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | $entityManager->clear(); |
| 214 | 214 | $progressBar->finish(); |
| 215 | 215 | $output->writeln(''); |
| 216 | - $output->writeln('<comment>Indexed ' . $entitiesIndexed . ' entities</comment>'); |
|
| 216 | + $output->writeln('<comment>Indexed '.$entitiesIndexed.' entities</comment>'); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | * @required |
| 54 | 54 | */ |
| 55 | 55 | public function setObjectManager(EntityManagerInterface $om): void { |
| 56 | - if($this->objectManager) { |
|
| 56 | + if ($this->objectManager) { |
|
| 57 | 57 | return; |
| 58 | 58 | } |
| 59 | 59 | $this->objectManager = $om; |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | * @param ContainerBuilder $container |
| 17 | 17 | */ |
| 18 | 18 | public function process(ContainerBuilder $container): void { |
| 19 | - if(!$container->hasAlias(SearchService::class)) { |
|
| 19 | + if (!$container->hasAlias(SearchService::class)) { |
|
| 20 | 20 | return; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | $serviceId = (string)$container->getAlias(SearchService::class); |
| 24 | 24 | |
| 25 | - if(!$container->hasDefinition($serviceId)) { |
|
| 25 | + if (!$container->hasDefinition($serviceId)) { |
|
| 26 | 26 | return; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | $servicesMap = array(); |
| 32 | 32 | // Builds an array with fully-qualified type class names as keys and service IDs as values |
| 33 | - foreach($container->findTaggedServiceIds(FacetServiceInterface::TAG_NAME, true) as $serviceId => $tag) { |
|
| 33 | + foreach ($container->findTaggedServiceIds(FacetServiceInterface::TAG_NAME, true) as $serviceId => $tag) { |
|
| 34 | 34 | // Add form type service to the service locator |
| 35 | 35 | $serviceDefinition = $container->getDefinition($serviceId); |
| 36 | 36 | $servicesMap[$serviceDefinition->getClass()] = new Reference($serviceId); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function getFieldValue(string $fieldName) { |
| 86 | 86 | $value = $this->fields[$fieldName] ?? null; |
| 87 | - if(\in_array($fieldName, self::$forceSingleValueFields) && \is_array($value)) { |
|
| 87 | + if (\in_array($fieldName, self::$forceSingleValueFields) && \is_array($value)) { |
|
| 88 | 88 | return current($value); |
| 89 | 89 | } |
| 90 | 90 | return $value; |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | * @see \StingerSoft\EntitySearchBundle\Model\Document::addMultiValueField() |
| 98 | 98 | */ |
| 99 | 99 | public function addMultiValueField(string $fieldName, $value): void { |
| 100 | - if(!array_key_exists($fieldName, $this->fields)) { |
|
| 100 | + if (!array_key_exists($fieldName, $this->fields)) { |
|
| 101 | 101 | $this->fields[$fieldName] = array( |
| 102 | 102 | $value |
| 103 | 103 | ); |
| 104 | - } else if(!\is_array($this->fields[$fieldName])) { |
|
| 104 | + } else if (!\is_array($this->fields[$fieldName])) { |
|
| 105 | 105 | $this->fields[$fieldName] = array( |
| 106 | 106 | $value, $this->fields[$fieldName] |
| 107 | 107 | ); |
| 108 | - } else if(!\in_array($value, $this->fields[$fieldName])) { |
|
| 108 | + } else if (!\in_array($value, $this->fields[$fieldName])) { |
|
| 109 | 109 | $this->fields[$fieldName][] = $value; |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function setEntityClass(string $clazz): void { |
| 130 | 130 | $this->entityClass = $clazz; |
| 131 | - if(!$this->entityType) { |
|
| 131 | + if (!$this->entityType) { |
|
| 132 | 132 | $this->entityType = $clazz; |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -92,10 +92,10 @@ discard block |
||
| 92 | 92 | * @return array |
| 93 | 93 | */ |
| 94 | 94 | public function __get($name) { |
| 95 | - if(strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
| 95 | + if (strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
| 96 | 96 | $facetname = substr($name, 6); |
| 97 | 97 | |
| 98 | - if(isset($this->facets[$facetname])) { |
|
| 98 | + if (isset($this->facets[$facetname])) { |
|
| 99 | 99 | return $this->facets[$facetname]; |
| 100 | 100 | } |
| 101 | 101 | return []; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * The value of the property |
| 112 | 112 | */ |
| 113 | 113 | public function __set($name, $value): void { |
| 114 | - if(strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
| 114 | + if (strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
| 115 | 115 | $facetname = substr($name, 6); |
| 116 | 116 | $this->facets[$facetname] = $value; |
| 117 | 117 | } |