Example #1
0
 /**
  * Extract facets from the Solr response
  * 
  * @param simplexml	$xml	solr response
  * @return Facets, null if none
  */
 protected function extractFacets($xml)
 {
     $facets = new Search\Facets();
     $groups = $xml->xpath("//lst[@name='facet_fields']/lst");
     if ($groups !== false && count($groups) > 0) {
         foreach ($groups as $facet_group) {
             // if only one entry, then all the results have this same facet,
             // so no sense even showing this as a limit
             $count = count($facet_group->int);
             if ($count <= 1) {
                 continue;
             }
             $group_internal_name = (string) $facet_group["name"];
             $group = new Search\FacetGroup();
             $group->name = $group_internal_name;
             $group->public = $this->config->getFacetPublicName($group_internal_name);
             // put facets into an array
             $facet_array = array();
             foreach ($facet_group->int as $int) {
                 $facet_array[(string) $int["name"]] = (int) $int;
             }
             // date
             $decade_display = array();
             $is_date = $this->config->isDateType($group_internal_name);
             if ($is_date == true) {
                 $date_arrays = $group->luceneDateToDecade($facet_array);
                 $decade_display = $date_arrays["display"];
                 $facet_array = $date_arrays["decades"];
             }
             foreach ($facet_array as $key => $value) {
                 $facet = new Search\Facet();
                 $facet->name = $key;
                 $facet->count = $value;
                 // dates are different
                 if ($is_date == true) {
                     $facet->name = $decade_display[$key];
                     $facet->is_date = true;
                     $facet->key = $key;
                 }
                 $group->addFacet($facet);
             }
             $facets->addGroup($group);
         }
     }
     return $facets;
 }
Example #2
0
 /**
  * Parse facets out of the response
  *
  * @param DOMDocument $dom 	Primo XML
  * @return Facets
  */
 protected function extractFacets(\DOMDocument $dom)
 {
     $facets = new Search\Facets();
     // echo $dom->saveXML();
     $groups = $dom->getElementsByTagName("FACET");
     if ($groups->length > 0) {
         // we'll pass the facets into an array so we can control both which
         // ones appear and in what order in the Xerxes config
         $facet_group_array = array();
         foreach ($groups as $facet_group) {
             $facet_values = $facet_group->getElementsByTagName("FACET_VALUES");
             // if only one entry, then all the results have this same facet,
             // so no sense even showing this as a limit
             if ($facet_values->length <= 1) {
                 continue;
             }
             $group_internal_name = $facet_group->getAttribute("NAME");
             $facet_group_array[$group_internal_name] = $facet_values;
         }
         // now take the order of the facets as defined in xerxes config
         foreach ($this->config->getFacets() as $group_internal_name => $facet_values) {
             // we defined it, but it's not in the primo response
             if (!array_key_exists($group_internal_name, $facet_group_array)) {
                 continue;
             }
             $group = new Search\FacetGroup();
             $group->name = $group_internal_name;
             $group->public = $this->config->getFacetPublicName($group_internal_name);
             // get the actual facets out of the array above
             $facet_values = $facet_group_array[$group_internal_name];
             // and put them in their own array so we can mess with them
             $facet_array = array();
             foreach ($facet_values as $facet_value) {
                 $key = $facet_value->getAttribute("KEY");
                 $value = $facet_value->getAttribute("VALUE");
                 $facet_array[$key] = $value;
             }
             // date
             $decade_display = array();
             $is_date = $this->config->isDateType($group_internal_name);
             if ($is_date == true) {
                 $date_arrays = $group->luceneDateToDecade($facet_array);
                 $decade_display = $date_arrays["display"];
                 $facet_array = $date_arrays["decades"];
             } else {
                 // not a date, sort by hit count
                 arsort($facet_array);
             }
             // now make them into group facet objects
             foreach ($facet_array as $key => $value) {
                 $public_value = $this->config->getValuePublicName($group_internal_name, $key);
                 $facet = new Search\Facet();
                 $facet->name = $public_value;
                 $facet->count = $value;
                 // dates are different
                 if ($is_date == true) {
                     $facet->name = $decade_display[$key];
                     $facet->is_date = true;
                     $facet->key = $key;
                 }
                 $group->addFacet($facet);
             }
             $facets->addGroup($group);
         }
     }
     return $facets;
 }
Example #3
0
 /**
  * Parse facets out of the response
  *
  * @param DOMDocument $dom 	Primo XML
  * @return Facets
  */
 protected function extractFacets(\DOMDocument $dom)
 {
     $facets = new Search\Facets();
     $id = $this->query->getHash();
     // header("Content-type: text/plain");	print_r($this->query->getLimits());
     // see if this is in the cache
     $xml = $this->cache->get($id);
     if ($xml == "") {
         $this->cache->set($id, $dom->saveXML());
     } else {
         $dom = new \DOMDocument();
         $dom->loadXML($xml);
     }
     $groups = $dom->getElementsByTagName("FACET");
     // otherwise, grab the response
     if ($groups->length > 0) {
         // we'll pass the facets into an array so we can control both which
         // ones appear and in what order in the Xerxes config
         $facet_group_array = array();
         foreach ($groups as $facet_group) {
             $facet_values = $facet_group->getElementsByTagName("FACET_VALUES");
             // if only one entry, then all the results have this same facet,
             // so no sense even showing this as a limit
             if ($facet_values->length <= 1) {
                 continue;
             }
             $group_internal_name = $facet_group->getAttribute("NAME");
             $facet_group_array[$group_internal_name] = $facet_values;
         }
         // now take the order of the facets as defined in xerxes config
         foreach ($this->config->getFacets() as $group_internal_name => $facet_values) {
             // we defined it, but it's not in the primo response
             if (!array_key_exists($group_internal_name, $facet_group_array)) {
                 continue;
             }
             $group = new Search\FacetGroup();
             $group->name = $group_internal_name;
             // get the actual facets out of the array above
             $facet_values = $facet_group_array[$group_internal_name];
             // and put them in their own array so we can mess with them
             $facet_array = array();
             foreach ($facet_values as $facet_value) {
                 $key = $facet_value->getAttribute("KEY");
                 $value = $facet_value->getAttribute("VALUE");
                 $facet_array[$key] = $value;
             }
             // date
             $decade_display = array();
             $is_date = $this->config->isDateType($group_internal_name);
             if ($is_date == true) {
                 $date_arrays = $group->luceneDateToDecade($facet_array);
                 $decade_display = $date_arrays["display"];
                 $facet_array = $date_arrays["decades"];
             } elseif ($group->name != "tlevel") {
                 // not a date, sort by hit count
                 arsort($facet_array);
             }
             // now make them into group facet objects
             foreach ($facet_array as $key => $value) {
                 $facet = new Search\Facet();
                 $facet->count = $value;
                 $facet->name = $key;
                 if ($group->name == "tlevel" || $group->name == "pfilter") {
                     $facet->name = str_replace('_', ' ', $facet->name);
                     $facet->name = ucwords($facet->name);
                 }
                 // is this an excluded facet?
                 foreach ($this->query->getLimits() as $limit) {
                     if ($limit->field == $group->name && $limit->value == $key && $limit->boolean == "NOT") {
                         $facet->is_excluded = 1;
                     }
                 }
                 // dates are different
                 if ($is_date == true) {
                     $facet->name = $decade_display[$key];
                     $facet->is_date = true;
                     $facet->key = $key;
                 }
                 $group->addFacet($facet);
             }
             $facets->addGroup($group);
         }
     }
     return $facets;
 }