/** * Process a single group. * * Without queuedjobs, it's necessary to shell this out to a background task as this is * very memory intensive. * * The sub-process will then invoke $processor->runGroup() in {@see Solr_Reindex::doReindex} * * @param LoggerInterface $logger * @param SolrIndex $indexInstance Index instance * @param array $state Variant state * @param string $class Class to index * @param int $groups Total groups * @param int $group Index of group to process * @param string $taskName Name of task script to run */ protected function processGroup(LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group, $taskName) { // Build state $statevar = json_encode($state); if (strpos(PHP_OS, "WIN") !== false) { $statevar = '"' . str_replace('"', '\\"', $statevar) . '"'; } else { $statevar = "'" . $statevar . "'"; } // Build script $indexName = $indexInstance->getIndexName(); $scriptPath = sprintf("%s%sframework%scli-script.php", BASE_PATH, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); $scriptTask = "php {$scriptPath} dev/tasks/{$taskName}"; $cmd = "{$scriptTask} index={$indexName} class={$class} group={$group} groups={$groups} variantstate={$statevar}"; $cmd .= " verbose=1 2>&1"; $logger->info("Running '{$cmd}'"); // Execute script via shell $res = $logger ? passthru($cmd) : `{$cmd}`; if ($logger) { $logger->info(preg_replace('/\\r\\n|\\n/', '$0 ', $res)); } // If we're in dev mode, commit more often for fun and profit if (Director::isDev()) { Solr::service($indexName)->commit(); } // This will slow down things a tiny bit, but it is done so that we don't timeout to the database during a reindex DB::query('SELECT 1'); }
protected function processGroup(LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group, $taskName) { // Trigger another job for this group $job = Injector::inst()->create('SolrReindexGroupQueuedJob', $indexInstance->getIndexName(), $state, $class, $groups, $group); $this->getQueuedJobService()->queueJob($job); $title = $job->getTitle(); $logger->info("Queued {$title}"); }
/** * Overload */ public function search(SearchQuery $query, $offset = -1, $limit = -1, $params = array()) { // escape query $queryInternals = array_pop($query->search); $queryInternals['text'] = self::escapeQuery($queryInternals['text']); $query->search[] = $queryInternals; $result = parent::search($query, $offset, $limit, $params); // unescape suggestions $unescapedSuggestions = self::unescapeQuery(array($result->Suggestion, $result->SuggestionNice, $result->SuggestionQueryString)); $result->Suggestion = $unescapedSuggestions[0]; $result->SuggestionNice = $unescapedSuggestions[1]; $result->SuggestionQueryString = $unescapedSuggestions[2]; return $result; }
/** * Overridden field definitions to define additional custom fields like sort * fields and additional functionality. * * @return string */ public function getFieldDefinitions() { $xml = parent::getFieldDefinitions(); $stored = Director::isDev() ? "stored='true'" : "stored='false'"; $xml .= "\n\n\t\t<!-- Additional custom fields for sorting, see PageSolrIndex.php -->"; $xml .= "\n\t\t<field name='Title' type='alphaOnlySort' indexed='true' stored='true' />"; $xml .= "\n\t\t<field name='LastEdited' type='tdate' indexed='true' stored='true' />"; $xml .= "\n\n\t\t<!-- Additional custom fields for spell checking, see PageSolrIndex.php -->"; $xml .= "\n\t\t<field name='spellcheckData' type='textSpell' {$stored} indexed='true' multiValued='true' />"; $xml .= "\n\t\t<field name='highlightData' type='htmltext' stored='true' indexed='true' multiValued='true' />"; return $xml; }
/** * Overrides the parent to add a field for autocomplete * @return HTMLText */ public function getTypes() { $val = parent::getTypes(); if (!$val || !is_object($val)) { return $val; } $xml = $val->getValue(); $xml .= <<<XML \t <fieldType name="autosuggest_text" class="solr.TextField" \t positionIncrementGap="100"> \t <analyzer type="index"> \t <tokenizer class="solr.StandardTokenizerFactory"/> \t <filter class="solr.LowerCaseFilterFactory"/> \t <filter class="solr.ShingleFilterFactory" minShingleSize="2" maxShingleSize="4" outputUnigrams="true" outputUnigramsIfNoShingles="true" /> \t <filter class="solr.PatternReplaceFilterFactory" pattern="^([0-9. ])*\$" replacement="" \t replace="all"/> \t <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> \t </analyzer> \t <analyzer type="query"> \t <tokenizer class="solr.StandardTokenizerFactory"/> \t <filter class="solr.LowerCaseFilterFactory"/> \t </analyzer> \t </fieldType> XML; $val->setValue($xml); return $val; }
/** * Gets the datalist of records in the given group in the current state * * Assumes that the desired variant state is in effect. * * @param SolrIndex $indexInstance * @param string $class * @param int $groups * @param int $group * @return DataList */ protected function getRecordsInGroup(SolrIndex $indexInstance, $class, $groups, $group) { // Generate filtered list of local records $baseClass = ClassInfo::baseDataClass($class); $items = DataList::create($class)->where(sprintf('"%s"."ID" %% \'%d\' = \'%d\'', $baseClass, intval($groups), intval($group)))->sort("ID"); // Add child filter $classes = $indexInstance->getClasses(); $options = $classes[$class]; if (!$options['include_children']) { $items = $items->filter('ClassName', $class); } return $items; }
public function processGroup(LoggerInterface $logger, SolrIndex $indexInstance, $state, $class, $groups, $group, $taskName) { $indexName = $indexInstance->getIndexName(); $stateName = json_encode($state); $logger->info("Called processGroup with {$indexName}, {$stateName}, {$class}, group {$group} of {$groups}"); }
/** * Commits the specified index to the Solr service * * @param SolrIndex $index Index object * @return bool Flag indicating success */ protected function commitIndex($index) { return $index->commit() !== false; }
/** * Update the index on the given store * * @param SolrIndex $instance Instance * @param SolrConfigStore $store */ protected function updateIndex($instance, $store) { $index = $instance->getIndexName(); $this->getLogger()->info("Configuring {$index}."); // Upload the config files for this index $this->getLogger()->info("Uploading configuration ..."); $instance->uploadConfig($store); // Then tell Solr to use those config files $service = Solr::service(); if ($service->coreIsActive($index)) { $this->getLogger()->info("Reloading core ..."); $service->coreReload($index); } else { $this->getLogger()->info("Creating core ..."); $service->coreCreate($index, $store->instanceDir($index)); } $this->getLogger()->info("Done"); }