Differential D18499 Diff 44445 src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
| Show All 22 Lines | abstract class PhabricatorCursorPagedPolicyAwareQuery | ||||
| private $groupVector; | private $groupVector; | ||||
| private $builtinOrder; | private $builtinOrder; | ||||
| private $edgeLogicConstraints = array(); | private $edgeLogicConstraints = array(); | ||||
| private $edgeLogicConstraintsAreValid = false; | private $edgeLogicConstraintsAreValid = false; | ||||
| private $spacePHIDs; | private $spacePHIDs; | ||||
| private $spaceIsArchived; | private $spaceIsArchived; | ||||
| private $ngrams = array(); | private $ngrams = array(); | ||||
| private $ferretEngine; | private $ferretEngine; | ||||
| private $ferretConstraints; | private $ferretTokens; | ||||
| protected function getPageCursors(array $page) { | protected function getPageCursors(array $page) { | ||||
| return array( | return array( | ||||
| $this->getResultCursor(head($page)), | $this->getResultCursor(head($page)), | ||||
| $this->getResultCursor(last($page)), | $this->getResultCursor(last($page)), | ||||
| ); | ); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,341 Lines • ▼ Show 20 Lines | /* -( Integration with CustomField )--------------------------------------- */ | ||||
| } | } | ||||
| /* -( Ferret )------------------------------------------------------------- */ | /* -( Ferret )------------------------------------------------------------- */ | ||||
| public function withFerretConstraint( | public function withFerretConstraint( | ||||
| PhabricatorFerretEngine $engine, | PhabricatorFerretEngine $engine, | ||||
| $raw_query) { | array $fulltext_tokens) { | ||||
| if ($this->ferretEngine) { | if ($this->ferretEngine) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Query may not have multiple fulltext constraints.')); | 'Query may not have multiple fulltext constraints.')); | ||||
| } | } | ||||
| if (!strlen($raw_query)) { | if (!$fulltext_tokens) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| $this->ferretEngine = $engine; | $this->ferretEngine = $engine; | ||||
| $this->ferretConstraints = preg_split('/\s+/', $raw_query); | $this->ferretTokens = $fulltext_tokens; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function buildFerretJoinClause(AphrontDatabaseConnection $conn) { | protected function buildFerretJoinClause(AphrontDatabaseConnection $conn) { | ||||
| if (!$this->ferretEngine) { | if (!$this->ferretEngine) { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| $engine = $this->ferretEngine; | $engine = $this->ferretEngine; | ||||
| $ngram_engine = new PhabricatorNgramEngine(); | $ngram_engine = new PhabricatorNgramEngine(); | ||||
| $ngram_table = $engine->newNgramsObject(); | $ngram_table = $engine->newNgramsObject(); | ||||
| $ngram_table_name = $ngram_table->getTableName(); | $ngram_table_name = $ngram_table->getTableName(); | ||||
| $flat = array(); | $flat = array(); | ||||
| foreach ($this->ferretConstraints as $term) { | foreach ($this->ferretTokens as $fulltext_token) { | ||||
| $value = $term; | $raw_token = $fulltext_token->getToken(); | ||||
| $length = count(phutil_utf8v($term)); | $value = $raw_token->getValue(); | ||||
| $length = count(phutil_utf8v($value)); | |||||
| if ($length >= 3) { | if ($length >= 3) { | ||||
| $ngrams = $ngram_engine->getNgramsFromString($value, 'query'); | $ngrams = $ngram_engine->getNgramsFromString($value, 'query'); | ||||
| $prefix = false; | $prefix = false; | ||||
| } else if ($length == 2) { | } else if ($length == 2) { | ||||
| $ngrams = $ngram_engine->getNgramsFromString($value, 'prefix'); | $ngrams = $ngram_engine->getNgramsFromString($value, 'prefix'); | ||||
| $prefix = false; | $prefix = false; | ||||
| } else { | } else { | ||||
| ▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | /* -( Ferret )------------------------------------------------------------- */ | ||||
| } | } | ||||
| protected function buildFerretWhereClause(AphrontDatabaseConnection $conn) { | protected function buildFerretWhereClause(AphrontDatabaseConnection $conn) { | ||||
| if (!$this->ferretEngine) { | if (!$this->ferretEngine) { | ||||
| return array(); | return array(); | ||||
| } | } | ||||
| $where = array(); | $where = array(); | ||||
| foreach ($this->ferretConstraints as $constraint) { | foreach ($this->ferretTokens as $fulltext_token) { | ||||
| $raw_token = $fulltext_token->getToken(); | |||||
| $value = $raw_token->getValue(); | |||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '(ftfield.rawCorpus LIKE %~ OR ftfield.normalCorpus LIKE %~)', | '(ftfield.rawCorpus LIKE %~ OR ftfield.normalCorpus LIKE %~)', | ||||
| $constraint, | $value, | ||||
| $constraint); | $value); | ||||
| } | } | ||||
| return $where; | return $where; | ||||
| } | } | ||||
| protected function shouldGroupFerretResultRows() { | protected function shouldGroupFerretResultRows() { | ||||
| return (bool)$this->ferretConstraints; | return (bool)$this->ferretTokens; | ||||
| } | } | ||||
| /* -( Ngrams )------------------------------------------------------------- */ | /* -( Ngrams )------------------------------------------------------------- */ | ||||
| protected function withNgramsConstraint( | protected function withNgramsConstraint( | ||||
| PhabricatorSearchNgrams $index, | PhabricatorSearchNgrams $index, | ||||
| ▲ Show 20 Lines • Show All 747 Lines • Show Last 20 Lines | |||||