@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | public function addFacetValue($key, $value, $increaseCounterBy = 1) { |
33 | - if(!isset($this->facets[$key])){ |
|
33 | + if (!isset($this->facets[$key])) { |
|
34 | 34 | $this->facets[$key] = array(); |
35 | 35 | } |
36 | - if(!isset($this->facets[$key][$value])){ |
|
36 | + if (!isset($this->facets[$key][$value])) { |
|
37 | 37 | $this->facets[$key][$value] = 0; |
38 | 38 | } |
39 | 39 | $this->facets[$key][$value] = $this->facets[$key][$value] + $increaseCounterBy; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @see \StingerSoft\EntitySearchBundle\Model\Result\FacetSet::getFacet() |
47 | 47 | */ |
48 | 48 | public function getFacet($key) { |
49 | - if(isset($this->facets[$key])) { |
|
49 | + if (isset($this->facets[$key])) { |
|
50 | 50 | return $this->facets[$key]; |
51 | 51 | } else { |
52 | 52 | return; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | protected function updateEntity($entity, ObjectManager $manager) { |
99 | 99 | $document = $this->getEntityHandler()->createDocument($manager, $entity); |
100 | - if($document !== false) { |
|
100 | + if ($document !== false) { |
|
101 | 101 | $this->getSearchService($manager)->saveDocument($document); |
102 | 102 | } |
103 | 103 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function removeEntity($entity, ObjectManager $manager) { |
110 | 110 | $document = $this->getEntityHandler()->createDocument($manager, $entity); |
111 | - if($document !== false) { |
|
111 | + if ($document !== false) { |
|
112 | 112 | $this->getSearchService($manager)->removeDocument($document); |
113 | 113 | } |
114 | 114 | } |
@@ -46,18 +46,18 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function __construct(SearchService $searchService, array $mapping = array()) { |
48 | 48 | $this->searchService = $searchService; |
49 | - foreach($mapping as $key => $config) { |
|
50 | - if(!isset($config['mappings'])) { |
|
51 | - throw new \InvalidArgumentException($key . ' has no mapping defined!'); |
|
49 | + foreach ($mapping as $key => $config) { |
|
50 | + if (!isset($config['mappings'])) { |
|
51 | + throw new \InvalidArgumentException($key.' has no mapping defined!'); |
|
52 | 52 | } |
53 | - if(!isset($config['persistence'])) { |
|
54 | - throw new \InvalidArgumentException($key . ' has no persistence defined!'); |
|
53 | + if (!isset($config['persistence'])) { |
|
54 | + throw new \InvalidArgumentException($key.' has no persistence defined!'); |
|
55 | 55 | } |
56 | - if(!isset($config['persistence']['model'])) { |
|
57 | - throw new \InvalidArgumentException($key . ' has no model defined!'); |
|
56 | + if (!isset($config['persistence']['model'])) { |
|
57 | + throw new \InvalidArgumentException($key.' has no model defined!'); |
|
58 | 58 | } |
59 | 59 | $map = array(); |
60 | - foreach($config['mappings'] as $fieldKey => $fieldConfig) { |
|
60 | + foreach ($config['mappings'] as $fieldKey => $fieldConfig) { |
|
61 | 61 | $map[$fieldKey] = isset($fieldConfig['propertyPath']) && $fieldConfig['propertyPath'] ? $fieldConfig['propertyPath'] : $fieldKey; |
62 | 62 | } |
63 | 63 | |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | * @return boolean |
73 | 73 | */ |
74 | 74 | public function isIndexable($object) { |
75 | - if($object instanceof SearchableEntity) { |
|
75 | + if ($object instanceof SearchableEntity) { |
|
76 | 76 | return true; |
77 | 77 | } |
78 | - if(count($this->getMapping($object)) > 0) { |
|
78 | + if (count($this->getMapping($object)) > 0) { |
|
79 | 79 | return true; |
80 | 80 | } |
81 | 81 | return false; |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | * @return boolean|Document Returns false if no document could be created |
90 | 90 | */ |
91 | 91 | public function createDocument(ObjectManager $manager, $object) { |
92 | - if(!$this->isIndexable($object)) |
|
92 | + if (!$this->isIndexable($object)) |
|
93 | 93 | return false; |
94 | 94 | $document = $this->getSearchService($manager)->createEmptyDocumentFromEntity($object); |
95 | 95 | $index = $this->fillDocument($document, $object); |
96 | - if($index == false) |
|
96 | + if ($index == false) |
|
97 | 97 | return false; |
98 | 98 | |
99 | 99 | return $document; |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | * @param object $object |
107 | 107 | * @return boolean |
108 | 108 | */ |
109 | - protected function fillDocument(Document &$document, $object) { |
|
110 | - if($object instanceof SearchableEntity) { |
|
109 | + protected function fillDocument(Document&$document, $object) { |
|
110 | + if ($object instanceof SearchableEntity) { |
|
111 | 111 | return $object->indexEntity($document); |
112 | 112 | } |
113 | 113 | $mapping = $this->getMapping($object); |
114 | 114 | $accessor = PropertyAccess::createPropertyAccessor(); |
115 | - foreach($mapping as $fieldName => $propertyPath) { |
|
115 | + foreach ($mapping as $fieldName => $propertyPath) { |
|
116 | 116 | $document->addField($fieldName, $accessor->getValue($object, $propertyPath)); |
117 | 117 | } |
118 | 118 | return true; |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | */ |
127 | 127 | protected function getMapping($object) { |
128 | 128 | $clazz = get_class($object); |
129 | - if(isset($this->cachedMapping[$clazz])) { |
|
129 | + if (isset($this->cachedMapping[$clazz])) { |
|
130 | 130 | return $this->cachedMapping[$clazz]; |
131 | 131 | } |
132 | 132 | $ref = new \ReflectionClass($clazz); |
133 | 133 | |
134 | 134 | $mapping = array(); |
135 | 135 | |
136 | - foreach($this->mapping as $className => $config) { |
|
137 | - if($clazz == $className || $ref->isSubclassOf($className)) { |
|
136 | + foreach ($this->mapping as $className => $config) { |
|
137 | + if ($clazz == $className || $ref->isSubclassOf($className)) { |
|
138 | 138 | $mapping = array_merge($mapping, $config); |
139 | 139 | } |
140 | 140 | } |
@@ -89,12 +89,14 @@ |
||
89 | 89 | * @return boolean|Document Returns false if no document could be created |
90 | 90 | */ |
91 | 91 | public function createDocument(ObjectManager $manager, $object) { |
92 | - if(!$this->isIndexable($object)) |
|
93 | - return false; |
|
92 | + if(!$this->isIndexable($object)) { |
|
93 | + return false; |
|
94 | + } |
|
94 | 95 | $document = $this->getSearchService($manager)->createEmptyDocumentFromEntity($object); |
95 | 96 | $index = $this->fillDocument($document, $object); |
96 | - if($index == false) |
|
97 | - return false; |
|
97 | + if($index == false) { |
|
98 | + return false; |
|
99 | + } |
|
98 | 100 | |
99 | 101 | return $document; |
100 | 102 | } |
@@ -65,15 +65,15 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function execute(InputInterface $input, OutputInterface $output) { |
67 | 67 | // Detect upload path |
68 | - if(!self::$defaultUploadPath) { |
|
68 | + if (!self::$defaultUploadPath) { |
|
69 | 69 | $root = $this->getContainer()->get('kernel')->getRootDir(); |
70 | - self::$defaultUploadPath = $root . '/../web/uploads'; |
|
70 | + self::$defaultUploadPath = $root.'/../web/uploads'; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Get the entity argument |
74 | 74 | $entity = $input->getArgument('entity'); |
75 | 75 | |
76 | - if($entity == 'all') { |
|
76 | + if ($entity == 'all') { |
|
77 | 77 | // $indexHandler = $this->getIndexHandler(); |
78 | 78 | // $entities = $indexHandler->getSearchableEntities(); |
79 | 79 | // foreach($entities as $bundle => $searchableEntities) { |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | try { |
99 | 99 | // Get repository for the given entity type |
100 | 100 | $repository = $entityManager->getRepository($entity); |
101 | - } catch(\Exception $e) { |
|
101 | + } catch (\Exception $e) { |
|
102 | 102 | $output->writeln(sprintf('<error>No repository found for "%s", check your input</error>', $entity)); |
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Get all entities |
107 | 107 | $entities = $repository->findAll(); |
108 | - if(count($entities) == 0) { |
|
108 | + if (count($entities) == 0) { |
|
109 | 109 | $output->writeln('<comment>No entities found for indexing</comment>'); |
110 | 110 | return; |
111 | 111 | } |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | $entitiesIndexed = 0; |
114 | 114 | |
115 | 115 | // Index each entity seperate |
116 | - foreach($entities as $entity) { |
|
117 | - if($this->getEntityToDocumentMapper()->isIndexable($entity)){ |
|
116 | + foreach ($entities as $entity) { |
|
117 | + if ($this->getEntityToDocumentMapper()->isIndexable($entity)) { |
|
118 | 118 | $document = $this->getEntityToDocumentMapper()->createDocument($entityManager, $entity); |
119 | 119 | $this->getSearchService($entityManager)->saveDocument($document); |
120 | 120 | $entitiesIndexed++; |
121 | 121 | } |
122 | 122 | } |
123 | - $output->writeln('<comment>Indexed ' . $entitiesIndexed . ' entities</comment>'); |
|
123 | + $output->writeln('<comment>Indexed '.$entitiesIndexed.' entities</comment>'); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return EntityToDocumentMapperInterface |
129 | 129 | */ |
130 | 130 | protected function getEntityToDocumentMapper() { |
131 | - if(!$this->entityToDocumentMapper) { |
|
131 | + if (!$this->entityToDocumentMapper) { |
|
132 | 132 | $this->entityToDocumentMapper = $this->getContainer()->get(EntityToDocumentMapperInterface::SERVICE_ID); |
133 | 133 | } |
134 | 134 | return $this->entityToDocumentMapper; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @return SearchService |
140 | 140 | */ |
141 | 141 | protected function getSearchService(ObjectManager $manager) { |
142 | - if(!$this->searchService) { |
|
142 | + if (!$this->searchService) { |
|
143 | 143 | $this->searchService = $this->getContainer()->get(SearchService::SERVICE_ID); |
144 | 144 | } |
145 | 145 | $this->searchService->setObjectManager($manager); |
@@ -25,7 +25,6 @@ |
||
25 | 25 | * Tries to create a document from the given object |
26 | 26 | * |
27 | 27 | * @param ObjectManager $manager |
28 | - * @param object $object |
|
29 | 28 | * @return boolean|Document Returns false if no document could be created |
30 | 29 | */ |
31 | 30 | public function getEntity(ObjectManager $manager, Document $document); |
@@ -66,8 +66,9 @@ |
||
66 | 66 | $choices = array(); |
67 | 67 | |
68 | 68 | foreach($facets as $facet => $count) { |
69 | - if($count == 0) |
|
70 | - break; |
|
69 | + if($count == 0) { |
|
70 | + break; |
|
71 | + } |
|
71 | 72 | $choices[$facet] = $facet . ' (' . $count . ')'; |
72 | 73 | } |
73 | 74 | return $choices; |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | )); |
37 | 37 | |
38 | 38 | $usedFacets = $options['used_facets']; |
39 | - if($usedFacets){ |
|
40 | - foreach($usedFacets as $facetType) { |
|
41 | - $builder->add('facet_' . $facetType, FacetType::class, array( |
|
42 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
39 | + if ($usedFacets) { |
|
40 | + foreach ($usedFacets as $facetType) { |
|
41 | + $builder->add('facet_'.$facetType, FacetType::class, array( |
|
42 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
43 | 43 | 'multiple' => true, |
44 | 44 | 'expanded' => true, |
45 | 45 | )); |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | * @param FacetSet $facets |
76 | 76 | */ |
77 | 77 | protected function createFacets(FormBuilderInterface $builder, FacetSet $facets) { |
78 | - foreach($facets->getFacets() as $facetType => $facetValues) { |
|
79 | - $builder->add('facet_' . $facetType, ChoiceType::class, array( |
|
80 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
78 | + foreach ($facets->getFacets() as $facetType => $facetValues) { |
|
79 | + $builder->add('facet_'.$facetType, ChoiceType::class, array( |
|
80 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
81 | 81 | 'multiple' => true, |
82 | 82 | 'expanded' => true, |
83 | 83 | 'choices_as_values' => true, |
84 | - 'property_path' => 'facets[' . $facetType . ']', |
|
84 | + 'property_path' => 'facets['.$facetType.']', |
|
85 | 85 | 'choices' => $this->generateFacetChoices($facetType, $facetValues) |
86 | 86 | )); |
87 | 87 | } |
@@ -95,10 +95,10 @@ discard block |
||
95 | 95 | protected function generateFacetChoices($facetType, array $facets) { |
96 | 96 | $choices = array(); |
97 | 97 | |
98 | - foreach($facets as $facet => $count) { |
|
99 | - if($count == 0) |
|
98 | + foreach ($facets as $facet => $count) { |
|
99 | + if ($count == 0) |
|
100 | 100 | break; |
101 | - $choices[$facet . ' (' . $count . ')'] = $facet; |
|
101 | + $choices[$facet.' ('.$count.')'] = $facet; |
|
102 | 102 | } |
103 | 103 | return $choices; |
104 | 104 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $id = $document->getEntityClass(); |
30 | 30 | $id .= '#'; |
31 | 31 | $entityId = $document->getEntityId(); |
32 | - if(is_scalar($entityId)) { |
|
32 | + if (is_scalar($entityId)) { |
|
33 | 33 | $id .= $entityId; |
34 | 34 | } else { |
35 | 35 | $id .= md5(serialize($entityId)); |
@@ -75,15 +75,15 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function autocomplete($search, $maxResults = 10) { |
77 | 77 | $words = array(); |
78 | - foreach($this->index as $doc) { |
|
79 | - foreach($doc->getFields() as $content) { |
|
80 | - if(is_string($content)) { |
|
78 | + foreach ($this->index as $doc) { |
|
79 | + foreach ($doc->getFields() as $content) { |
|
80 | + if (is_string($content)) { |
|
81 | 81 | $words = array_merge($words, explode(' ', $content)); |
82 | 82 | } |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - return array_filter($words, function ($word) use ($search) { |
|
86 | + return array_filter($words, function($word) use ($search) { |
|
87 | 87 | return stripos($word, $search) === 0; |
88 | 88 | }); |
89 | 89 | } |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | $facets = new FacetSetAdapter(); |
102 | 102 | |
103 | 103 | $hits = array(); |
104 | - foreach($this->index as $key => $doc) { |
|
105 | - foreach($doc->getFields() as $content) { |
|
106 | - if(is_string($content) && stripos($content, $term) !== false) { |
|
107 | - if(!isset($hits[$key])) { |
|
104 | + foreach ($this->index as $key => $doc) { |
|
105 | + foreach ($doc->getFields() as $content) { |
|
106 | + if (is_string($content) && stripos($content, $term) !== false) { |
|
107 | + if (!isset($hits[$key])) { |
|
108 | 108 | $hits[$key] = 0; |
109 | 109 | } |
110 | 110 | $hits[$key] = $hits[$key] + 1; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | } |
114 | 114 | arsort($hits); |
115 | 115 | $results = array(); |
116 | - foreach(array_keys($hits) as $docId) { |
|
116 | + foreach (array_keys($hits) as $docId) { |
|
117 | 117 | $doc = $this->index[$docId]; |
118 | 118 | $facets->addFacetValue(FacetSet::FACET_ENTITY_TYPE, $doc->getEntityClass()); |
119 | 119 | $facets->addFacetValue(FacetSet::FACET_AUTHOR, $doc->getFieldValue(Document::FIELD_AUTHOR)); |
@@ -11,11 +11,9 @@ |
||
11 | 11 | */ |
12 | 12 | namespace StingerSoft\EntitySearchBundle\Form; |
13 | 13 | |
14 | -use StingerSoft\EntitySearchBundle\Model\Query; |
|
15 | 14 | use StingerSoft\EntitySearchBundle\Model\Result\FacetSet; |
16 | 15 | use StingerSoft\EntitySearchBundle\Model\ResultSet; |
17 | 16 | use Symfony\Component\Form\AbstractType; |
18 | -use Symfony\Component\Form\ChoiceList\LazyChoiceList; |
|
19 | 17 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
20 | 18 | use Symfony\Component\Form\FormBuilderInterface; |
21 | 19 | use Symfony\Component\Form\FormEvent; |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | $builder->resetModelTransformers(); |
37 | 37 | $builder->resetViewTransformers(); |
38 | 38 | |
39 | - if($options['multiple']) { |
|
40 | - $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { |
|
39 | + if ($options['multiple']) { |
|
40 | + $builder->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) { |
|
41 | 41 | $event->stopPropagation(); |
42 | 42 | }, 1); |
43 | 43 | } |
44 | - $builder->addEventListener(FormEvents::SUBMIT, function(FormEvent $event){ |
|
44 | + $builder->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) { |
|
45 | 45 | $data = $event->getForm()->getExtraData(); |
46 | 46 | $event->setData(array_unique(array_merge($data, $event->getData()))); |
47 | 47 | }); |
@@ -69,13 +69,13 @@ discard block |
||
69 | 69 | * @param FacetSet $facets |
70 | 70 | */ |
71 | 71 | protected function createFacets(FormBuilderInterface $builder, FacetSet $facets) { |
72 | - foreach($facets->getFacets() as $facetType => $facetValues) { |
|
73 | - $builder->add('facet_' . $facetType, ChoiceType::class, array( |
|
74 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
72 | + foreach ($facets->getFacets() as $facetType => $facetValues) { |
|
73 | + $builder->add('facet_'.$facetType, ChoiceType::class, array( |
|
74 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
75 | 75 | 'multiple' => true, |
76 | 76 | 'expanded' => true, |
77 | 77 | 'choices_as_values' => true, |
78 | - 'property_path' => 'facets[' . $facetType . ']', |
|
78 | + 'property_path' => 'facets['.$facetType.']', |
|
79 | 79 | 'choices' => $this->generateFacetChoices($facetType, $facetValues) |
80 | 80 | )); |
81 | 81 | } |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | protected function generateFacetChoices($facetType, array $facets) { |
90 | 90 | $choices = array(); |
91 | 91 | |
92 | - foreach($facets as $facet => $count) { |
|
93 | - if($count == 0) |
|
92 | + foreach ($facets as $facet => $count) { |
|
93 | + if ($count == 0) |
|
94 | 94 | break; |
95 | - $choices[$facet . ' (' . $count . ')'] = $facet; |
|
95 | + $choices[$facet.' ('.$count.')'] = $facet; |
|
96 | 96 | } |
97 | 97 | return $choices; |
98 | 98 | } |
@@ -66,8 +66,9 @@ |
||
66 | 66 | $choices = array(); |
67 | 67 | |
68 | 68 | foreach($facets as $facet => $count) { |
69 | - if($count == 0) |
|
70 | - break; |
|
69 | + if($count == 0) { |
|
70 | + break; |
|
71 | + } |
|
71 | 72 | $choices[$facet] = $facet . ' (' . $count . ')'; |
72 | 73 | } |
73 | 74 | return $choices; |
@@ -45,7 +45,7 @@ |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | |
48 | - public function testWithNotExistingFacets(){ |
|
48 | + public function testWithNotExistingFacets() { |
|
49 | 49 | |
50 | 50 | $query = new Query('Hemelinger', array(), array( |
51 | 51 | Document::FIELD_TYPE |