/** * Create a new attachment document * * @param MidgardAttachment $attachment The Attachment to index. * @param MidgardObject $source The source objece to which the attachment is bound. */ public function __construct($attachment, $source) { //before doing anything else, verify that the attachment is readable, otherwise we might get stuck in endless loops later on $test = $attachment->open('r'); if (!$test) { debug_add('Attachment ' . $attachment->guid . ' cannot be read, aborting. Last midgard error: ' . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } else { fclose($test); } parent::__construct(); $this->_set_type('midcom_attachment'); $this->_attachment = $attachment; $this->_source = $source; debug_print_r("Processing this attachment:", $attachment); $this->source = $this->_source->guid; $this->RI = $this->_attachment->guid; $this->document_url = "{$GLOBALS['midcom_config']['midcom_site_url']}midcom-serveattachmentguid-{$this->RI}/{$this->_attachment->name}"; $this->_process_attachment(); $this->_process_topic(); }
/** * Query the index and, if set, restrict the query by a given filter. * * @param string $query The query, which must suite the backends query syntax. * @param midcom_services_indexer_filter $filter An optional filter used to restrict the query. This may be null indicating no filter. * @return Array An array of documents matching the query, or false on a failure. */ public function query($query, midcom_services_indexer_filter $filter = null) { if ($filter !== null) { $query .= ' AND ' . $filter->get_query_string(); } $url = "http://{$GLOBALS['midcom_config']['indexer_xmltcp_host']}:{$GLOBALS['midcom_config']['indexer_xmltcp_port']}/solr/select"; $request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET); $url = $request->getUrl(); // FIXME: Make this configurable, even better: adapt the whole indexer system to fetching enable querying for counts and slices $maxrows = 1000; $url->setQueryVariables(array('q' => $query, 'fl' => '*,score', 'rows' => $maxrows)); if (!empty($this->_index_name)) { $url->setQueryVariable('fq', '__INDEX_NAME:"' . rawurlencode($this->_index_name) . '"'); } $request->setHeader('Accept-Charset', 'UTF-8'); $request->setHeader('Content-type', 'text/xml; charset=utf-8'); try { $response = $request->send(); } catch (Exception $e) { debug_add("Failed to execute request " . $url . ": " . $e->getMessage(), MIDCOM_LOG_WARN); return false; } $this->code = $response->getStatus(); if ($this->code != 200) { debug_print_r($url . " returned response code {$this->code}, body:", $response->getBody()); return false; } $body = $response->getBody(); $response = DomDocument::loadXML($body); $xquery = new DomXPath($response); $result = array(); $num = $xquery->query('/response/result')->item(0); if ($num->getAttribute('numFound') == 0) { return array(); } foreach ($xquery->query('/response/result/doc') as $res) { $doc = new midcom_services_indexer_document(); foreach ($res->childNodes as $str) { $name = $str->getAttribute('name'); $doc->add_result($name, $str->tagName == 'float' ? (double) $str->nodeValue : (string) $str->nodeValue); if ($name == 'RI') { $doc->add_result('__RI', $str->nodeValue); } if ($name == 'score' && $filter == null) { $doc->score = (double) $str->nodeValue; } } /* FIXME: before result slicing is properly supported this can be too heavy if ( isset($doc->source) && mgd_is_guid($doc->source)) { midcom::get('cache')->content->register($doc->source); } */ $result[] = $doc; } debug_add(sprintf('Returning %d results', count($result)), MIDCOM_LOG_INFO); return $result; }
/** * This will translate all member variables into appropriate * field records, missing topic data is auto-detected */ public function members_to_fields() { if (empty($this->topic_guid) || empty($this->topic_url) || empty($this->component)) { //if one of those is missing, we override all three to ensure consistency $this->_process_topic(); } parent::members_to_fields(); }
/** * @dataProvider provider_html2text */ public function test_html2text($in, $out) { $document = new midcom_services_indexer_document(); $this->assertEquals($out, $document->html2text($in)); }