Skip to content

Commit 767d2ae

Browse files
committed
Fixed formatting
1 parent 07a1a27 commit 767d2ae

File tree

1 file changed

+61
-69
lines changed

1 file changed

+61
-69
lines changed

Resources/doc/cookbook/attachments.md

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,18 @@ Here is an example query that can be ran on attachments. This also includes an e
4242
for attachments.
4343

4444
```php
45-
46-
$keywordQuery = new QueryString();
47-
$keywordQuery->addParam(NULL, array('fuzziness' => 1));
48-
$keywordQuery->setQuery("$term~");
49-
$keywordQuery->setDefaultOperator('AND');
50-
51-
$query = new Query($keywordQuery);
52-
$query->setFields(array("id", "..."));
53-
$query->setHighlight(array(
54-
'fields' => array(
55-
'content' => new \stdClass()
56-
)
57-
));
58-
45+
$keywordQuery = new QueryString();
46+
$keywordQuery->addParam(NULL, array('fuzziness' => 1));
47+
$keywordQuery->setQuery("$term~");
48+
$keywordQuery->setDefaultOperator('AND');
49+
50+
$query = new Query($keywordQuery);
51+
$query->setFields(array("id", "..."));
52+
$query->setHighlight(array(
53+
'fields' => array(
54+
'content' => new \stdClass()
55+
)
56+
));
5957
```
6058

6159
Converting Attachments
@@ -66,27 +64,25 @@ This is an example of indexing documents in the required base64 encoding. You wi
6664
base64.
6765

6866
```php
69-
70-
public function getContent()
71-
{
72-
//Upload directory set at /web/uploads/library
73-
return base64_encode(file_get_contents($this->getUploadRootDir() . '/' . $this->filename, 'r'));
74-
}
75-
76-
protected function getUploadRootDir()
77-
{
78-
// the absolute directory path where uploaded
79-
// documents should be saved
80-
return __DIR__.'/../../../../web/'.$this->getUploadDir();
81-
}
82-
83-
protected function getUploadDir()
84-
{
85-
// get rid of the __DIR__ so it doesn't screw up
86-
// when displaying uploaded doc/image in the view.
87-
return 'uploads/library';
88-
}
89-
67+
public function getContent()
68+
{
69+
//Upload directory set at /web/uploads/library
70+
return base64_encode(file_get_contents($this->getUploadRootDir() . '/' . $this->filename, 'r'));
71+
}
72+
73+
protected function getUploadRootDir()
74+
{
75+
// the absolute directory path where uploaded
76+
// documents should be saved
77+
return __DIR__.'/../../../../web/'.$this->getUploadDir();
78+
}
79+
80+
protected function getUploadDir()
81+
{
82+
// get rid of the __DIR__ so it doesn't screw up
83+
// when displaying uploaded doc/image in the view.
84+
return 'uploads/library';
85+
}
9086
```
9187

9288
Handling Highlights
@@ -97,36 +93,34 @@ The interface requires the getId() and the setElasticHighlights() method. You wi
9793
methods to view the output. An example entity is displayed below.
9894

9995
```php
96+
use FOS\ElasticaBundle\Transformer\HighlightableModelInterface;
10097

101-
use FOS\ElasticaBundle\Transformer\HighlightableModelInterface;
98+
class Library implements HighlightableModelInterface {
10299

103-
class Library implements HighlightableModelInterface {
100+
private $id
104101

105-
private $id
106-
107-
private $highlights;
108-
109-
//Needs this method for HighlightableModelInterface
110-
public function getId()
111-
{
112-
return $this->id;
113-
}
114-
115-
//Needs this method for HighlightableModelInterface
116-
public function setElasticHighlights(array $highlights)
117-
{
118-
$this->highlights = $highlights;
119-
120-
return $this;
121-
}
122-
123-
public function getElasticHighlights()
124-
{
125-
return $this->highlights;
126-
}
102+
private $highlights;
127103

104+
//Needs this method for HighlightableModelInterface
105+
public function getId()
106+
{
107+
return $this->id;
108+
}
109+
110+
//Needs this method for HighlightableModelInterface
111+
public function setElasticHighlights(array $highlights)
112+
{
113+
$this->highlights = $highlights;
114+
115+
return $this;
116+
}
117+
118+
public function getElasticHighlights()
119+
{
120+
return $this->highlights;
128121
}
129122

123+
}
130124
```
131125

132126
Viewing Highlights in Twig
@@ -135,15 +129,13 @@ Viewing Highlights in Twig
135129
This is just a quick reference to obtaining the highlighted text returned by the query in a TWIG file.
136130

137131
```php
138-
139-
{% for highlights in reference.ElasticHighlights %}
140-
{% for highlight in highlights %}
141-
<tr class="alert alert-info">
142-
<td></td>
143-
<td></td>
144-
<td>{{ highlight|raw }}</td>
145-
</tr>
146-
{% endfor %}
132+
{% for highlights in reference.ElasticHighlights %}
133+
{% for highlight in highlights %}
134+
<tr class="alert alert-info">
135+
<td></td>
136+
<td></td>
137+
<td>{{ highlight|raw }}</td>
138+
</tr>
147139
{% endfor %}
148-
140+
{% endfor %}
149141
```

0 commit comments

Comments
 (0)