private function initialize_replysets($replysets, AfsQuery $query, AfsHelperConfiguration $config)
 {
     foreach ($replysets as $replyset) {
         if (property_exists($replyset, 'meta') && property_exists($replyset->meta, 'producer')) {
             $producer = $replyset->meta->producer;
             if ($producer == AfsProducer::SEARCH) {
                 if ('Promote' == $replyset->meta->uri) {
                     $this->promote = new AfsPromoteReplysetHelper($replyset, $this->config);
                 } else {
                     $replyset_helper = new AfsReplysetHelper($replyset, $query, $config);
                     $feed = $replyset_helper->get_meta()->get_feed();
                     if ($config->is_array_format()) {
                         $this->replysets[$feed] = $replyset_helper->format();
                     } else {
                         $this->replysets[$feed] = $replyset_helper;
                     }
                 }
             } elseif ($producer == AfsProducer::SPELLCHECK) {
                 $this->spellcheck_mgr->add_spellcheck($replyset);
             } elseif ($producer == AfsProducer::CONCEPT) {
                 $this->concepts->add_concept($replyset);
             }
         }
     }
     if ($config->is_array_format()) {
         if (!is_null($this->promote)) {
             $this->promote = $this->promote->format();
         }
     }
 }
 /** @brief Construct new replyset helper instance.
  *
  * @param $reply_set [in] one reply from decoded json reply.
  * @param $query [in] query which has produced current reply.
  * @param $config [in] helper configuration object.
  */
 public function __construct($reply_set, AfsQuery $query, AfsHelperConfiguration $config)
 {
     $reply_helper_factory = new AfsReplyHelperFactory($config->get_reply_text_visitor());
     parent::__construct($reply_set, $config, $reply_helper_factory);
     $this->initialize_facet($reply_set, $query, $config);
     $this->initialize_cluster($reply_set, $query, $config);
     $this->initialize_pager($reply_set, $query, $config);
 }
Beispiel #3
0
 /** @brief Constructs new cluster helper instance.
  *
  * @param $cluster [in] One cluster reply.
  * @param $meta [in] Reply set meta data.
  * @param $facet_helper [in] Facet helper (used to retrieve value label).
  * @param $query [in] AfsQuery object previously initialized. It is used to
  *        generate new query to filter on this cluster reply.
  * @param $config [in] Helper configuration.
  */
 public function __construct($cluster, AfsMetaHelper $meta, $facet_helper, AfsQuery $query, AfsHelperConfiguration $config)
 {
     $formatter = AfsFacetHelperRetriever::get_formatter($meta->get_cluster_id(), $query);
     $this->id = $formatter->format($cluster->id);
     $this->initialize_label($facet_helper);
     $this->total_replies = $cluster->totalItems;
     $factory = new AfsReplyHelperFactory($config->get_reply_text_visitor());
     $this->replies = $factory->create_replies($meta->get_feed(), $cluster);
     $this->query = $query->auto_set_from()->unset_cluster()->add_filter($meta->get_cluster_id(), $this->id);
     $this->config = $config;
 }
 public function testBlabla()
 {
     $client_data = '<afs:type xmlns:afs=\\"http://ref.antidot.net/7.3/bo.xsd\\">default</afs:type><afs:customData xmlns:afs=\\"http://ref.antidot.net/7.3/bo.xsd\\"><afs:key1>v1</afs:key1></afs:customData>';
     $input = json_decode('{
         "header": {
             "query": {
                 "userId": "afd070b6-4315-40cc-975d-747e28bf132a",
                 "sessionId": "5bf5642d-a262-4608-9901-45aa6e87325d",
                 "date": "2013-10-02T15:48:41+0200",
                 "queryParam": [
                     {
                         "name": "afs:service",
                         "value": "42"
                     }
                 ],
                 "mainCtx": { "textQuery": "title" },
                 "textQuery": "title"
             },
             "user": {
                 "requestMethod": "GET",
                 "agent": "Mozilla/5.0 (X11; Linux x86_64; rv:23.0) Gecko/20100101 Firefox/23.0 Iceweasel/23.0",
                 "address": "127.0.0.1",
                 "output": {
                     "format": "JSON",
                     "encoding": "gzip",
                     "charset": "UTF-8"
                 }
             },
             "performance": { "durationMs": 666 },
             "info": { }
         },
         "replySet": [
             {
                 "meta": {
                     "uri": "Promote",
                     "totalItems": 200,
                     "totalItemsIsExact": true,
                     "pageItems": 2,
                     "firstPageItem": 3,
                     "lastPageItem": 4,
                     "durationMs": 42,
                     "firstPaFId": 1,
                     "lastPaFId": 1,
                     "producer": "SEARCH"
                 },
                 "facets": {
                     "facet": [
                         {
                             "afs:t": "FacetTree",
                             "node": [
                                 {
                                     "key": "false",
                                     "labels": [ { "label": "BAD" } ],
                                     "items": 67
                                 },
                                 {
                                     "key": "true",
                                     "labels": [ { "label": "GOOD" } ],
                                     "items": 133
                                 }
                             ],
                             "layout": "TREE",
                             "type": "BOOL",
                             "id": "BOOL",
                             "labels": [ { "label": "Boolean facet" } ]
                         }
                     ]
                 },
                 "content": {
                     "reply": [
                         {
                             "docId": 198,
                             "uri": "http://foo.bar.baz/116",
                             "title": [
                                 {
                                     "afs:t": "KwicString",
                                     "text": "The "
                                 },
                                 {
                                     "afs:t": "KwicMatch",
                                     "match": "title"
                                 },
                                 {
                                     "afs:t": "KwicString",
                                     "text": " 116"
                                 }
                             ],
                             "abstract": [
                                 {
                                     "afs:t": "KwicString",
                                     "text": "viens de tomber a monté d\'un nouveau cran dans l\'étrangeté. Jamais dans l\'Histoire de l\'humanité il n\'a existé de civilisation sans enfants. Je tente d\'en imaginer les conséquences. George, qui m\'a deviné, énumère: - Comme nous ne nous reproduisons pas, la moitié féminine de l\'humanité"
                                 },
                                 { "afs:t": "KwicTruncate" }
                             ],
                             "relevance": {
                                 "rank": 3
                             },
                             "clientData": [
                                 {
                                     "contents": "' . $client_data . '",
                                     "id": "main",
                                     "mimeType": "text/xml"
                                 }
                             ]
                         },
                         {
                             "docId": 197,
                             "uri": "http://foo.bar.baz/81",
                             "title": [
                                 {
                                     "afs:t": "KwicString",
                                     "text": "The "
                                 },
                                 {
                                     "afs:t": "KwicMatch",
                                     "match": "title"
                                 },
                                 {
                                     "afs:t": "KwicString",
                                     "text": " 81"
                                 }
                             ],
                             "abstract": [
                                 {
                                     "afs:t": "KwicString",
                                     "text": "morose... il n\'y a pas de quoi en être fier. J\'émets des doutes, certes; mais au fond de moi, j\'ai confiance. Ne vous en étonnez-vous pas? Il y aurait pourtant bien de quoi! Voici que va surgir de nulle part une collectivité cachée comme aucune autre. Rien de pareil, jamais, n\'est arrivé dans"
                                 },
                                 {
                                     "afs:t": "KwicTruncate"
                                 }
                             ],
                             "relevance": {
                                 "rank": 4
                             },
                             "clientData": [
                                 {
                                     "contents": "' . $client_data . '",
                                     "id": "main",
                                     "mimeType": "text/xml"
                                 }
                             ]
                         }
                     ]
                 },
                 "pager": {
                     "previousPage": 1,
                     "nextPage": 3,
                     "currentPage": 2,
                     "page": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
                 }
             }
         ]
     }');
     $config = new AfsHelperConfiguration();
     $config->set_helper_format(AfsHelperFormat::HELPERS);
     $helper = new AfsPromoteReplysetHelper($input->replySet[0], $config);
     $meta = $helper->get_meta();
     $this->assertEquals('Promote', $meta->get_feed());
     $this->assertEquals('200', $meta->get_total_replies());
     $this->assertEquals('42', $meta->get_duration());
     $this->assertEquals('SEARCH', $meta->get_producer());
     $this->assertEquals(2, $helper->get_nb_replies());
     $replies = $helper->get_replies();
     $this->assertEquals('The title 116', $replies[0]->title);
     $this->assertEquals('The title 81', $replies[1]->title);
     $custom_data = $replies[0]->get_custom_data();
     $this->assertEquals(array("key1" => "v1"), $custom_data);
     // and so on...
 }
Beispiel #5
0
 public function testIntrospectionResponseShouldInitializeMetadata()
 {
     $input = json_decode('{
         "header": {
             "query": {
                 "userId": "afd070b6-4315-40cc-975d-747e28bf132a",
                 "sessionId": "5bf5642d-a262-4608-9901-45aa6e87325d"
             },
             "performance": {
                 "durationMs": 666
             }
         },
         "metadata": [
         {
           "uri": "Catalog",
           "meta": {
             "producer": [],
             "info": {
               "sizeKb": 409093,
               "date": 1447110000,
               "searchFeedInfo": {
                 "nbDocs": 33210,
                 "nbShards": 1,
                 "setInfos": [
                   {
                     "setId": "Antidot_Root_Field",
                     "childrenInfos": [],
                     "facetInfos": [
                       {
                         "afs:t": "FacetTree",
                         "layout": "TREE",
                         "type": "INTEGER",
                         "id": "product_id",
                         "sticky": false,
                         "filter": true
                       },
                       {
                         "afs:t": "FacetTree",
                         "layout": "TREE",
                         "type": "STRING",
                         "id": "name",
                         "sticky": false,
                         "filter": true
                       },
                       {
                         "afs:t": "FacetTree",
                         "layout": "TREE",
                         "type": "REAL",
                         "id": "price_from",
                         "sticky": false,
                         "filter": true
                       }
                     ]
                   }
                 ]
               }
             }
           }
         }
       ]
     }');
     $config = new AfsHelperConfiguration();
     $config->set_helper_format(AfsHelperFormat::HELPERS);
     $response_helper = new AfsResponseHelper($input, new AfsQuery(), $config);
     $this->assertNotEmpty($response_helper->get_all_metadata());
     $this->assertTrue($response_helper->has_metadata('Catalog'));
     $this->assertNotNull($response_helper->get_feed_metadata('Catalog'));
 }
Beispiel #6
0
$twig->addExtension(new Twig_Extension_Debug());
/** [Twig init] */
// Coder/Decoder and Query
/** [Coder/decoder and Query] */
$coder = new AfsQueryCoder('full_example.php');
$query = $coder->build_query($_GET);
/** [Coder/decoder and Query] */
// Connector
/** [Connector] */
$service = new AfsService(70000, AfsServiceStatus::STABLE);
$host = 'eval.partners.antidot.net';
$connector = new AfsSearchConnector($host, $service);
/** [Connector] */
// Configuration
/** [Helper configuration] */
$config = new AfsHelperConfiguration();
$config->set_query_coder($coder);
$config->set_helper_format(AfsHelperFormat::ARRAYS);
/** [Helper configuration] */
// Facets and Facet Manager
/** [Facets and Facet manager] */
$facet_mgr = $query->get_facet_manager();
$facet_mgr->add_facet(new AfsFacet('Organization', AfsFacetType::STRING_TYPE));
$facet_mgr->add_facet(new AfsFacet('date_parution', AfsFacetType::DATE_TYPE));
$facet_mgr->add_facet(new AfsFacet('geo', AfsFacetType::STRING_TYPE));
$facet_mgr->add_facet(new AfsFacet('media', AfsFacetType::STRING_TYPE));
$facet_mgr->add_facet(new AfsFacet('person', AfsFacetType::STRING_TYPE));
$facet_mgr->add_facet(new AfsFacet('period', AfsFacetType::DATE_TYPE, AfsFacetLayout::INTERVAL));
$facet_mgr->add_facet(new AfsFacet('source', AfsFacetType::STRING_TYPE));
$facet_mgr->add_facet(new AfsFacet('taxo_iptc', AfsFacetType::STRING_TYPE));
$facet_mgr->add_facet(new AfsFacet('theme', AfsFacetType::STRING_TYPE));
Beispiel #7
0
 public function testComputedLastPage3()
 {
     $input = json_decode('{
         "uri": "Catalog",
         "totalItems": 60,
         "totalItemsIsExact": true,
         "pageItems": 10,
         "firstPageItem": 1,
         "lastPageItem": 20,
         "durationMs": 6,
         "firstPaFId": 1,
         "lastPaFId": 1,
         "producer": "SEARCH"
     }');
     $meta = new AfsMetaHelper($input);
     $input = json_decode('{
         "pager": {
             "previousPage": 42,
             "nextPage": 666,
             "currentPage": 111,
             "page": [ 1 ]
         }
     }');
     $config = new AfsHelperConfiguration();
     $config->set_query_coder(new AfsQueryCoder('foo.php'));
     $helper = new AfsPagerHelper($input->pager, $meta, new AfsQuery(), $config);
     $this->assertEquals(6, $helper->get_last_page_no());
 }
Beispiel #8
0
 public function testFormattedReplyWithLinks()
 {
     $input = json_decode('{
         "header": {
             "query": {
                 "userId": "afd070b6-4315-40cc-975d-747e28bf132a",
                 "sessionId": "5bf5642d-a262-4608-9901-45aa6e87325d",
                 "date": "2013-10-02T15:48:41+0200",
                 "queryParam": [
                     {
                         "name": "afs:service",
                         "value": "42"
                     }
                 ],
                 "mainCtx": {
                     "textQuery": "title"
                 },
                 "textQuery": "title"
             },
             "user": {
                 "requestMethod": "GET",
                 "agent": "Mozilla/5.0 (X11; Linux x86_64; rv:23.0) Gecko/20100101 Firefox/23.0 Iceweasel/23.0",
                 "address": "127.0.0.1",
                 "output": {
                     "format": "JSON",
                     "encoding": "gzip",
                     "charset": "UTF-8"
                 }
             },
             "performance": {
                 "durationMs": 666
             },
             "info": { }
         },
         "replySet": [
             {
                 "meta": {
                     "uri": "Test",
                     "totalItems": 200,
                     "totalItemsIsExact": true,
                     "pageItems": 2,
                     "firstPageItem": 3,
                     "lastPageItem": 4,
                     "durationMs": 42,
                     "firstPaFId": 1,
                     "lastPaFId": 1,
                     "producer": "SEARCH"
                 },
                 "facets": {
                     "facet": [
                         {
                             "afs:t": "FacetTree",
                             "node": [
                                 {
                                     "key": "false",
                                     "labels": [
                                         {
                                             "label": "BAD"
                                         }
                                     ],
                                     "items": 67
                                 },
                                 {
                                     "key": "true",
                                     "labels": [
                                         {
                                             "label": "GOOD"
                                         }
                                     ],
                                     "items": 133
                                 }
                             ],
                             "layout": "TREE",
                             "type": "BOOL",
                             "id": "BOOL",
                             "labels": [
                                 {
                                     "label": "Boolean facet"
                                 }
                             ]
                         }
                     ]
                 },
                 "content": {
                     "reply": [
                         {
                             "docId": 198,
                             "uri": "http://foo.bar.baz/116",
                             "title": [
                                 {
                                     "afs:t": "KwicString",
                                         "text": "The "
                                 },
                                 {
                                     "afs:t": "KwicMatch",
                                         "match": "title"
                                 },
                                 {
                                     "afs:t": "KwicString",
                                         "text": " 116"
                                 }
                             ],
                             "abstract": [
                                 {
                                     "afs:t": "KwicString",
                                     "text": "viens de tomber a monté d\'un nouveau cran dans l\'étrangeté. Jamais dans l\'Histoire de l\'humanité il n\'a existé de civilisation sans enfants. Je tente d\'en imaginer les conséquences. George, qui m\'a deviné, énumère: - Comme nous ne nous reproduisons pas, la moitié féminine de l\'humanité"
                                 },
                                 {
                                     "afs:t": "KwicTruncate"
                                 }
                             ],
                             "relevance": {
                                 "rank": 3
                             },
                             "clientData": [
                                 {
                                     "contents": "<clientdata>{&quot;data&quot;: [{&quot;data1&quot;: &quot;data 0&quot;}, {&quot;data1&quot;: &quot;data 1&quot;}, {&quot;m1&quot;: &quot;m 1&quot;, &quot;m0&quot;: &quot;m 0&quot;, &quot;m3&quot;: &quot;m 3&quot;, &quot;m2&quot;: &quot;m 2&quot;}]}</clientdata>",
                                     "id": "main",
                                     "mimeType": "text/xml"
                                 }
                             ]
                         },
                         {
                             "docId": 197,
                             "uri": "http://foo.bar.baz/81",
                             "title": [
                                 {
                                     "afs:t": "KwicString",
                                     "text": "The "
                                 },
                                 {
                                     "afs:t": "KwicMatch",
                                     "match": "title"
                                 },
                                 {
                                     "afs:t": "KwicString",
                                     "text": " 81"
                                 }
                             ],
                             "abstract": [
                                 {
                                     "afs:t": "KwicString",
                                     "text": "morose... il n\'y a pas de quoi en être fier. J\'émets des doutes, certes; mais au fond de moi, j\'ai confiance. Ne vous en étonnez-vous pas? Il y aurait pourtant bien de quoi! Voici que va surgir de nulle part une collectivité cachée comme aucune autre. Rien de pareil, jamais, n\'est arrivé dans"
                                 },
                                 {
                                     "afs:t": "KwicTruncate"
                                 }
                             ],
                             "relevance": {
                                 "rank": 4
                             },
                             "clientData": [
                                 {
                                     "contents": "<clientdata>&lt;data&gt;&lt;data1&gt;data 0&lt;/data1&gt;&lt;data1&gt;data 1&lt;/data1&gt;&lt;multi&gt;&lt;m0&gt;m 0&lt;/m0&gt;&lt;m1&gt;m 1&lt;/m1&gt;&lt;m2&gt;m 2&lt;/m2&gt;&lt;m3&gt;m 3&lt;/m3&gt;&lt;/multi&gt;&lt;/data&gt;</clientdata>",
                                     "id": "main",
                                     "mimeType": "text/xml"
                                 }
                             ]
                         }
                     ]
                 },
                 "pager": {
                     "previousPage": 1,
                     "nextPage": 3,
                     "currentPage": 2,
                     "page": [
                         1,
                         2,
                         3,
                         4,
                         5,
                         6,
                         7,
                         8,
                         9,
                         10
                     ]
                 }
             }
         ]
     }');
     $query = new AfsQuery();
     $query = $query->set_query('title');
     $query = $query->set_replies(2);
     $query = $query->set_page(3);
     $config = new AfsHelperConfiguration();
     $coder = new AfsQueryCoder('foo.php');
     $config->set_query_coder($coder);
     $facet_mgr = $query->get_facet_manager();
     $facet_mgr->add_facet(new AfsFacet('BOOL', AfsFacetType::BOOL_TYPE));
     $helper = new AfsReplysetHelper($input->replySet[0], $query, $config);
     $meta = $helper->get_meta()->format();
     $this->assertEquals('Test', $meta['feed']);
     $this->assertEquals('200', $meta['total_replies']);
     $this->assertEquals('42', $meta['duration']);
     $this->assertEquals('SEARCH', $meta['producer']);
     $this->assertTrue($helper->has_facet());
     $facets = $helper->get_facets();
     $this->assertEquals(1, count($facets));
     $this->assertEquals('Boolean facet', $facets[0]->get_label());
     $elems = $facets[0]->get_elements();
     $this->assertEquals(2, count($elems));
     $this->assertEquals('BAD', $elems[0]->label);
     $this->assertTrue($elems[0]->link != null);
     $this->assertEquals($elems[0]->link, 'foo.php?replies=2&query=title&filter=BOOL_false');
     // You can continue here if you want but unit tests already exists for
     // facets.
     $this->assertEquals(2, $helper->get_nb_replies());
     $replies = $helper->get_replies();
     $this->assertEquals('The <b>title</b> 116', $replies[0]->get_title());
     $this->assertEquals('The <b>title</b> 81', $replies[1]->get_title());
     // and so on...
     $this->assertTrue($helper->has_pager());
     $pager = $helper->get_pager()->format();
     $this->assertEquals('foo.php?replies=2&query=title&page@Test=3', $pager['pages']['next']);
     $this->assertEquals('foo.php?replies=2&query=title', $pager['pages']['previous']);
     // and so on...
 }
 public function testSetAndRetrieveSpellcheckTextVisitor()
 {
     $config = new AfsHelperConfiguration();
     $visitor = new SpellcheckTextVisitorMock();
     $config->set_spellcheck_text_visitor($visitor);
     $visitor = $config->get_spellcheck_text_visitor();
     $this->assertNotNull($visitor);
     $text = new AfsSpellcheckText(json_decode('{"text": "bar"}'));
     $this->assertEquals('ARGbarARG', $visitor->visit_AfsSpellcheckText($text)->raw);
 }
Beispiel #10
0
 public function testFacetWithoutLabel()
 {
     $input = json_decode('{
         "afs:t": "FacetTree",
         "node": [
             {
                 "key": "false",
                 "labels": [
                     {
                         "label": "BAD"
                     }
                 ],
                 "items": 67
             },
             {
                 "key": "true",
                 "labels": [
                     {
                         "label": "GOOD"
                     }
                 ],
                 "items": 133
             }
         ],
         "layout": "TREE",
         "type": "BOOL",
         "id": "BOOOOL"
     }');
     $config = new AfsHelperConfiguration();
     $config->set_helper_format(AfsHelperFormat::HELPERS);
     $query = new AfsQuery();
     $facet = new AfsFacetHelper($input, $query, $config);
     $this->assertEquals('BOOOOL', $facet->get_label());
 }