sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
private function serializeBodyObject($object): string
{
try {
return $this->serializer->serialize($object, 'atol_client', $this->getSerializeBodyObjectContext());
} catch (\RuntimeException $exception) {
throw ParseException::becauseOfRuntimeException($exception, ParseExcepti... | @param mixed $object
@throws ParseException
@return string | entailment |
public function get($key, $default = null)
{
$value = $this->settings;
$value = set_nested_array_value($value, $key);
if ( ! is_null($value))
{
return $value;
}
return $default;
} | Gets a value
@param $key
@param null $default
@return mixed | entailment |
public function getAll()
{
$values = json_decode(file_get_contents($this->cacheFile), true);
if ( ! is_null($values))
{
return $values;
}
return [];
} | Gets all cached settings
@return array | entailment |
public function addSubquery(Zend_Search_Lucene_Search_Query $subquery, $sign=null)
{
if ($sign !== true || $this->_signs !== null) { // Skip, if all subqueries are required
if ($this->_signs === null) { // Check, If all previous subqueries are required
... | Add a $subquery (Zend_Search_Lucene_Search_Query) to this query.
The sign is specified as:
TRUE - subquery is required
FALSE - subquery is prohibited
NULL - subquery is neither prohibited, nor required
@param Zend_Search_Lucene_Search_Query $subquery
@param boolean|null $sign
@return void | entailment |
public function rewrite(Zend_Search_Lucene_Interface $index)
{
$query = new Zend_Search_Lucene_Search_Query_Boolean();
$query->setBoost($this->getBoost());
foreach ($this->_subqueries as $subqueryId => $subquery) {
$query->addSubquery(
$subquery->rewrite($index),... | Re-write queries into primitive queries
@param Zend_Search_Lucene_Interface $index
@return Zend_Search_Lucene_Search_Query | entailment |
public function optimize(Zend_Search_Lucene_Interface $index)
{
$subqueries = array();
$signs = array();
// Optimize all subqueries
foreach ($this->_subqueries as $id => $subquery) {
$subqueries[] = $subquery->optimize($index);
$signs[] = ($this->_s... | Optimize query in the context of specified index
@param Zend_Search_Lucene_Interface $index
@return Zend_Search_Lucene_Search_Query | entailment |
public function createWeight(Zend_Search_Lucene_Interface $reader)
{
include_once 'Zend/Search/Lucene/Search/Weight/Boolean.php';
$this->_weight = new Zend_Search_Lucene_Search_Weight_Boolean($this, $reader);
return $this->_weight;
} | Constructs an appropriate Weight implementation for this query.
@param Zend_Search_Lucene_Interface $reader
@return Zend_Search_Lucene_Search_Weight | entailment |
private function _calculateConjunctionResult()
{
$this->_resVector = null;
if (count($this->_subqueries) == 0) {
$this->_resVector = array();
}
$resVectors = array();
$resVectorsSizes = array();
$resVectorsIds = array(); // is used to prevent arra... | Calculate result vector for Conjunction query
(like '<subquery1> AND <subquery2> AND <subquery3>') | entailment |
private function _calculateNonConjunctionResult()
{
$requiredVectors = array();
$requiredVectorsSizes = array();
$requiredVectorsIds = array(); // is used to prevent arrays comparison
$optional = array();
foreach ($this->_subqueries as $subqueryId => $subquery) {
... | Calculate result vector for non Conjunction query
(like '<subquery1> AND <subquery2> AND NOT <subquery3> OR <subquery4>') | entailment |
public function _conjunctionScore($docId, Zend_Search_Lucene_Interface $reader)
{
if ($this->_coord === null) {
$this->_coord = $reader->getSimilarity()->coord(
count($this->_subqueries),
count($this->_subqueries)
);
}
$score = 0;
... | Score calculator for conjunction queries (all subqueries are required)
@param integer $docId
@param Zend_Search_Lucene_Interface $reader
@return float | entailment |
public function _nonConjunctionScore($docId, Zend_Search_Lucene_Interface $reader)
{
if ($this->_coord === null) {
$this->_coord = array();
$maxCoord = 0;
foreach ($this->_signs as $sign) {
if ($sign !== false /* not prohibited */) {
$... | Score calculator for non conjunction queries (not all subqueries are required)
@param integer $docId
@param Zend_Search_Lucene_Interface $reader
@return float | entailment |
public function execute(Zend_Search_Lucene_Interface $reader, $docsFilter = null)
{
// Initialize weight if it's not done yet
$this->_initWeight($reader);
if ($docsFilter === null) {
// Create local documents filter if it's not provided by upper query
include_once 'Z... | Execute query in context of index reader
It also initializes necessary internal structures
@param Zend_Search_Lucene_Interface $reader
@param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter | entailment |
public function score($docId, Zend_Search_Lucene_Interface $reader)
{
if (isset($this->_resVector[$docId])) {
if ($this->_signs === null) {
return $this->_conjunctionScore($docId, $reader);
} else {
return $this->_nonConjunctionScore($docId, $reader);
... | Score specified document
@param integer $docId
@param Zend_Search_Lucene_Interface $reader
@return float | entailment |
public function getQueryTerms()
{
$terms = array();
foreach ($this->_subqueries as $id => $subquery) {
if ($this->_signs === null || $this->_signs[$id] !== false) {
$terms = array_merge($terms, $subquery->getQueryTerms());
}
}
return $terms... | Return query terms
@return array | entailment |
protected function _highlightMatches(Zend_Search_Lucene_Search_Highlighter_Interface $highlighter)
{
foreach ($this->_subqueries as $id => $subquery) {
if ($this->_signs === null || $this->_signs[$id] !== false) {
$subquery->_highlightMatches($highlighter);
}
... | Query specific matches highlighting
@param Zend_Search_Lucene_Search_Highlighter_Interface $highlighter Highlighter object (also contains doc for highlighting) | entailment |
public static function parse(DocumentationPage $page, $baselink = null)
{
if (!$page || (!$page instanceof DocumentationPage)) {
return false;
}
$md = $page->getMarkdown(true);
// Pre-processing
$md = self::rewrite_image_links($md, $page);
$md = self::re... | Parse a given path to the documentation for a file. Performs a case
insensitive lookup on the file system. Automatically appends the file
extension to one of the markdown extensions as well so /install/ in a
web browser will match /install.md or /INSTALL.md.
Filepath: /var/www/myproject/src/cms/en/folder/subfolder/pag... | entailment |
private static function finalize_code_output($i, $output)
{
if (isset($output[$i]) && trim($output[$i])) {
$output[$i] .= "\n```\n";
} else {
$output[$i] = "```";
}
return $output;
} | Adds the closing code backticks. Removes trailing whitespace.
@param int
@param array
@return array | entailment |
public static function rewrite_api_links($markdown, $doc_page)
{
$version = $doc_page->getVersion();
$module = $doc_page->getEntity()->getKey();
// define regexs of the api links to be parsed (note: do not include backticks)
$regexs = array(
'title_and_method' => '# \[ ... | Rewrite links with special "api:" prefix to html as in the following example:
(1) [api:DataObject] gets re-written to
<a href="https://api.silverstripe.org/search/lookup/?q=DataObject&version=2.4&module=framework">DataObject</a>
(2) [api:DataObject::$defaults] gets re-written to
<a href="https://api.silverstripe.org/s... | entailment |
public static function generate_html_id($title)
{
$t = $title;
$t = str_replace('&', '-and-', $t);
$t = str_replace('&', '-and-', $t);
$t = preg_replace('/[^A-Za-z0-9]+/', '-', $t);
$t = preg_replace('/-+/', '-', $t);
$t = trim($t, '-');
$t = strtolower($t... | Generate an html element id from a string
@return String | entailment |
public static function rewrite_relative_links($md, $page)
{
$baselink = $page->getEntity()->Link();
$re = '/
([^\!]?) # exclude image format
\[
(.*?) # link title (non greedy)
\]
\(
(.*?) # link url (non greedy)
\)
/x';
preg_match_all($re, $md, $matches);
/... | Resolves all relative links within markdown.
@param String $md Markdown content
@param DocumentationPage $page
@return String Markdown | entailment |
public static function load($data)
{
$termDictionary = array();
$termInfos = array();
$pos = 0;
// $tiVersion = $tiiFile->readInt();
$tiVersion = ord($data[0]) << 24 | ord($data[1]) << 16 | ord($data[2]) << 8 | ord($data[3]);
$pos += 4;
if ($tiVersion !... | Dictionary index loader.
It takes a string which is actually <segment_name>.tii index file data and
returns two arrays - term and tremInfo lists.
See Zend_Search_Lucene_Index_SegmintInfo class for details
@param string $data
@return array
@throws Zend_Search_Lucene_Exception | entailment |
public function writeAMFData($data,$forcetype=null) {
//If theres no type forced we'll try detecting it
if (is_null($forcetype)) {
$type=false;
// NULL type
if (!$type && is_null($data)) $type = SabreAMF_AMF0_Const::DT_NULL;
// ... | writeAMFData
@param mixed $data
@param int $forcetype
@return mixed | entailment |
public function writeMixedArray($data) {
$this->stream->writeLong(0);
foreach($data as $key=>$value) {
$this->writeString($key);
$this->writeAMFData($value);
}
$this->writeString('');
$this->stream->writeByte(SabreAMF_AMF0_Cons... | writeMixedArray
@param array $data
@return void | entailment |
public function writeArray($data) {
if (!count($data)) {
$this->stream->writeLong(0);
} else {
end($data);
$last = key($data);
$this->stream->writeLong($last+1);
for($i=0;$i<=$last;$i++) {
if (is... | writeArray
@param array $data
@return void | entailment |
public function writeObject($data) {
foreach($data as $key=>$value) {
$this->writeString($key);
$this->writeAmfData($value);
}
$this->writeString('');
$this->stream->writeByte(SabreAMF_AMF0_Const::DT_OBJECTTERM);
return true;
... | writeObject
@param object $data
@return void | entailment |
public function writeString($string) {
$this->stream->writeInt(strlen($string));
$this->stream->writeBuffer($string);
} | writeString
@param string $string
@return void | entailment |
public function writeLongString($string) {
$this->stream->writeLong(strlen($string));
$this->stream->writeBuffer($string);
} | writeLongString
@param string $string
@return void | entailment |
public function writeTypedObject($data) {
if ($data instanceof SabreAMF_ITypedObject) {
$classname = $data->getAMFClassName();
$data = $data->getAMFData();
} else $classname = $this->getRemoteClassName(get_class($data));
$this->writeString($class... | writeTypedObject
@param object $data
@return void | entailment |
public function writeAMF3Data(SabreAMF_AMF3_Wrapper $data) {
$serializer = new SabreAMF_AMF3_Serializer($this->stream);
return $serializer->writeAMFData($data->getData());
} | writeAMF3Data
@param mixed $data
@return void | entailment |
public function writeDate(DateTime $data) {
$this->stream->writeDouble($data->format('U')*1000);
// empty timezone
$this->stream->writeInt(0);
} | Writes a date object
@param DateTime $data
@return void | entailment |
public function set($key, $value)
{
$keyExp = explode('.', $key);
$row = $this->database
->table($this->config['db_table'])
->where('setting_key', $keyExp[0])
->first(['setting_value']);
if (is_null($row))
{
$newKeyExp = array_slice($... | Store value into registry
@param string $key
@param mixed $value
@return mixed | entailment |
public function get($key, $default = null)
{
$value = $this->fetch($key);
if ( ! is_null($value))
{
return $value;
}
if ($default != null)
{
return $default;
}
if ($this->config['fallback'])
{
if ( ! is_nu... | Gets a value
@param string $key
@param string $default
@return mixed | entailment |
public function getAll($cache = true)
{
if ($cache)
{
return $this->cache->getAll();
}
$all = [];
$rows = $this->database->table($this->config['db_table'])->get();
foreach ($rows as $row)
{
$value = json_decode($row->setting_value, t... | Fetch all values
@param $cache
@return mixed | entailment |
public function has($key)
{
$keyExp = explode('.', $key);
if ($this->cache->has($key))
{
return true;
}
$row = $this->database
->table($this->config['db_table'])
->where('setting_key', $keyExp[0])
->first(['setting_value']);
... | Checks if setting exists
@param $key
@return bool | entailment |
public function forget($key)
{
$keyExp = explode('.', $key);
// get settings value by first key name
$query = $this->database
->table($this->config['db_table'])
->where('setting_key', $keyExp[0]);
$row = $query->first(['setting_value']);
if ( ! is_n... | Remove a settings from database and cache file
@param string $key
@return void | entailment |
public function clean($params = [])
{
if ( ! empty($this->config['primary_config_file']))
{
$default_settings = Arr::dot(Config::get($this->config['primary_config_file']));
$saved_settings = Arr::dot($this->getAll($cache = false));
if (array_key_exists('flush',... | Cleans settings that are no longer used in primary config file
@param $params | entailment |
public function flush()
{
$this->cache->flush();
return $this->database->table($this->config['db_table'])->delete();
} | Remove all settings
@return bool | entailment |
private function fetch($key)
{
$keyExp = explode('.', $key);
if ($this->cache->has($key))
{
return $this->cache->get($key);
}
$row = $this->database
->table($this->config['db_table'])
->where('setting_key', $keyExp[0])
->firs... | @param $key
@return mixed|null | entailment |
public static function obtainWriteLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
{
$lock = $lockDirectory->createFile(self::WRITE_LOCK_FILE);
if (!$lock->lock(LOCK_EX)) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Can\'... | Obtain exclusive write lock on the index
@param Zend_Search_Lucene_Storage_Directory $lockDirectory
@return Zend_Search_Lucene_Storage_File
@throws Zend_Search_Lucene_Exception | entailment |
public static function releaseWriteLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
{
$lock = $lockDirectory->getFileObject(self::WRITE_LOCK_FILE);
$lock->unlock();
} | Release exclusive write lock
@param Zend_Search_Lucene_Storage_Directory $lockDirectory | entailment |
private static function _startReadLockProcessing(Zend_Search_Lucene_Storage_Directory $lockDirectory)
{
$lock = $lockDirectory->createFile(self::READ_LOCK_PROCESSING_LOCK_FILE);
if (!$lock->lock(LOCK_EX)) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Searc... | Obtain the exclusive "read escalation/de-escalation" lock
Required to protect the escalate/de-escalate read lock process
on GFS (and potentially other) mounted filesystems.
Why we need this:
While GFS supports cluster-wide locking via flock(), it's
implementation isn't quite what it should be. The locking
semantics ... | entailment |
private static function _stopReadLockProcessing(Zend_Search_Lucene_Storage_Directory $lockDirectory)
{
$lock = $lockDirectory->getFileObject(self::READ_LOCK_PROCESSING_LOCK_FILE);
$lock->unlock();
} | Release the exclusive "read escalation/de-escalation" lock
Required to protect the escalate/de-escalate read lock process
on GFS (and potentially other) mounted filesystems.
@param Zend_Search_Lucene_Storage_Directory $lockDirectory | entailment |
public static function obtainReadLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
{
$lock = $lockDirectory->createFile(self::READ_LOCK_FILE);
if (!$lock->lock(LOCK_SH)) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Can\'t ... | Obtain shared read lock on the index
It doesn't block other read or update processes, but prevent index from the premature cleaning-up
@param Zend_Search_Lucene_Storage_Directory $defaultLockDirectory
@return Zend_Search_Lucene_Storage_File
@throws Zend_Search_Lucene_Exception | entailment |
public static function releaseReadLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
{
$lock = $lockDirectory->getFileObject(self::READ_LOCK_FILE);
$lock->unlock();
} | Release shared read lock
@param Zend_Search_Lucene_Storage_Directory $lockDirectory | entailment |
public static function escalateReadLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
{
self::_startReadLockProcessing($lockDirectory);
$lock = $lockDirectory->getFileObject(self::READ_LOCK_FILE);
// First, release the shared lock for the benefit of GFS since
// it will fail... | Escalate Read lock to exclusive level
@param Zend_Search_Lucene_Storage_Directory $lockDirectory
@return boolean | entailment |
public static function deEscalateReadLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
{
$lock = $lockDirectory->getFileObject(self::READ_LOCK_FILE);
$lock->lock(LOCK_SH);
} | De-escalate Read lock to shared level
@param Zend_Search_Lucene_Storage_Directory $lockDirectory | entailment |
public static function obtainOptimizationLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
{
$lock = $lockDirectory->createFile(self::OPTIMIZATION_LOCK_FILE);
if (!$lock->lock(LOCK_EX, true)) {
return false;
}
return $lock;
} | Obtain exclusive optimization lock on the index
Returns lock object on success and false otherwise (doesn't block execution)
@param Zend_Search_Lucene_Storage_Directory $lockDirectory
@return mixed | entailment |
public static function releaseOptimizationLock(Zend_Search_Lucene_Storage_Directory $lockDirectory)
{
$lock = $lockDirectory->getFileObject(self::OPTIMIZATION_LOCK_FILE);
$lock->unlock();
} | Release exclusive optimization lock
@param Zend_Search_Lucene_Storage_Directory $lockDirectory | entailment |
public function install(
ModuleDataSetupInterface $setup,
ModuleContextInterface $context
) {
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerSetup->addAttribute(\Magento\Customer\Model\Customer::ENTITY, 'legal_type', [
'type' => 'int'... | {@inheritdoc} | entailment |
public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory)
{
/**
* Zend_Search_Lucene uses segments.gen file to retrieve current generation number
*
* Apache Lucene index format documentation mentions this method only as a fallback method
... | Get current generation number
Returns generation number
0 means pre-2.1 index format
-1 means there are no segments files.
@param Zend_Search_Lucene_Storage_Directory $directory
@return integer
@throws Zend_Search_Lucene_Exception | entailment |
public function setFormatVersion($formatVersion)
{
if ($formatVersion != self::FORMAT_PRE_2_1
&& $formatVersion != self::FORMAT_2_1
&& $formatVersion != self::FORMAT_2_3
) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Luc... | Set index format version.
Index is converted to this format at the nearest upfdate time
@param int $formatVersion
@throws Zend_Search_Lucene_Exception | entailment |
private function _readPre21SegmentsFile()
{
$segmentsFile = $this->_directory->getFileObject('segments');
$format = $segmentsFile->readInt();
if ($format != (int)0xFFFFFFFF) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('W... | Read segments file for pre-2.1 Lucene index format
@throws Zend_Search_Lucene_Exception | entailment |
private function _readSegmentsFile()
{
$segmentsFile = $this->_directory->getFileObject(self::getSegmentFileName($this->_generation));
$format = $segmentsFile->readInt();
if ($format == (int)0xFFFFFFFC) {
$this->_formatVersion = self::FORMAT_2_3;
} else if ($format == (... | Read segments file
@throws Zend_Search_Lucene_Exception | entailment |
private function _close()
{
if ($this->_closed) {
// index is already closed and resources are cleaned up
return;
}
$this->commit();
// Release "under processing" flag
Zend_Search_Lucene_LockManager::releaseReadLock($this->_directory);
if ($... | Close current index and free resources | entailment |
private function _getIndexWriter()
{
if ($this->_writer === null) {
include_once 'Zend/Search/Lucene/Index/Writer.php';
$this->_writer = new Zend_Search_Lucene_Index_Writer(
$this->_directory,
$this->_segmentInfos,
$this->_formatVersion... | Returns an instance of Zend_Search_Lucene_Index_Writer for the index
@return Zend_Search_Lucene_Index_Writer | entailment |
public function numDocs()
{
$numDocs = 0;
foreach ($this->_segmentInfos as $segmentInfo) {
$numDocs += $segmentInfo->numDocs();
}
return $numDocs;
} | Returns the total number of non-deleted documents in this index.
@return integer | entailment |
public function isDeleted($id)
{
if ($id >= $this->_docCount) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Document id is out of the range.');
}
$segmentStartId = 0;
foreach ($this->_segmentInfos as $segmentInfo) ... | Checks, that document is deleted
@param integer $id
@return boolean
@throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range | entailment |
public function find($query)
{
if (is_string($query)) {
include_once 'Zend/Search/Lucene/Search/QueryParser.php';
$query = Zend_Search_Lucene_Search_QueryParser::parse($query);
}
if (!$query instanceof Zend_Search_Lucene_Search_Query) {
include_once 'Zen... | Performs a query against the index and returns an array
of Zend_Search_Lucene_Search_QueryHit objects.
Input is a string or Zend_Search_Lucene_Search_Query.
@param Zend_Search_Lucene_Search_QueryParser|string $query
@return array Zend_Search_Lucene_Search_QueryHit
@throws Zend_Search_Lucene_Exception | entailment |
public function getFieldNames($indexed = false)
{
$result = array();
foreach( $this->_segmentInfos as $segmentInfo ) {
$result = array_merge($result, $segmentInfo->getFields($indexed));
}
return $result;
} | Returns a list of all unique field names that exist in this index.
@param boolean $indexed
@return array | entailment |
public function getDocument($id)
{
if ($id instanceof Zend_Search_Lucene_Search_QueryHit) {
/* @var $id Zend_Search_Lucene_Search_QueryHit */
$id = $id->id;
}
if ($id >= $this->_docCount) {
include_once 'Zend/Search/Lucene/Exception.php';
thro... | Returns a Zend_Search_Lucene_Document object for the document
number $id in this index.
@param integer|Zend_Search_Lucene_Search_QueryHit $id
@return Zend_Search_Lucene_Document
@throws Zend_Search_Lucene_Exception Exception is thrown if $id is out of the range | entailment |
public function hasTerm(Zend_Search_Lucene_Index_Term $term)
{
foreach ($this->_segmentInfos as $segInfo) {
if ($segInfo->getTermInfo($term) !== null) {
return true;
}
}
return false;
} | Returns true if index contain documents with specified term.
Is used for query optimization.
@param Zend_Search_Lucene_Index_Term $term
@return boolean | entailment |
public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
{
$subResults = array();
$segmentStartDocId = 0;
foreach ($this->_segmentInfos as $segmentInfo) {
$subResults[] = $segmentInfo->termDocs($term, $segmentStartDocId, $docsFilter);
$segme... | Returns IDs of all documents containing term.
@param Zend_Search_Lucene_Index_Term $term
@param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
@return array | entailment |
public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
{
$result = array();
$segmentStartDocId = 0;
foreach ($this->_segmentInfos as $segmentInfo) {
$result += $segmentInfo->termFreqs($term, $segmentStartDocId, $docsFilter);
$segmentStartD... | Returns an array of all term freqs.
Result array structure: array(docId => freq, ...)
@param Zend_Search_Lucene_Index_Term $term
@param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
@return integer | entailment |
public function docFreq(Zend_Search_Lucene_Index_Term $term)
{
$result = 0;
foreach ($this->_segmentInfos as $segInfo) {
$termInfo = $segInfo->getTermInfo($term);
if ($termInfo !== null) {
$result += $termInfo->docFreq;
}
}
return ... | Returns the number of documents in this index containing the $term.
@param Zend_Search_Lucene_Index_Term $term
@return integer | entailment |
public function norm($id, $fieldName)
{
if ($id >= $this->_docCount) {
return null;
}
$segmentStartId = 0;
foreach ($this->_segmentInfos as $segInfo) {
if ($segmentStartId + $segInfo->count() > $id) {
break;
}
$segment... | Returns a normalization factor for "field, document" pair.
@param integer $id
@param string $fieldName
@return float | entailment |
public function delete($id)
{
if ($id instanceof Zend_Search_Lucene_Search_QueryHit) {
/* @var $id Zend_Search_Lucene_Search_QueryHit */
$id = $id->id;
}
if ($id >= $this->_docCount) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new... | Deletes a document from the index.
$id is an internal document id
@param integer|Zend_Search_Lucene_Search_QueryHit $id
@throws Zend_Search_Lucene_Exception | entailment |
public function addDocument(Zend_Search_Lucene_Document $document)
{
$this->_getIndexWriter()->addDocument($document);
$this->_docCount++;
$this->_hasChanges = true;
} | Adds a document to this index.
@param Zend_Search_Lucene_Document $document | entailment |
private function _updateDocCount()
{
$this->_docCount = 0;
foreach ($this->_segmentInfos as $segInfo) {
$this->_docCount += $segInfo->count();
}
} | Update document counter | entailment |
public function commit()
{
if ($this->_hasChanges) {
$this->_getIndexWriter()->commit();
$this->_updateDocCount();
$this->_hasChanges = false;
}
} | Commit changes resulting from delete() or undeleteAll() operations.
@todo undeleteAll processing. | entailment |
public function optimize()
{
// Commit changes if any changes have been made
$this->commit();
if (count($this->_segmentInfos) > 1 || $this->hasDeletions()) {
$this->_getIndexWriter()->optimize();
$this->_updateDocCount();
}
} | Optimize index.
Merges all segments into one | entailment |
public function terms()
{
$result = array();
/**
* Zend_Search_Lucene_Index_TermsPriorityQueue
*/
include_once 'Zend/Search/Lucene/Index/TermsPriorityQueue.php';
$segmentInfoQueue = new Zend_Search_Lucene_Index_TermsPriorityQueue();
foreach ($this->_segmentInfos as $segm... | Returns an array of all terms in this index.
@return array | entailment |
public function resetTermsStream()
{
if ($this->_termsStream === null) {
/**
* Zend_Search_Lucene_TermStreamsPriorityQueue
*/
include_once 'Zend/Search/Lucene/TermStreamsPriorityQueue.php';
$this->_termsStream = new Zend_Search_Lucene_TermStreamsPriorityQueue($this->_s... | Reset terms stream. | entailment |
public function findOrFail($id): Model
{
if (!is_numeric($id) && empty($id)) {
throw new RepositoryException($this, 'Provided id can not be empty.');
}
if (($this->model->getKeyType() === 'int' && !is_int($id)) ||
($this->model->getKeyType() === 'string' && is_int($i... | {@inheritdoc} | entailment |
public function create(Model $model): Model
{
$this->validateServedEntity($model);
if (!$model->save()) {
throw new RepositoryException($this, "Cannot create $this->modelClass record");
}
return $model;
} | {@inheritdoc} | entailment |
public function delete(Model $model): void
{
$this->validateServedEntity($model);
try {
$result = $model->delete();
} catch (Throwable $exception) {
throw new RepositoryException($this, "Cannot delete $this->modelClass record", 500, $exception);
}
if ... | {@inheritdoc} | entailment |
public function getPage(PagingInfo $paging, array $fieldValues = []): LengthAwarePaginator
{
$builder = $this->query();
$builder->addNestedWhereQuery($this->getNestedWhereConditions($builder->getQuery(), $fieldValues));
return $builder->paginate($paging->pageSize, ['*'], 'page', $paging->pa... | {@inheritdoc} | entailment |
public function getCursorPage(CursorRequest $cursor, array $fieldValues = []): CursorResult
{
$builder = $this->query();
$builder->addNestedWhereQuery($this->getNestedWhereConditions($builder->getQuery(), $fieldValues));
return $this->toCursorResult($cursor, $builder);
} | {@inheritdoc} | entailment |
private function performJoin($query, string $table, string $foreign, string $other)
{
// Check that table not joined yet
$joins = [];
foreach ((array)$query->getQuery()->joins as $key => $join) {
$joins[] = $join->table;
}
if (!in_array($table, $joins)) {
... | Perform join query.
@param Builder|QueryBuilder $query Query builder to apply joins
@param string $table Joined table
@param string $foreign Foreign key
@param string $other Other table key
@return Builder|QueryBuilder | entailment |
protected function getWithBuilder(
array $with,
?array $withCounts = null,
?array $where = null,
?SortOptions $sortOptions = null
): Builder {
return $this->query()
->when($with, function (Builder $query) use ($with) {
return $query->with($with);
... | Returns builder that satisfied requested conditions, with eager loaded requested relations and relations counts,
ordered by requested rules.
@param array $with Which relations should be preloaded
@param array|null $withCounts Which related entities should be counted
@param array|null $where Conditions that retrieved e... | entailment |
public function count(array $where = []): int
{
$builder = $this->query();
if (count($where)) {
$builder->addNestedWhereQuery($this->getNestedWhereConditions($builder->getQuery(), $where));
}
return $builder->count();
} | {@inheritdoc} | entailment |
public function getWith(
array $with,
?array $withCounts = null,
?array $where = null,
?SortOptions $sortOptions = null
): Collection {
$builder = $this->query()
->with($with)
->when($withCounts, function (Builder $query) use ($withCounts) {
... | {@inheritdoc} | entailment |
public function getWhere(array $fieldValues): Collection
{
$builder = $this->query();
return $builder
->addNestedWhereQuery($this->getNestedWhereConditions($builder->getQuery(), $fieldValues))
->get();
} | {@inheritdoc} | entailment |
public function findWhere(array $fieldValues): ?Model
{
$builder = $this->query();
return $builder
->addNestedWhereQuery($this->getNestedWhereConditions($builder->getQuery(), $fieldValues))
->first();
} | {@inheritdoc} | entailment |
protected function getNestedWhereConditions($builder, array $criteria)
{
$subQuery = $builder->forNestedWhere();
foreach ($criteria as $key => $criterionData) {
switch (true) {
case $criterionData instanceof Criterion:
$criterion = $criterionData;
... | Returns query builder with applied criteria. This method work recursively and group nested criteria in one level.
@param QueryBuilder $builder Top level query builder
@param array $criteria Nested list of criteria
@return QueryBuilder
@throws BadCriteriaException when any criterion is not valid | entailment |
protected function isNestedCriteria(array $criterionData): bool
{
$isValid = true;
foreach ($criterionData as $key => $possibleCriterion) {
$isValid = $isValid &&
(
(is_int($key) && is_array($possibleCriterion)) ||
($key === Criter... | Shows whether given criterion data is nested.
@param array $criterionData Criterion data to check
@return boolean | entailment |
protected function parseCriterion(array $criterionData): Criterion
{
return new Criterion([
Criterion::ATTRIBUTE => $criterionData[0] ?? null,
Criterion::OPERATOR => $criterionData[1] ?? null,
Criterion::VALUE => $criterionData[2] ?? null,
Criterion::BOOLEAN =... | Transforms criterion data into DTO.
@param array $criterionData Criterion data to transform
@return Criterion | entailment |
protected function isCriterionValid(Criterion $criterion): bool
{
$isMultipleOperator = (is_array($criterion->value) || $criterion->value instanceof Collection) &&
in_array($criterion->operator, $this->multipleOperators);
$isSingleOperator = is_string($criterion->value) && in_array(strto... | Checks whether the criterion is valid.
@param Criterion $criterion Criterion to check validity
@return boolean | entailment |
public function validate($attributes, Constraint $constraint)
{
if ($attributes->getEmail() || $attributes->getPhone()) {
return;
}
$this->context
->buildViolation($constraint->message)
->atPath('phone / email')
->addViolation();
} | {@inheritdoc}
@param Attributes $attributes
@param EmailOrPhone $constraint | entailment |
public function getBreadcrumbTitle($divider = ' - ')
{
$pathParts = explode('/', trim($this->getRelativePath(), '/'));
// from the page from this
array_pop($pathParts);
// add the module to the breadcrumb trail.
$pathParts[] = $this->entity->getTitle();
$titleParts... | @param string - has to be plain text for open search compatibility.
@return string | entailment |
public function getMarkdown($removeMetaData = false)
{
try {
if (is_file($this->getPath()) && $md = file_get_contents($this->getPath())) {
$this->populateMetaDataFromText($md, $removeMetaData);
return $md;
}
$this->read = true;
} ... | Return the raw markdown for a given documentation page.
@param boolean $removeMetaData
@return string|false | entailment |
public function getRelativeLink()
{
$path = $this->getRelativePath();
$url = explode('/', $path);
$url = implode(
'/',
array_map(
function ($a) {
return DocumentationHelper::clean_page_url($a);
},
$ur... | This should return the link from the entity root to the page. The link
value has the cleaned version of the folder names. See
{@link getRelativePath()} for the actual file path.
@return string | entailment |
public function Link($short = false)
{
return Controller::join_links(
$this->entity->Link($short),
$this->getRelativeLink()
);
} | Returns the URL that will be required for the user to hit to view the
given document base name.
@param boolean $short If true, will attempt to return a short version of the url
This might omit the version number if this is the default version.
@return string | entailment |
public function populateCanonicalUrl()
{
$url = Director::absoluteURL(Controller::join_links(
Config::inst()->get('DocumentationViewer', 'link_base'),
$this->getEntity()->getLanguage(),
$this->getRelativeLink()
));
$this->setCanonicalUrl($url);
} | Determine and set the canonical URL for the given record, for example: dev/docs/en/Path/To/Document | entailment |
public function populateMetaDataFromText(&$md, $removeMetaData = false)
{
if (!$md) {
return;
}
// See if there is YAML metadata block at the top of the document. e.g.
// ---
// property: value
// another: value
// ---
//
// If we ... | Return metadata from the first html block in the page, then remove the
block on request
@param DocumentationPage $md
@param bool $remove | entailment |
public function finishExpression()
{
if ($this->getState() != self::ST_LITERAL) {
include_once 'Zend/Search/Lucene/Exception.php';
throw new Zend_Search_Lucene_Exception('Literal expected.');
}
$this->_conjunctions[] = $this->_currentConjunction;
return $thi... | Finish an expression and return result
Result is a set of boolean query conjunctions
Each conjunction is an array of conjunction elements
Each conjunction element is presented with two-elements array:
array(<literal>, <is_negative>)
So, it has a structure:
array( array( array(<literal>, <is_negative>), // first lite... | entailment |
public function literalAction()
{
// Add literal to the current conjunction
$this->_currentConjunction[] = array($this->_literal, !$this->_negativeLiteral);
// Switch off negative signal
$this->_negativeLiteral = false;
} | Literal processing | entailment |
final public function map(callable $callback): self
{
$literal = [];
for ($i = 0, $rows = $this->getRowCount(); $i < $rows; $i++) {
$row = [];
for ($j = 0, $columns = $this->getColumnCount(); $j < $columns; $j++) {
$row[] = $callback($this->get($i, $j), $i, ... | Iterates over the current matrix with a callback function to return a new
matrix with the mapped values. $callback takes four arguments:
- The current matrix element
- The current row
- The current column
- The matrix being iterated over
@param callable $callback
@return self | entailment |
protected function _fread($length = 1)
{
$returnValue = substr($this->_data, $this->_position, $length);
$this->_position += $length;
return $returnValue;
} | Reads $length number of bytes at the current position in the
file and advances the file pointer.
@param integer $length
@return string | entailment |
public function seek($offset, $whence=SEEK_SET)
{
switch ($whence) {
case SEEK_SET:
$this->_position = $offset;
break;
case SEEK_CUR:
$this->_position += $offset;
break;
case SEEK_END:
$this->_position = strlen($this->_dat... | Sets the file position indicator and advances the file pointer.
The new position, measured in bytes from the beginning of the file,
is obtained by adding offset to the position specified by whence,
whose values are defined as follows:
SEEK_SET - Set position equal to offset bytes.
SEEK_CUR - Set position to current loc... | entailment |
protected function _fwrite($data, $length=null)
{
// We do not need to check if file position points to the end of "file".
// Only append operation is supported now
if ($length !== null) {
$this->_data .= substr($data, 0, $length);
} else {
$this->_data .= $d... | Writes $length number of bytes (all, if $length===null) to the end
of the file.
@param string $data
@param integer $length | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.