public function indexDocumentByPHID($phid, $context)
 {
     $this->setContext($context);
     $document = $this->buildAbstractDocumentByPHID($phid);
     if ($document === null) {
         // This indexer doesn't build a document index, so we're done.
         return $this;
     }
     $object = $this->loadDocumentByPHID($phid);
     // Automatically rebuild CustomField indexes if the object uses custom
     // fields.
     if ($object instanceof PhabricatorCustomFieldInterface) {
         $this->indexCustomFields($document, $object);
     }
     // Automatically rebuild subscriber indexes if the object is subscribable.
     if ($object instanceof PhabricatorSubscribableInterface) {
         $this->indexSubscribers($document);
     }
     // Automatically build project relationships
     if ($object instanceof PhabricatorProjectInterface) {
         $this->indexProjects($document, $object);
     }
     $engine = PhabricatorSearchEngine::loadEngine();
     $engine->reindexAbstractDocument($document);
     $this->dispatchDidUpdateIndexEvent($phid, $document);
     return $this;
 }
 public function buildConfigurationPagePanel()
 {
     $viewer = $this->getViewer();
     $application = $this->getApplication();
     $active_engine = PhabricatorSearchEngine::loadEngine();
     $engines = PhabricatorSearchEngine::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 function indexDocumentByPHID($phid, $context)
 {
     try {
         $this->setContext($context);
         $document = $this->buildAbstractDocumentByPHID($phid);
         if ($document === null) {
             // This indexer doesn't build a document index, so we're done.
             return $this;
         }
         $object = $this->loadDocumentByPHID($phid);
         // Automatically rebuild CustomField indexes if the object uses custom
         // fields.
         if ($object instanceof PhabricatorCustomFieldInterface) {
             $this->indexCustomFields($document, $object);
         }
         // Automatically rebuild subscriber indexes if the object is subscribable.
         if ($object instanceof PhabricatorSubscribableInterface) {
             $this->indexSubscribers($document);
         }
         // Automatically build project relationships
         if ($object instanceof PhabricatorProjectInterface) {
             $this->indexProjects($document, $object);
         }
         $engine = PhabricatorSearchEngine::loadEngine();
         try {
             $engine->reindexAbstractDocument($document);
         } catch (Exception $ex) {
             phlog(pht('Unable to index document %s with engine %s.', $document->getPHID(), get_class($engine)));
             phlog($ex);
         }
         $this->dispatchDidUpdateIndexEvent($phid, $document);
     } catch (Exception $ex) {
         phlog(pht('Unable to build document %s with indexer %s.', $phid, get_class($this)));
         phlog($ex);
     }
     return $this;
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $engine = PhabricatorSearchEngine::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.'));
     }
 }
 protected function shouldUseElasticSearchEngine()
 {
     $search_engine = PhabricatorSearchEngine::loadEngine();
     return $search_engine instanceof PhabricatorElasticSearchEngine;
 }
 public function loadDocumentPHIDsWithoutPolicyChecks()
 {
     $query = id(clone $this->savedQuery)->setParameter('offset', $this->getOffset())->setParameter('limit', $this->getRawResultLimit());
     $engine = PhabricatorSearchEngine::loadEngine();
     return $engine->executeSearch($query);
 }
 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 = PhabricatorSearchEngine::loadEngine();
     $fulltext_results = $engine->executeSearch($fulltext_query);
     if (empty($fulltext_results)) {
         $fulltext_results = array(null);
     }
     return qsprintf($conn, 'task.phid IN (%Ls)', $fulltext_results);
 }
 public function testLoadAllEngines()
 {
     PhabricatorSearchEngine::loadAllEngines();
     $this->assertTrue(true);
 }