public function createEntryDocument(entry $entry) { $document = new Apache_Solr_Document(); $document->plugins_data = ''; foreach (self::$solrFields as $solrField) { $fieldType = $solrField['type']; $func_name = "get" . $solrField['phpName']; if ($fieldType == "date") { $value = call_user_func(array($entry, $func_name), "%Y-%m-%dT%H:%M:%SZ"); } else { $value = call_user_func(array($entry, $func_name)); } //$value = $entry->getByName($solrField['phpName']); $solrName = $solrField['solrName']; switch ($solrField['type']) { case "array": if ($value != '') { $values = explode(",", $value); foreach ($vals as $value) { $document->addField($solrName, $value); } } break; default: $document->addField($solrName, $value); } } return $document; }
/** * add a document * @param array */ public function addDocument($doc) { $document = new Apache_Solr_Document(); foreach ($doc as $key => $val) { if (is_array($val)) { foreach ($val as $_val) { $document->addField($key, $_val); } } else { $document->addField($key, $val); } } $this->service->addDocument($document); }
/** * Adds fields to the document as defined in $indexingConfiguration * * @param \Apache_Solr_Document $document base document to add fields to * @param array $indexingConfiguration Indexing configuration / mapping * @param array $data Record data * @return \Apache_Solr_Document Modified document with added fields */ protected function addDocumentFieldsFromTyposcript(\Apache_Solr_Document $document, array $indexingConfiguration, array $data) { // mapping of record fields => solr document fields, resolving cObj foreach ($indexingConfiguration as $solrFieldName => $recordFieldName) { if (is_array($recordFieldName)) { // configuration for a content object, skipping continue; } if (!self::isAllowedToOverrideField($solrFieldName)) { throw new InvalidFieldNameException('Must not overwrite field .' . $solrFieldName, 1435441863); } $fieldValue = $this->resolveFieldValue($indexingConfiguration, $solrFieldName, $data); if (is_array($fieldValue)) { // multi value foreach ($fieldValue as $multiValue) { $document->addField($solrFieldName, $multiValue); } } else { if ($fieldValue !== '' && $fieldValue !== null) { $document->setField($solrFieldName, $fieldValue); } } } return $document; }
/** * Method for adding an object from the database into the index. * * @param DataObject * @param string * @param array */ protected function _addAs($object, $base, $options) { $includeSubs = $options['include_children']; $doc = new Apache_Solr_Document(); // Always present fields $doc->setField('_documentid', $this->getDocumentID($object, $base, $includeSubs)); $doc->setField('ID', $object->ID); $doc->setField('ClassName', $object->ClassName); foreach (SearchIntrospection::hierarchy(get_class($object), false) as $class) { $doc->addField('ClassHierarchy', $class); } // Add the user-specified fields foreach ($this->getFieldsIterator() as $name => $field) { if ($field['base'] == $base) { $this->_addField($doc, $object, $field); } } // CUSTOM Duplicate index combined fields ("Title" rather than // "SiteTree_Title"). // // This allows us to sort on these fields without deeper architectural // changes to the fulltextsearch module. Note: We can't use <copyField> // for this purpose because it only writes into multiValue=true // fields, and those can't be (reliably) sorted on. $this->_addField($doc, $object, $this->getCustomPropertyFieldData('Title', $object)); $this->_addField($doc, $object, $this->getCustomPropertyFieldData('LastEdited', $object, 'SSDatetime')); $this->getService()->addDocument($doc); return $doc; }
/** * @test */ public function transformsUnixTimestampToIsoDateOnMultiValuedField() { $this->documentMock->addField('dateField', '1262343600'); // 2010-01-01 12:00 $this->documentMock->addField('dateField', '1262343601'); // 2010-01-01 12:01 $configuration = array('dateField' => 'timestampToIsoDate'); $this->service->processDocument($this->documentMock, $configuration); $value = $this->documentMock->getField('dateField'); $this->assertEquals($value['value'], array('2010-01-01T12:00:00Z', '2010-01-01T12:00:01Z'), 'field was not processed with timestampToIsoDate'); }
public function testAddFieldWithBoostMultipliesWithAPreexistingBoost() { $field = 'field'; $boost = 0.5; // set a field with a boost $this->_fixture->setField($field, 'value1', $boost); // now add another value with the same boost $this->_fixture->addField($field, 'value2', $boost); // new boost should be $boost * $boost $this->assertEquals($boost * $boost, $this->_fixture->getFieldBoost($field)); }
/** * Adds fields to the document as defined in $indexingConfiguration * * @param Apache_Solr_Document $document base document to add fields to * @param array $indexingConfiguration Indexing configuration / mapping * @param array $data Record data * @return Apache_Solr_Document Modified document with added fields */ protected function addDocumentFieldsFromTyposcript(Apache_Solr_Document $document, array $indexingConfiguration, array $data) { // mapping of record fields => solr document fields, resolving cObj foreach ($indexingConfiguration as $solrFieldName => $recordFieldName) { if (is_array($recordFieldName)) { // configuration for a content object, skipping continue; } $fieldValue = $this->resolveFieldValue($indexingConfiguration, $solrFieldName, $data); if (is_array($fieldValue)) { // multi value foreach ($fieldValue as $multiValue) { $document->addField($solrFieldName, $multiValue); } } else { $document->setField($solrFieldName, $fieldValue); } } return $document; }
<?php require dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new limeade_test(2, limeade_output::get()); $t->diag('document format a document'); $document = new Apache_Solr_Document(); $document->setBoost(10); $document->setField('sfl_guid', 'GUID_1234'); $document->setField('name', 'Thomas Rabaix', 1); $document->setMultiValue('skills', 'php'); $document->setMultiValue('skills', 'symfony'); $document->addField('skills', 'objective-c'); $expected = array('name' => 'skills', 'value' => array(0 => 'php', 1 => 'symfony', 2 => 'objective-c'), 'boost' => false); $t->cmp_ok($document->getField('skills'), '==', $expected, '::getField test multivalue setter'); $expected = array('name' => 'name', 'value' => 'Thomas Rabaix', 'boost' => 1); $t->cmp_ok($document->getField('name'), '==', $expected, '::getField test setter');
public function addResource($resource) { if (!is_array($resource)) { return false; } $fields = array('id' => $resource['Resource']['id'], 'sha' => $resource['Resource']['sha'], 'user' => $resource['User']['name'], 'filetype' => $resource['Resource']['mime_type'], 'filename' => $resource['Resource']['file_name'], 'type' => $resource['Resource']['type'], 'title' => $resource['Resource']['title'], 'public' => $resource['Resource']['public'], 'modified' => $this->_formatDate($resource['Resource']['modified']), 'created' => $this->_formatDate($resource['Resource']['created']), 'comment' => \_\pluck($resource['Comment'], 'content'), 'annotation' => \_\pluck($resource['Annotation'], 'caption'), 'keyword' => \_\pluck($resource['Keyword'], 'keyword'), 'collection' => $resource['Collection'] ?: array()); $document = new \Apache_Solr_Document(); foreach ($fields as $key => $val) { if (is_array($val)) { foreach ($val as $subval) { $document->addField($key, $subval); } } else { $document->{$key} = $val; } } foreach ($resource['Metadatum'] as $m) { $document->addField($m['attribute'] . '_t', $m['value']); } $this->solr->addDocument($document); $this->solr->commit(); $this->solr->optimize(); }
public function indexPage(Kwf_Component_Data $page, $debugOutput = false) { if (Kwc_Abstract::getFlag($page->componentClass, 'skipFulltext')) { return; } //performance //echo "checking for childComponents\n"; $fulltextComponents = $this->getFulltextComponents($page); if ($fulltextComponents) { if ($debugOutput) { echo " *** indexing {$page->componentId} {$page->url}..."; } $contents = $this->getFulltextContentForPage($page, $fulltextComponents); unset($fulltextComponents); if (!$contents) { if ($debugOutput) { echo " [no content]\n"; } return false; } if ($debugOutput) { echo " [" . implode(' ', array_keys($contents)) . "]\n"; } $doc = new Apache_Solr_Document(); foreach ($contents as $field => $text) { if ($text instanceof Kwf_DateTime) { $text = gmdate('Y-m-d\\TH:i:s\\Z', $text->getTimestamp()); } $doc->addField($field, $text); } $doc->addField('componentId', $page->componentId); $response = $this->_getSolrService($page)->addDocument($doc); if ($response->getHttpStatus() != 200) { throw new Kwf_Exception("addDocument failed"); } $this->_getSolrService($page)->commit(); $this->_afterIndex($page); return true; } return false; }
/** Build the solr lucene index for folders */ public function indexFolder($args) { $folder = $args['folder']; try { $index = $this->ModuleComponent->Solr->getSolrIndex(); } catch (Exception $e) { $this->getLogger()->warn($e->getMessage() . ' - Could not index folder (' . $folder->getKey() . ')'); return; } $progress = array_key_exists('progress', $args) ? $args['progress'] : null; if ($progress) { $message = 'Indexing folder ' . ($progress->getCurrent() + 1) . ' / ' . $progress->getMaximum(); $this->Progress->updateProgress($progress, $progress->getCurrent() + 1, $message); } try { $response = $index->search('id: folder_' . $folder->getKey(), 0, 99999); foreach ($response->response->docs as $doc) { $index->deleteById($doc->id); } if ($response->response->numFound > 0) { $index->commit(); } $doc = new Apache_Solr_Document(); $doc->addField('id', 'folder_' . $folder->getKey()); $doc->addField('key', $folder->getKey()); $doc->addField('name', $folder->getName(), 3.0); // boost factor of 3 for name $doc->addField('description', $folder->getDescription(), 2.0); // boost factor of 2 for description $index->addDocument($doc); $index->commit(); } catch (Exception $e) { $this->getLogger()->warn('Error saving folder (' . $folder->getKey() . ') to Solr index: ' . $e->getMessage()); } }
protected function _addAs($object, $base, $options) { $includeSubs = $options['include_children']; $doc = new Apache_Solr_Document(); // Always present fields $doc->setField('_documentid', $this->getDocumentID($object, $base, $includeSubs)); $doc->setField('ID', $object->ID); $doc->setField('ClassName', $object->ClassName); foreach (SearchIntrospection::hierarchy(get_class($object), false) as $class) { $doc->addField('ClassHierarchy', $class); } // Add the user-specified fields foreach ($this->getFieldsIterator() as $name => $field) { if ($field['base'] == $base) { $this->_addField($doc, $object, $field); } } try { $this->getService()->addDocument($doc); } catch (Exception $e) { SS_Log::log($e, SS_Log::WARN); return false; } return $doc; }
protected function buildProductDocument($storeId, $productId, $indexableAttributes) { $helper = Mage::helper('solr'); $indexableAttributes = Mage::helper('solr/attribute')->getNamedProductAttributes($indexableAttributes); $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId); /** @var Mage_Catalog_Model_Product $product */ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); $host = parse_url($baseUrl, PHP_URL_HOST); $document = new Apache_Solr_Document(); $document->setField('appKey', 'Asm_Solr'); $document->setField('type', 'catalog/product'); $document->setField('id', $helper->getProductDocumentId($product->getEntityId())); $document->setField('site', $host); $document->setField('siteHash', $helper->getSiteHashForDomain($host)); $document->setField('storeId', $storeId); $document->setField('created', $helper->dateToIso($product->getCreatedAt())); $document->setField('changed', $helper->dateToIso($product->getUpdatedAt())); $document->setField('sku', $product->getSku()); $document->setField('productId', $product->getEntityId()); $categoryIds = $product->getCategoryIds(); foreach ($categoryIds as $categoryId) { $document->addField('categoryId', $categoryId); } $document->setField('isSalable', $product->isSalable()); $document->setField('inStock', $product->isInStock()); $document->setField('isVisible', $product->getStatus()); $document->setField('isVisibleInCatalog', $product->isVisibleInCatalog()); $document->setField('title', $product->getName()); $document->setField('content', $product->getDescription()); $document->setField('keywords', $helper->trimExplode(',', $product->getMetaKeyword(), true)); $document->setField('url', $product->getProductUrl()); $document->setField('price', $product->getPrice()); if ($product->getManufacturer()) { $document->setField('manufacturer', $product->getAttributeText('manufacturer')); } $document->setField('image_stringS', $product->getImage()); $document->setField('small_image_stringS', $product->getSmallImage()); $document->setField('thumbnail_stringS', $product->getThumbnail()); $productType = $product->getTypeId(); $document->setField('type_id_stringS', $productType); if ($productType == 'configurable') { $childProductAttributes = $this->getConfigurableProductChildProductAttributes($storeId, $product); $indexableAttributes = array_merge($indexableAttributes, $childProductAttributes); } $fieldProcessorFactory = Mage::getResourceModel('solr/indexer_fieldprocessor_factory'); // add other searchable attributes as dynamic fields foreach ($indexableAttributes as $attributeCode => $attributeValue) { if (empty($attributeValue) || in_array($attributeCode, $this->fixedSchemaFieldAttributes)) { // don't add fixed schema fields twice continue; } $fieldProcessor = $fieldProcessorFactory->getFieldProcessor($attributeCode, $attributeValue); $document->setField($fieldProcessor->getFieldName(), $fieldProcessor->getFieldValue()); } return $document; }
public function convertObjectToDocument($dataObject, $stage = null, $fieldBoost = array()) { $document = new Apache_Solr_Document(); $fieldsToIndex = array(); $object = null; // whether the original item is an object or array. // determines how we treat the object later when checking all the fields $sourceObject = true; $id = 0; if (is_object($dataObject)) { if ($dataObject->hasMethod('hasField') && $dataObject->hasField('ShowInSearch') && !$dataObject->ShowInSearch) { return; } $fieldsToIndex = $this->getSearchableFieldsFor($dataObject); // $dataObject->searchableFields(); $object = $this->objectToFields($dataObject); $id = $dataObject->ID; } else { $object = $dataObject; $id = isset($dataObject['ID']) ? $dataObject['ID'] : 0; $fieldsToIndex = isset($object['index_fields']) ? $object['index_fields'] : array_flip(array_keys($object)); $sourceObject = false; } $fieldsToIndex['SS_URL'] = true; $fieldsToIndex['SS_ID'] = true; $fieldsToIndex['LastEdited'] = true; $fieldsToIndex['Created'] = true; $fieldsToIndex['ClassName'] = true; $fieldsToIndex['ClassNameHierarchy'] = true; $fieldsToIndex['ParentsHierarchy'] = true; // the stage we're on when we write this doc to the index. // this is used for versioned AND non-versioned objects; we just cheat and // set it BOTH stages if it's non-versioned object $fieldsToIndex['SS_Stage'] = true; // if it's a versioned object, just save ONE stage value. if ($stage) { $object['SS_Stage'] = array('Type' => 'Enum', 'Value' => $stage); $id = $id . '_' . $stage; } else { $object['SS_Stage'] = array('Type' => 'Enum', 'Value' => array('Stage', 'Live')); } if (!$id) { return false; } // specially handle the subsite module - this has serious implications for our search // @TODO we want to genercise this later for other modules to hook into it! if (ClassInfo::exists('Subsite')) { $fieldsToIndex['SubsiteID'] = true; if (is_object($dataObject)) { $object['SubsiteID'] = array('Type' => 'Int', 'Value' => $dataObject->SubsiteID); } } $classType = isset($object['ClassName']) ? $object['ClassName']['Value'] : null; // we're not indexing the ID field because it conflicts with Solr's internal ID unset($object['ID']); // a special type hierarchy if ($classType) { $classes = array_values(ClassInfo::ancestry($classType)); $object['ClassNameHierarchy'] = array('Type' => 'MultiValueField', 'Value' => $classes); $object['ParentsHierarchy'] = $this->getParentsHierarchyField($dataObject); } foreach ($object as $field => $valueDesc) { if (!$valueDesc) { continue; } if (!is_array($valueDesc) || !isset($valueDesc['Type'])) { // if we're indexing an object and there's no valueDesc, just skip this field if ($sourceObject) { continue; } $valueDesc = array('Value' => $valueDesc, 'Type' => $this->mapper->mapValueToType($field, $valueDesc)); } $type = $valueDesc['Type']; $value = $valueDesc['Value']; // this should have already been taken care of, but just in case... if ($type == 'MultiValueField' && $value instanceof MultiValueField) { $value = $value->getValues(); } if (!isset($fieldsToIndex[$field])) { continue; } $fieldName = $this->mapper->mapFieldNameFromType($field, $type, $fieldsToIndex[$field]); if (!$fieldName) { continue; } $value = $this->mapper->convertValue($value, $type); if (is_array($value)) { foreach ($value as $v) { $document->addField($fieldName, $v); } } else { $boost = false; if (isset($fieldBoost["{$fieldName}:{$value}"])) { $boost = $fieldBoost["{$fieldName}:{$value}"]; } $document->setField($fieldName, $value, $boost); $document->{$fieldName} = $value; } } $document->id = $classType ? $classType . '_' . $id : SolrSearchService::RAW_DATA_KEY . $id; return $document; }
function s4w_build_document($post_info, $domain = NULL, $path = NULL) { global $blog_id; global $current_blog; $doc = NULL; $plugin_s4w_settings = s4w_get_option(); $exclude_ids = $plugin_s4w_settings['s4w_exclude_pages']; $categoy_as_taxonomy = $plugin_s4w_settings['s4w_cat_as_taxo']; $index_comments = $plugin_s4w_settings['s4w_index_comments']; $index_custom_fields = $plugin_s4w_settings['s4w_index_custom_fields']; if ($post_info) { # check if we need to exclude this document if (is_multisite() && in_array($current_blog->domain . $post_info->ID, (array) $exclude_ids)) { return NULL; } else { if (!is_multisite() && in_array($post_info->ID, (array) $exclude_ids)) { return NULL; } } $doc = new Apache_Solr_Document(); $auth_info = get_userdata($post_info->post_author); # wpmu specific info if (is_multisite()) { // if we get here we expect that we've "switched" what blog we're running // as if ($domain == NULL) { $domain = $current_blog->domain; } if ($path == NULL) { $path = $current_blog->path; } $blogid = get_blog_id_from_url($domain, $path); $doc->setField('id', $domain . $path . $post_info->ID); $doc->setField('permalink', get_blog_permalink($blogid, $post_info->ID)); $doc->setField('blogid', $blogid); $doc->setField('blogdomain', $domain); $doc->setField('blogpath', $path); $doc->setField('wp', 'multisite'); } else { $doc->setField('id', $post_info->ID); $doc->setField('permalink', get_permalink($post_info->ID)); $doc->setField('wp', 'wp'); } $numcomments = 0; if ($index_comments) { $comments = get_comments("status=approve&post_id={$post_info->ID}"); foreach ($comments as $comment) { $doc->addField('comments', $comment->comment_content); $numcomments += 1; } } $doc->setField('title', $post_info->post_title); $doc->setField('content', strip_tags($post_info->post_content)); // rawcontent strips out characters lower than 0x20 $doc->setField('rawcontent', strip_tags(preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $post_info->post_content))); // contentnoshortcodes also strips characters below 0x20 but also strips shortcodes // used in WP to add images or other content, useful if you're pulling this data // into another system // // For example // [caption id="attachment_92495" align="alignright" width="160" caption="Duane Sand"][/caption] FARGO - Republican U.S. Senate... // // Will become // FARGO - Republican U.S. Senate... $doc->setField('contentnoshortcodes', strip_tags(preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', strip_tags(strip_shortcodes($post_info->post_content))))); $doc->setField('numcomments', $numcomments); $doc->setField('author', $auth_info->display_name); $doc->setField('author_s', get_author_posts_url($auth_info->ID, $auth_info->user_nicename)); $doc->setField('type', $post_info->post_type); $doc->setField('date', s4w_format_date($post_info->post_date_gmt)); $doc->setField('tdate', s4w_format_date($post_info->post_date_gmt)); $doc->setField('modified', s4w_format_date($post_info->post_modified_gmt)); $doc->setField('displaydate', $post_info->post_date); $doc->setField('displaymodified', $post_info->post_modified); $categories = get_the_category($post_info->ID); if (!$categories == NULL) { foreach ($categories as $category) { if ($categoy_as_taxonomy) { $doc->addField('categories', get_category_parents($category->cat_ID, FALSE, '^^')); } else { $doc->addField('categories', $category->cat_name); } } } //get all the taxonomy names used by wp $taxonomies = (array) get_taxonomies(array('_builtin' => FALSE), 'names'); foreach ($taxonomies as $parent) { $terms = get_the_terms($post_info->ID, $parent); if ((array) $terms === $terms) { //we are creating *_taxonomy as dynamic fields using our schema //so lets set up all our taxonomies in that format $parent = $parent . "_taxonomy"; foreach ($terms as $term) { $doc->addField($parent, $term->name); } } } $tags = get_the_tags($post_info->ID); if (!$tags == NULL) { foreach ($tags as $tag) { $doc->addField('tags', $tag->name); } } if (count($index_custom_fields) > 0 && count($custom_fields = get_post_custom($post_info->ID))) { foreach ((array) $index_custom_fields as $field_name) { $field = (array) $custom_fields[$field_name]; foreach ($field as $key => $value) { $doc->addField($field_name . '_str', $value); $doc->addField($field_name . '_srch', $value); } } } // add full json respone $json_response = new JSON_API_Response(); $json_post = new JSON_API_Post_full(get_post($post_info->ID)); $response = (object) array('post' => $json_post); $doc->setField('json', $json_response->get_json($response)); // add tone: /nieuws/beste van het web/weblog/column/ $tone = 'Nieuws'; if ($blog_id > 1) { $nmt_blog_type = stripslashes(get_blog_option($blog_id, 'nmt_blog_type')); $nmt_blog_types = array(1 => 'Weblog', 2 => 'Column', 3 => 'Nieuws', 4 => 'Fotoserie'); $tone = $nmt_blog_types[$nmt_blog_type]; } else { $category_slugs = array(); if (!$categories == NULL) { foreach ($categories as $category) { $category_slugs[] = $category->slug; } } if (in_array('beste-van-het-web', $category_slugs)) { $tone = 'Beste van het web'; } } $doc->setField('tone', $tone); } else { // this will fire during blog sign up on multisite, not sure why _e('Post Information is NULL', 'solr4wp'); } syslog(LOG_ERR, "built document for {$blog_id} - {$domain}{$path} with title " . $post_info->post_title . " and status of " . $post_info->post_status); return $doc; }
/** * This returns an Apache_Solr_Document to index, if the addons say it * should be. * * @param Omeka_Record $record The record to index. * @param associative array of SolrSearch_Addon_Addon $addons The * configuration controlling how records are indexed. * * @return Apache_Solr_Document|null * @author Eric Rochester <*****@*****.**> **/ public function indexRecord($record, $addon) { $doc = new Apache_Solr_Document(); $doc->id = "{$addon->table}_{$record->id}"; $doc->addField('model', $addon->table); $doc->addField('modelid', $record->id); $titleField = $addon->getTitleField(); foreach ($addon->fields as $field) { $solrName = $this->makeSolrName($addon, $field->name); if (is_null($field->remote)) { $value = $this->getLocalValue($record, $field); } else { $value = $this->getRemoteValue($record, $field); } foreach ($value as $v) { $doc->addField($solrName, $v); if (!is_null($titleField) && $titleField->name === $field->name) { $doc->addField('title', $v); } } } if ($addon->tagged) { foreach ($record->getTags() as $tag) { $doc->addField('tag', $tag->name); } } if ($addon->resultType) { $doc->addField('resulttype', $addon->resultType); } return $doc; }
/** * Prepares a Solr Document with the correct fields for the record type * * @param mixed $record * @return Apache_Solr_Document */ private function createDocument($record) { // These are the fields from the tickets table that we're indexing // // Note: enteredDate, latitude, longitude are indexed as well, even // though they are not in this list. // They are just handled slightly differently from the generic fields listed $ticketFields = array('id', 'category_id', 'client_id', 'enteredByPerson_id', 'assignedPerson_id', 'referredPerson_id', 'addressId', 'location', 'city', 'state', 'zip', 'status', 'substatus_id'); // These are the fields from the issues table that we're indexing $issueFields = array('contactMethod_id', 'issueType_id', 'reportedByPerson_id'); if ($record instanceof Ticket) { $document = new \Apache_Solr_Document(); $document->addField('recordKey', "t_{$record->getId()}"); $document->addField('recordType', 'ticket'); $document->addField('enteredDate', $record->getEnteredDate(Search::DATE_FORMAT), \DateTimeZone::UTC); if ($record->getClosedDate()) { $document->addField('closedDate', $record->getClosedDate(Search::DATE_FORMAT), \DateTimeZone::UTC); } if ($record->getLatLong()) { $document->addField('coordinates', $record->getLatLong()); } if ($record->getCategory()) { $c = $record->getCategory(); $document->addField('displayPermissionLevel', $c->getDisplayPermissionLevel()); if ($c->getSlaDays()) { $document->addField('slaDays', $c->getSlaDays()); } } // Ticket information indexing foreach ($ticketFields as $f) { $get = 'get' . ucfirst($f); if ($record->{$get}()) { $document->addField($f, $record->{$get}()); if (substr($f, -3) == '_id') { $document->addField(substr($f, 0, -3), $this->sortableString($record, $f)); } } } $person = $record->getAssignedPerson(); if ($person && $person->getDepartment_id()) { $document->addField('department_id', $person->getDepartment_id()); $document->addField('department', $this->sortableString($person, 'department_id')); } // Issue information indexing $description = ''; foreach ($record->getIssues() as $issue) { $description .= $issue->getDescription(); foreach ($issueFields as $f) { $get = 'get' . ucfirst($f); if ($issue->{$get}()) { $document->addField($f, $issue->{$get}()); $document->addField(substr($f, 0, -3), $this->sortableString($issue, $f)); } } foreach ($issue->getLabels() as $id => $label) { $document->addField('label_id', $id); $document->addField('label', $label->getName()); } } if ($description) { $document->addField('description', $description); } // Index extra fields provided by the AddressService $additionalFields = $record->getAdditionalFields(); if ($additionalFields) { foreach ($additionalFields as $key => $value) { if ($value) { $document->addField($key, $value); } } } if ($record->getLatitude() && $record->getLongitude()) { $latitude = $record->getLatitude(); $longitude = $record->getLongitude(); $document->addField('latitude', $latitude); $document->addField('longitude', $longitude); foreach ($record->getClusterIds() as $key => $value) { $document->addField($key, $value); } } return $document; } }