Skip to content

Commit f243bc7

Browse files
author
Charles THIBAULT
committed
Update version
1 parent df8230f commit f243bc7

File tree

2 files changed

+341
-10
lines changed

2 files changed

+341
-10
lines changed

afs_version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/** @brief API fix version number.
1616
*
1717
* You should increase this number as soon as a bug is fixed.*/
18-
define('AFS_API_VERSION_FIX', 2);
18+
define('AFS_API_VERSION_FIX', 3);
1919

2020
/** @brief API full version number. */
2121
define('AFS_API_VERSION', implode('.', array(AFS_API_VERSION_MAJOR, AFS_API_VERSION_MINOR, AFS_API_VERSION_FIX)));

doc/data/raw_example.php

Lines changed: 340 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,355 @@
22
/** @file raw_example.php
33
* @example raw_example.php
44
*/
5-
65
require_once "PHP_API/afs_lib.php";
7-
8-
$search = new AfsSearch('http://poc-afsstore.afs-antidot.net/', 30005);
9-
6+
$search = new AfsSearch('eval.partners.antidot.net', 48000);
107
$query = $search->build_query_from_url_parameters();
118
$query = $query->set_lang('fr'); // language is set manually in order to get spellcheck results
129
$query = $query->set_multi_selection_facets('classification');
1310
$query = $query->set_mono_selection_facets('afs:lang', 'has_variants', 'has_image');
1411
$query = $query->set_facet_order('price_eur', 'marketing', 'classification', 'has_variants', 'has_image');
1512
$query = $query->set_facets_values_sort_order(AfsFacetValuesSortMode::ITEMS, AfsSortOrder::DESC);
16-
1713
$helper = $search->execute($query);
1814
$generated_url = $search->get_generated_url();
19-
2015
$clustering_is_active = $query->has_cluster();
2116
$nsmap = array('ns' => 'http://ref.antidot.net/store/afs#');
17+
?>
18+
19+
20+
<html>
21+
<head>
22+
<title>Antidot PHP API - Raw example</title>
23+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
24+
<meta charset="UTF-8">
25+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
26+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
27+
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
28+
<!--[if lt IE 9]>
29+
<script src="../../assets/js/html5shiv.js"></script>
30+
<script src="../../assets/js/respond.min.js"></script>
31+
<![endif]-->
32+
</head>
33+
<body>
34+
<div>
35+
<a href="<?php echo $generated_url; ?>" target="_blank"><?php echo $generated_url; ?></a>
36+
</div>
37+
<div class="page-header">
38+
<h1>Raw example <small>based on the Antidot PHP API</small></h1>
39+
</div>
40+
<!-- ####################### Search box ########################### -->
41+
<div class="row">
42+
<div class="col-md-5"></div>
43+
<div class="input-group col-md-2">
44+
<form method="get" action="" role="form" class="input-group">
45+
<span class="input-group-addon">Search</span>
46+
<input type="search" name="query" class="form-control" placeholder="Keywords" />
47+
<span class="input-group-btn">
48+
<button class="btn btn-primary" type="submit"><span class="glyphicon glyphicon-search"></span></button>
49+
</span>
50+
</form>
51+
</div>
52+
</div>
53+
54+
<!-- ####################### Current filter parameters ########################### -->
55+
<?php
56+
$params = $query->get_parameters(false);
57+
if (array_key_exists('filter', $params) && is_array($params['filter'])) {
58+
echo '
59+
<div class="row">
60+
<div class="col-md-8">';
61+
foreach ($params['filter'] as $filter => $values) {
62+
echo '
63+
<ul>Filter: <strong>' . $filter . '</strong>';
64+
foreach ($values as $value) {
65+
echo '
66+
<li>Value: ' . $value . '</li>';
67+
}
68+
echo '
69+
</ul>';
70+
}
71+
echo '
72+
</div>
73+
</div>';
74+
} ?>
75+
76+
<!-- ####################### Promote ########################### -->
77+
<?php
78+
if ($helper->has_promote()) {
79+
echo '
80+
<div class="row">
81+
<div class="col-md-3"></div>';
82+
foreach ($helper->get_promotes() as $promote) {
83+
echo '
84+
<div class="col-md-2">
85+
<h4><span class="label label-danger">' . $promote->get_title() . '</span></h4>
86+
<p>' . $promote->get_abstract() . '</p>
87+
<ul>Some custom data:
88+
<li>tag: ' . $promote->get_custom_data('tag') . '</li>
89+
<li>identifier: ' . $promote->get_custom_data('id') . '</li>
90+
</ul>
91+
<ul>Or loop on custom data:';
92+
foreach ($promote->get_custom_data() as $key => $value) {
93+
echo '
94+
<li><strong>' . $key . '</strong>: ' . $value . '</li>';
95+
}
96+
echo '
97+
</ul>
98+
</div>';
99+
}
100+
echo '
101+
</div>
102+
</div>';
103+
} ?>
104+
105+
<?php
106+
// checks whether there is at least one replyset
107+
if ($helper->has_replyset()) {
108+
$replyset = $helper->get_replyset(); // Retrieves only first replyset
109+
if ($replyset->has_facet()) {
110+
/* if (in_array('facets', $replyset)) */
111+
?>
112+
<div class="row">
113+
<div class="col-md-3">
114+
<h2>Filters</h2>
115+
<!-- ####################### Filters ########################### -->
116+
<?php
117+
foreach ($replyset->get_facets() as $facet) {
118+
/* foreach ($replyset->facets->facet as $facet) */
119+
?>
120+
<div class="panel panel-default">
121+
<div class="panel-heading"><?php echo $facet->get_label() ?></div> <!-- $facet->labels[0]->label -->
122+
<div class="panel-body">
123+
<div class="list-group">
124+
<div class="list-group">
125+
<?php
126+
foreach ($facet->get_elements() as $value) {
127+
/* $item = null;
128+
* if ($facet->{'afs:t'} == 'FacetTree') {
129+
* $item = 'node';
130+
* } elif ($facet->{'afs:t'} == 'FacetInterval') {
131+
* $item = 'interval;
132+
* } else {
133+
* throw new Exception('Unknown facet layout: ' . $facet->{'afs:t'});
134+
* }
135+
* foreach ($facet->$item as $value) */
136+
?>
137+
<a class="list-group-item <?php echo ($value->active ? 'active' : '') ?>" href="<?php echo $value->link ?>"><?php echo $value->label ?><span class="badge"><?php echo $value->count ?></span></a>
138+
<!-- $active = $query->has_filter($facet->id, $value->key);
139+
...
140+
-->
141+
<?php } ?>
142+
</div>
143+
</div>
144+
</div>
145+
</div>
146+
<?php } ?>
147+
</div>
148+
<?php } ?>
149+
150+
<div class="col-md-9">
151+
<div class="row page-header">
152+
<div class="col-md-1"></div>
153+
<div class="col-md-2">
154+
<h2>Results <span class="label label-success"><?php echo $replyset->get_meta()->get_total_replies() ?></span></h2>
155+
<h4><span class="label label-info">Duration <?php echo $replyset->get_meta()->get_duration() ?> ms</span></h4>
156+
</div>
157+
<div class="col-md-1"></div>
158+
<div class="col-md-2">
159+
<!-- ####################### Relevance ########################### -->
160+
<?php
161+
if ($query->has_sort(AfsSortBuiltins::RELEVANCE)) {
162+
if ($query->get_sort_order(AfsSortBuiltins::RELEVANCE) == AfsSortOrder::ASC) {
163+
$relevance_icon = 'glyphicon-arrow-up';
164+
$relevance_query = $query->add_sort(AfsSortBuiltins::RELEVANCE, AfsSortOrder::DESC);
165+
} else {
166+
$relevance_icon = 'glyphicon-arrow-down';
167+
$relevance_query = $query->add_sort(AfsSortBuiltins::RELEVANCE, AfsSortOrder::ASC);
168+
}
169+
} else {
170+
$relevance_query = $query->add_sort(AfsSortBuiltins::RELEVANCE, AfsSortOrder::ASC);
171+
$relevance_icon = 'glyphicon-arrow-down';
172+
}
173+
$relevance_link = $search->get_helpers_configuration()->get_query_coder()->generate_link($relevance_query);
174+
?>
175+
<a href="<?php echo $relevance_link ?>" class="btn btn-default btn-lg active" role="button"><span class="glyphicon <?php echo $relevance_icon; ?>"></span> Relevance</a>
176+
</div>
177+
<div class="col-md-2">
178+
<?php
179+
$query_coder = $search->get_helpers_configuration()->get_query_coder();
180+
if ($clustering_is_active) {
181+
$cluster_query = $query->unset_cluster();
182+
$cluster_link = $query_coder->generate_link($query->unset_cluster());
183+
$cluster_label = 'Remove clusters';
184+
} else {
185+
$cluster_link = $query_coder->generate_link($query->set_cluster('marketing', 1)->set_overspill());
186+
$cluster_label = 'Create cluster on "marketing" filter';
187+
} ?>
188+
<a href="<?php echo $cluster_link ?>" class="btn btn-default btn-lg active" role="button"><?php echo $cluster_label ?></a>
189+
</div>
190+
</div>
191+
192+
<!-- ####################### Clusters ########################### -->
193+
<?php
194+
if ($clustering_is_active) {
195+
foreach ($replyset->get_clusters() as $cluster) {
196+
echo '
197+
<div class="row">
198+
<div class="col-md-1"></div>
199+
<div class="col-md-5">
200+
<h3>
201+
<span class="label label-success">
202+
<a href="' . $query_coder->generate_link($cluster->get_query()) . '">' . $cluster->get_label() . '<a>
203+
</span>
204+
</h3>
205+
</div>
206+
</div>
207+
<ul class="list-unstyled">';
208+
foreach ($cluster->get_replies() as $reply) {
209+
echo '
210+
<li>
211+
<h3>' . $reply->get_title() . '</h3>
212+
<p><a href="' . $reply->get_uri() . '">' . $reply->get_uri() . '</a></p>
213+
<p>' . $reply->get_abstract() . '</p>
214+
<p>Some client data:
215+
<ul>
216+
<li>Name: ' . $reply->get_clientdata()->get_value('/ns:product/ns:name', $nsmap) . '</li>
217+
<li>Availability: ' . $reply->get_clientdata()->get_value('/ns:product/ns:is_available', $nsmap) . '</li>
218+
<li>Prices:
219+
<ul>';
220+
// Here multiple values are retrieved from client data
221+
foreach ($reply->get_clientdata()->get_values('/ns:product/ns:prices/ns:price', $nsmap) as $value)
222+
echo '<li>' . $value . '</li>';
223+
echo '
224+
</ul>
225+
</li>
226+
</ul>
227+
</p>
228+
</li>';
229+
}
230+
echo '
231+
</ul>';
232+
}
233+
echo '
234+
<div class="row">
235+
<div class="col-md-1"></div>
236+
<div class="col-md-5">
237+
<h3><span class="label label-success">Other results</span></h3>
238+
</div>
239+
</div>';
240+
} ?>
241+
242+
<!-- ####################### Replies ########################### -->
243+
<?php
244+
echo '
245+
<ul class="list-unstyled">';
246+
foreach ($replyset->get_replies() as $reply) {
247+
?>
248+
<li>
249+
<h3><?php echo $reply->get_title() ?></h3>
250+
<p><a href="<?php echo $reply->get_uri() ?>"><?php echo $reply->get_uri() ?></a></p>
251+
<p><?php echo $reply->get_abstract() ?></p>
252+
<p>Some client data:
253+
<ul>
254+
<li>Name: <?php echo $reply->get_clientdata()->get_value('/ns:product/ns:name', $nsmap) ?></li>
255+
<li>Availability: <?php echo $reply->get_clientdata()->get_value('/ns:product/ns:is_available', $nsmap) ?></li>
256+
<li>Prices:
257+
<ul>
258+
<?php
259+
// Here multiple values are retrieved from client data
260+
foreach ($reply->get_clientdata()->get_values('/ns:product/ns:prices/ns:price', $nsmap) as $value) {
261+
echo '<li>' . $value . '</li>';
262+
} ?>
263+
</ul>
264+
</li>
265+
</ul>
266+
</p>
267+
</li>
268+
<?php } ?>
269+
</ul>
270+
</div>
271+
</div>
272+
273+
<!-- ####################### Pager ########################### -->
274+
<?php
275+
if ($replyset->has_pager()) {
276+
$pager = $replyset->get_pager();
277+
?>
278+
<div class="row">
279+
<div class="row">
280+
<div class="col-md-5"></div>
281+
<div class="input-group col-md-3">
282+
<ul class="pagination">
283+
<?php
284+
foreach ($pager->get_all_pages() as $page => $url) {
285+
if ($page == $pager->get_current_no()) {
286+
$active = 'active';
287+
} else {
288+
$active = '';
289+
}
290+
?>
291+
<li class="<?php echo $active ?>"><a href="<?php echo $url ?>"><?php echo $page ?></a></li>
292+
<?php } ?>
293+
294+
</ul>
295+
</div>
296+
</div>
297+
<?php } ?>
298+
299+
</div>
300+
301+
<!-- ####################### Spellcheck ########################### -->
302+
<?php } elseif ($helper->has_spellcheck()) { // if no replyset, let's check spellcheck ?>
303+
<div class="row">
304+
<div class="col-md-9">
305+
<div class="row">
306+
<div class="col-md-1"></div>
307+
<div class="col-md-4">
308+
<h2>Typo ?</h2>
309+
</div>
310+
</div>
311+
<?php
312+
foreach ($helper->get_spellchecks() as $feed => $suggestions) {
313+
?>
314+
<div class="row">
315+
<div class="col-md-6">
316+
<h4><?php echo $feed ?></h4>
317+
<ul class="list-unstyled">
318+
<?php
319+
foreach ($suggestions as $suggest) {
320+
?>
321+
<li>
322+
<h3>Did you mean...</h3>
323+
<p><a href="<?php echo $suggest->get_link() ?>"><?php echo $suggest->get_formatted_text() ?></a></p>
324+
</li>
325+
<?php } ?>
326+
</ul>
327+
</div>
328+
</div>
329+
<?php } ?>
330+
</div>
331+
</div>
332+
<!-- ####################### Error ########################### -->
333+
<?php } elseif ($helper->in_error()) { // no spellcheck... is there any error? ?>
334+
<div class="row">
335+
<div class="col-md-9">
336+
<div class="row">
337+
<div class="col-md-1"></div>
338+
<div class="col-md-4">
339+
<h2>Really bad error occured</h2>
340+
</div>
341+
</div>
342+
<div class="row">
343+
<div class="col-md-10">
344+
<h2><?php echo $helper->get_error_msg() ?></h2>
345+
</div>
346+
</div>
347+
</div>
348+
</div>
349+
<?php } ?>
22350

23-
for ($helper->get_promotes() => $promote) {
24-
$clientdata = $promote->get_custom_data();
25-
}
351+
<!-- jQuery (necessary for Bootstrap\'s JavaScript plugins) -->
352+
<script src="//code.jquery.com/jquery.js"></script>
353+
<!-- Include all compiled plugins (below), or include individual files as needed -->
354+
<script src="js/bootstrap.min.js"></script>
355+
</body>
356+
</html>

0 commit comments

Comments
 (0)