public function buildConfigurationPagePanel()
 {
     $viewer = $this->getViewer();
     $application = $this->getApplication();
     $active_engine = PhabricatorFulltextStorageEngine::loadEngine();
     $engines = PhabricatorFulltextStorageEngine::loadAllEngines();
     $rows = array();
     $rowc = array();
     foreach ($engines as $key => $engine) {
         try {
             $index_exists = $engine->indexExists() ? pht('Yes') : pht('No');
         } catch (Exception $ex) {
             $index_exists = pht('N/A');
         }
         try {
             $index_is_sane = $engine->indexIsSane() ? pht('Yes') : pht('No');
         } catch (Exception $ex) {
             $index_is_sane = pht('N/A');
         }
         if ($engine == $active_engine) {
             $rowc[] = 'highlighted';
         } else {
             $rowc[] = null;
         }
         $rows[] = array($key, get_class($engine), $index_exists, $index_is_sane);
     }
     $table = id(new AphrontTableView($rows))->setNoDataString(pht('No search engines available.'))->setHeaders(array(pht('Key'), pht('Class'), pht('Index Exists'), pht('Index Is Sane')))->setRowClasses($rowc)->setColumnClasses(array('', 'wide', ''));
     $box = id(new PHUIObjectBoxView())->setHeaderText(pht('Search Engines'))->appendChild($table);
     return $box;
 }
 public final function buildFulltextIndexes()
 {
     $object = $this->getObject();
     $extensions = PhabricatorFulltextEngineExtension::getAllExtensions();
     foreach ($extensions as $key => $extension) {
         if (!$extension->shouldIndexFulltextObject($object)) {
             unset($extensions[$key]);
         }
     }
     $document = $this->newAbstractDocument($object);
     $this->buildAbstractDocument($document, $object);
     foreach ($extensions as $extension) {
         $extension->indexFulltextObject($object, $document);
     }
     $storage_engine = PhabricatorFulltextStorageEngine::loadEngine();
     $storage_engine->reindexAbstractDocument($document);
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $engine = PhabricatorFulltextStorageEngine::loadEngine();
     $work_done = false;
     if (!$engine->indexExists()) {
         $console->writeOut('%s', pht('Index does not exist, creating...'));
         $engine->initIndex();
         $console->writeOut("%s\n", pht('done.'));
         $work_done = true;
     } else {
         if (!$engine->indexIsSane()) {
             $console->writeOut('%s', pht('Index exists but is incorrect, fixing...'));
             $engine->initIndex();
             $console->writeOut("%s\n", pht('done.'));
             $work_done = true;
         }
     }
     if ($work_done) {
         $console->writeOut("%s\n", pht('Index maintenance complete. Run `%s` to reindex documents', './bin/search index'));
     } else {
         $console->writeOut("%s\n", pht('Nothing to do.'));
     }
 }
 private function buildFullTextWhereClause(AphrontDatabaseConnection $conn)
 {
     if (!strlen($this->fullTextSearch)) {
         return null;
     }
     // In doing a fulltext search, we first find all the PHIDs that match the
     // fulltext search, and then use that to limit the rest of the search
     $fulltext_query = id(new PhabricatorSavedQuery())->setEngineClassName('PhabricatorSearchApplicationSearchEngine')->setParameter('query', $this->fullTextSearch);
     // NOTE: Setting this to something larger than 2^53 will raise errors in
     // ElasticSearch, and billions of results won't fit in memory anyway.
     $fulltext_query->setParameter('limit', 100000);
     $fulltext_query->setParameter('types', array(ManiphestTaskPHIDType::TYPECONST));
     $engine = PhabricatorFulltextStorageEngine::loadEngine();
     $fulltext_results = $engine->executeSearch($fulltext_query);
     if (empty($fulltext_results)) {
         $fulltext_results = array(null);
     }
     return qsprintf($conn, 'task.phid IN (%Ls)', $fulltext_results);
 }
 protected function shouldUseMySQLSearchEngine()
 {
     $search_engine = PhabricatorFulltextStorageEngine::loadEngine();
     return $search_engine instanceof PhabricatorMySQLFulltextStorageEngine;
 }
 public function loadDocumentPHIDsWithoutPolicyChecks()
 {
     $query = id(clone $this->savedQuery)->setParameter('offset', $this->getOffset())->setParameter('limit', $this->getRawResultLimit());
     $engine = PhabricatorFulltextStorageEngine::loadEngine();
     return $engine->executeSearch($query);
 }
 public function testLoadAllEngines()
 {
     PhabricatorFulltextStorageEngine::loadAllEngines();
     $this->assertTrue(true);
 }