idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
59,100
public function setNextEntrySign ( $ sign ) { if ( $ this -> _mode === self :: GM_BOOLEAN ) { include_once 'Zend/Search/Lucene/Search/QueryParserException.php' ; throw new Zend_Search_Lucene_Search_QueryParserException ( 'It\'s not allowed to mix boolean and signs styles in the same subquery.' ) ; } $ this -> _mode = self :: GM_SIGNS ; if ( $ sign == Zend_Search_Lucene_Search_QueryToken :: TT_REQUIRED ) { $ this -> _nextEntrySign = true ; } else if ( $ sign == Zend_Search_Lucene_Search_QueryToken :: TT_PROHIBITED ) { $ this -> _nextEntrySign = false ; } else { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Unrecognized sign type.' ) ; } }
Set sign for next entry
59,101
public function addEntry ( Zend_Search_Lucene_Search_QueryEntry $ entry ) { if ( $ this -> _mode !== self :: GM_BOOLEAN ) { $ this -> _signs [ ] = $ this -> _nextEntrySign ; } $ this -> _entries [ ] = $ entry ; $ this -> _nextEntryField = null ; $ this -> _nextEntrySign = null ; }
Add entry to a query
59,102
public function processFuzzyProximityModifier ( $ parameter = null ) { if ( $ this -> _nextEntryField !== null || $ this -> _nextEntrySign !== null ) { include_once 'Zend/Search/Lucene/Search/QueryParserException.php' ; throw new Zend_Search_Lucene_Search_QueryParserException ( '\'~\' modifier must follow word or phrase.' ) ; } $ lastEntry = array_pop ( $ this -> _entries ) ; if ( ! $ lastEntry instanceof Zend_Search_Lucene_Search_QueryEntry ) { include_once 'Zend/Search/Lucene/Search/QueryParserException.php' ; throw new Zend_Search_Lucene_Search_QueryParserException ( '\'~\' modifier must follow word or phrase.' ) ; } $ lastEntry -> processFuzzyProximityModifier ( $ parameter ) ; $ this -> _entries [ ] = $ lastEntry ; }
Process fuzzy search or proximity search modifier
59,103
public function boost ( $ boostFactor ) { if ( $ this -> _nextEntryField !== null || $ this -> _nextEntrySign !== null ) { include_once 'Zend/Search/Lucene/Search/QueryParserException.php' ; throw new Zend_Search_Lucene_Search_QueryParserException ( '\'^\' modifier must follow word, phrase or subquery.' ) ; } $ lastEntry = array_pop ( $ this -> _entries ) ; if ( ! $ lastEntry instanceof Zend_Search_Lucene_Search_QueryEntry ) { include_once 'Zend/Search/Lucene/Search/QueryParserException.php' ; throw new Zend_Search_Lucene_Search_QueryParserException ( '\'^\' modifier must follow word, phrase or subquery.' ) ; } $ lastEntry -> boost ( $ boostFactor ) ; $ this -> _entries [ ] = $ lastEntry ; }
Set boost factor to the entry
59,104
public function addLogicalOperator ( $ operator ) { if ( $ this -> _mode === self :: GM_SIGNS ) { include_once 'Zend/Search/Lucene/Search/QueryParserException.php' ; throw new Zend_Search_Lucene_Search_QueryParserException ( 'It\'s not allowed to mix boolean and signs styles in the same subquery.' ) ; } $ this -> _mode = self :: GM_BOOLEAN ; $ this -> _entries [ ] = $ operator ; }
Process logical operator
59,105
public function writeString ( $ str ) { settype ( $ str , 'string' ) ; $ chars = $ strlen = strlen ( $ str ) ; $ containNullChars = false ; for ( $ count = 0 ; $ count < $ strlen ; $ count ++ ) { if ( ( ord ( $ str [ $ count ] ) & 0xC0 ) == 0xC0 ) { $ addBytes = 1 ; if ( ord ( $ str [ $ count ] ) & 0x20 ) { $ addBytes ++ ; if ( ord ( $ str [ $ count ] ) & 0x10 ) { $ addBytes ++ ; } } $ chars -= $ addBytes ; if ( ord ( $ str [ $ count ] ) == 0 ) { $ containNullChars = true ; } $ count += $ addBytes ; } } if ( $ chars < 0 ) { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Invalid UTF-8 string' ) ; } $ this -> writeVInt ( $ chars ) ; if ( $ containNullChars ) { $ this -> _fwrite ( str_replace ( $ str , "\x00" , "\xC0\x80" ) ) ; } else { $ this -> _fwrite ( $ str ) ; } }
Writes a string to the end of file .
59,106
protected function mayCache ( $ item ) { return ( isset ( $ item ) && is_object ( $ item ) && isset ( $ item -> headers ) && is_string ( $ item -> headers -> etag ) && ! empty ( $ item -> headers -> etag ) && isset ( $ item -> body ) && is_object ( $ item -> body ) ) ; }
Returns whether or not the item may be cached . It has to be a stdClass that Sag would return with a valid E - Tag and no cache headers that tell us to not cache .
59,107
public function performSearch ( ) { try { $ index = Zend_Search_Lucene :: open ( self :: get_index_location ( ) ) ; Zend_Search_Lucene :: setResultSetLimit ( 100 ) ; $ query = new Zend_Search_Lucene_Search_Query_Boolean ( ) ; $ term = Zend_Search_Lucene_Search_QueryParser :: parse ( $ this -> getQuery ( ) ) ; $ query -> addSubquery ( $ term , true ) ; if ( $ this -> modules ) { $ moduleQuery = new Zend_Search_Lucene_Search_Query_MultiTerm ( ) ; foreach ( $ this -> modules as $ module ) { $ moduleQuery -> addTerm ( new Zend_Search_Lucene_Index_Term ( $ module , 'Entity' ) ) ; } $ query -> addSubquery ( $ moduleQuery , true ) ; } if ( $ this -> versions ) { $ versionQuery = new Zend_Search_Lucene_Search_Query_MultiTerm ( ) ; foreach ( $ this -> versions as $ version ) { $ versionQuery -> addTerm ( new Zend_Search_Lucene_Index_Term ( $ version , 'Version' ) ) ; } $ query -> addSubquery ( $ versionQuery , true ) ; } $ er = error_reporting ( ) ; error_reporting ( 'E_ALL ^ E_NOTICE' ) ; $ this -> results = $ index -> find ( $ query ) ; error_reporting ( $ er ) ; $ this -> totalResults = $ index -> numDocs ( ) ; } catch ( Zend_Search_Lucene_Exception $ e ) { user_error ( $ e . '. Ensure you have run the rebuld task (/dev/tasks/RebuildLuceneDocsIndex)' , E_USER_ERROR ) ; } }
Perform a search query on the index
59,108
private function buildQueryUrl ( $ params ) { $ url = parse_url ( $ _SERVER [ 'REQUEST_URI' ] ) ; if ( ! array_key_exists ( 'query' , $ url ) ) { $ url [ 'query' ] = '' ; } parse_str ( $ url [ 'query' ] , $ url [ 'query' ] ) ; if ( ! is_array ( $ url [ 'query' ] ) ) { $ url [ 'query' ] = array ( ) ; } if ( array_key_exists ( 'start' , $ url [ 'query' ] ) ) { unset ( $ url [ 'query' ] [ 'start' ] ) ; } $ url [ 'query' ] = array_merge ( $ url [ 'query' ] , $ params ) ; $ url [ 'query' ] = http_build_query ( $ url [ 'query' ] ) ; $ url = $ url [ 'path' ] . ( $ url [ 'query' ] ? '?' . $ url [ 'query' ] : '' ) ; return $ url ; }
Build a nice query string for the results
59,109
public static function get_meta_data ( ) { $ data = self :: $ meta_data ; $ defaults = array ( 'Description' => _t ( 'DocumentationViewer.OPENSEARCHDESC' , 'Search the documentation' ) , 'Tags' => _t ( 'DocumentationViewer.OPENSEARCHTAGS' , 'documentation' ) , 'Contact' => Config :: inst ( ) -> get ( 'Email' , 'admin_email' ) , 'ShortName' => _t ( 'DocumentationViewer.OPENSEARCHNAME' , 'Documentation Search' ) , 'Author' => 'SilverStripe' ) ; foreach ( $ defaults as $ key => $ value ) { if ( isset ( $ data [ $ key ] ) ) { $ defaults [ $ key ] = $ data [ $ key ] ; } } return $ defaults ; }
Returns the meta data needed by opensearch .
59,110
public function renderResults ( ) { if ( ! $ this -> results && $ this -> query ) { $ this -> performSearch ( ) ; } if ( ! $ this -> outputController ) { return user_error ( 'Call renderResults() on a DocumentationViewer instance.' , E_USER_ERROR ) ; } $ request = $ this -> outputController -> getRequest ( ) ; $ data = $ this -> getSearchResults ( $ request ) ; $ templates = array ( 'DocumentationViewer_search' ) ; if ( $ request -> requestVar ( 'format' ) && $ request -> requestVar ( 'format' ) == "atom" ) { $ title = ( $ title = $ this -> getTitle ( ) ) ? ' - ' . $ title : "" ; $ link = Controller :: join_links ( $ this -> outputController -> Link ( ) , 'DocumentationOpenSearchController/description/' ) ; $ data -> setField ( 'Title' , $ data -> Title . $ title ) ; $ data -> setField ( 'DescriptionURL' , $ link ) ; array_unshift ( $ templates , 'OpenSearchResults' ) ; } return $ this -> outputController -> customise ( $ data ) -> renderWith ( $ templates ) ; }
Renders the search results into a template . Either the search results template or the Atom feed .
59,111
public function merge ( ) { if ( $ this -> _mergeDone ) { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Merge is already done.' ) ; } if ( count ( $ this -> _segmentInfos ) < 1 ) { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Wrong number of segments to be merged (' . count ( $ this -> _segmentInfos ) . ').' ) ; } $ this -> _mergeFields ( ) ; $ this -> _mergeNorms ( ) ; $ this -> _mergeStoredFields ( ) ; $ this -> _mergeTerms ( ) ; $ this -> _mergeDone = true ; return $ this -> _writer -> close ( ) ; }
Do merge .
59,112
private function _mergeNorms ( ) { foreach ( $ this -> _writer -> getFieldInfos ( ) as $ fieldInfo ) { if ( $ fieldInfo -> isIndexed ) { foreach ( $ this -> _segmentInfos as $ segName => $ segmentInfo ) { if ( $ segmentInfo -> hasDeletions ( ) ) { $ srcNorm = $ segmentInfo -> normVector ( $ fieldInfo -> name ) ; $ norm = '' ; $ docs = $ segmentInfo -> count ( ) ; for ( $ count = 0 ; $ count < $ docs ; $ count ++ ) { if ( ! $ segmentInfo -> isDeleted ( $ count ) ) { $ norm .= $ srcNorm [ $ count ] ; } } $ this -> _writer -> addNorm ( $ fieldInfo -> name , $ norm ) ; } else { $ this -> _writer -> addNorm ( $ fieldInfo -> name , $ segmentInfo -> normVector ( $ fieldInfo -> name ) ) ; } } } } }
Merge field s normalization factors
59,113
public function canView ( ) { return ( Director :: isDev ( ) || Director :: is_cli ( ) || ! $ this -> config ( ) -> get ( 'check_permission' ) || Permission :: check ( $ this -> config ( ) -> get ( 'check_permission' ) ) ) ; }
Can the user view this documentation . Hides all functionality for private wikis .
59,114
public function getContent ( ) { $ page = $ this -> getPage ( ) ; $ html = $ page -> getHTML ( ) ; $ html = $ this -> replaceChildrenCalls ( $ html ) ; return $ html ; }
Return the content for the page . If its an actual documentation page then display the content from the page otherwise display the contents from the index . md file if its a folder
59,115
public function includeChildren ( $ args ) { if ( isset ( $ args [ 'Folder' ] ) ) { $ children = $ this -> getManifest ( ) -> getChildrenFor ( Controller :: join_links ( dirname ( $ this -> record -> getPath ( ) ) , $ args [ 'Folder' ] ) ) ; } else { $ children = $ this -> getManifest ( ) -> getChildrenFor ( dirname ( $ this -> record -> getPath ( ) ) ) ; } if ( isset ( $ args [ 'Exclude' ] ) ) { $ exclude = explode ( ',' , $ args [ 'Exclude' ] ) ; foreach ( $ children as $ k => $ child ) { foreach ( $ exclude as $ e ) { if ( $ child -> Link == Controller :: join_links ( $ this -> record -> Link ( ) , strtolower ( $ e ) , '/' ) ) { unset ( $ children [ $ k ] ) ; } } } } return $ this -> customise ( new ArrayData ( array ( 'Children' => $ children ) ) ) -> renderWith ( 'Includes/DocumentationPages' ) ; }
Short code parser
59,116
public function getBreadcrumbs ( ) { if ( $ this -> record ) { return $ this -> getManifest ( ) -> generateBreadcrumbs ( $ this -> record , $ this -> record -> getEntity ( ) ) ; } }
Generate a list of breadcrumbs for the user .
59,117
public function Link ( $ action = '' ) { $ link = Controller :: join_links ( Director :: baseURL ( ) , Config :: inst ( ) -> get ( 'DocumentationViewer' , 'link_base' ) , $ this -> getLanguage ( ) , $ action , '/' ) ; return $ link ; }
Return the base link to this documentation location .
59,118
public function AllPages ( $ version = null ) { $ pages = $ this -> getManifest ( ) -> getPages ( ) ; $ output = new ArrayList ( ) ; $ baseLink = $ this -> getDocumentationBaseHref ( ) ; foreach ( $ pages as $ url => $ page ) { if ( ! is_null ( $ version ) && ( string ) $ page [ 'version' ] !== ( string ) $ version ) { continue ; } $ first = strtoupper ( trim ( substr ( $ page [ 'title' ] , 0 , 1 ) ) ) ; if ( $ first ) { $ output -> push ( new ArrayData ( array ( 'Link' => Controller :: join_links ( $ baseLink , $ url ) , 'Title' => $ page [ 'title' ] , 'FirstLetter' => $ first ) ) ) ; } } return GroupedList :: create ( $ output -> sort ( 'Title' , 'ASC' ) ) ; }
Generate a list of all the pages in the documentation grouped by the first letter of the page .
59,119
public function getNextPage ( ) { return ( $ this -> record ) ? $ this -> getManifest ( ) -> getNextPage ( $ this -> record -> getPath ( ) , $ this -> getEntity ( ) -> getPath ( ) ) : null ; }
Returns the next page . Either retrieves the sibling of the current page or return the next sibling of the parent page .
59,120
public function getPreviousPage ( ) { return ( $ this -> record ) ? $ this -> getManifest ( ) -> getPreviousPage ( $ this -> record -> getPath ( ) , $ this -> getEntity ( ) -> getPath ( ) ) : null ; }
Returns the previous page . Either returns the previous sibling or the parent of this page
59,121
protected function getAtoumArguments ( ) { $ inlinedArguments = array ( ) ; foreach ( $ this -> atoumArguments as $ name => $ values ) { $ inlinedArguments [ ] = $ name ; if ( null !== $ values ) { $ inlinedArguments [ ] = $ values ; } } return $ inlinedArguments ; }
Return inlined atoum cli arguments
59,122
private function assertValid ( $ object , int $ code = 0 ) { $ errors = $ this -> validator -> validate ( $ object ) ; if ( count ( $ errors ) ) { throw ValidationException :: becauseOfValidationErrors ( $ errors , $ code ) ; } }
Assert that object is valid .
59,123
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 ) , ( $ this -> _signs === null ) ? true : $ this -> _signs [ $ subqueryId ] ) ; } return $ query ; }
Re - write queries into primitive queries
59,124
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 .
59,125
public static function generate_html_id ( $ title ) { $ t = $ title ; $ t = str_replace ( '&amp;' , '-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 ) ; return $ t ; }
Generate an html element id from a string
59,126
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 ) ; $ relativePath = DocumentationHelper :: normalizePath ( dirname ( $ page -> getRelativePath ( ) ) ) ; if ( strpos ( $ page -> getRelativePath ( ) , 'index.md' ) ) { $ relativeLink = $ page -> getRelativeLink ( ) ; } else { $ relativeLink = DocumentationHelper :: normalizePath ( dirname ( $ page -> getRelativeLink ( ) ) ) ; } if ( $ relativePath == '.' ) { $ relativePath = '' ; } if ( $ relativeLink == "." ) { $ relativeLink = '' ; } $ fileBaseLink = DocumentationHelper :: relativePath ( DocumentationHelper :: normalizePath ( dirname ( $ page -> getPath ( ) ) ) ) ; if ( $ matches ) { foreach ( $ matches [ 0 ] as $ i => $ match ) { $ title = $ matches [ 2 ] [ $ i ] ; $ url = $ matches [ 3 ] [ $ i ] ; if ( preg_match ( '/^api:/' , $ url ) ) { continue ; } $ urlParts = parse_url ( $ url ) ; if ( $ urlParts && isset ( $ urlParts [ 'scheme' ] ) ) { continue ; } if ( preg_match ( '/_images/' , $ url ) ) { $ relativeUrl = Controller :: join_links ( Director :: absoluteBaseURL ( ) , $ fileBaseLink , $ url ) ; } elseif ( preg_match ( '/^#/' , $ url ) ) { $ relativeUrl = Controller :: join_links ( $ baselink , $ page -> getRelativeLink ( ) , $ url ) ; } else { if ( preg_match ( '/^\//' , $ url ) ) { $ relativeUrl = Controller :: join_links ( $ baselink , $ url , '/' ) ; } else { $ relativeUrl = Controller :: join_links ( $ baselink , $ relativeLink , $ url , '/' ) ; } } while ( strpos ( $ relativeUrl , '..' ) !== false ) { $ relativeUrl = preg_replace ( '/[-\w]+\/\.\.\//' , '' , $ relativeUrl ) ; } $ relativeUrl = preg_replace ( '/([^:])\/{2,}/' , '$1/' , $ relativeUrl ) ; $ md = str_replace ( $ match , sprintf ( '%s[%s](%s)' , $ matches [ 1 ] [ $ i ] , $ title , $ relativeUrl ) , $ md ) ; } } return $ md ; }
Resolves all relative links within markdown .
59,127
public function writeDate ( DateTime $ data ) { $ this -> stream -> writeDouble ( $ data -> format ( 'U' ) * 1000 ) ; $ this -> stream -> writeInt ( 0 ) ; }
Writes a date object
59,128
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 , true ) ; $ all [ $ row -> setting_key ] = $ value ; } return $ all ; }
Fetch all values
59,129
public function forget ( $ key ) { $ keyExp = explode ( '.' , $ key ) ; $ query = $ this -> database -> table ( $ this -> config [ 'db_table' ] ) -> where ( 'setting_key' , $ keyExp [ 0 ] ) ; $ row = $ query -> first ( [ 'setting_value' ] ) ; if ( ! is_null ( $ row ) ) { if ( count ( $ keyExp ) > 1 ) { $ setting_value = json_decode ( $ row -> setting_value , true ) ; unset ( $ keyExp [ 0 ] ) ; $ newKey = implode ( '.' , $ keyExp ) ; Arr :: forget ( $ setting_value , $ newKey ) ; if ( count ( $ setting_value ) > 0 ) { $ query -> update ( [ 'setting_value' => json_encode ( $ setting_value ) ] ) ; } else { $ query -> delete ( ) ; } } else { $ query -> delete ( ) ; } } $ this -> cache -> forget ( $ key ) ; }
Remove a settings from database and cache file
59,130
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' , $ params ) && $ params [ 'flush' ] == true ) { $ this -> flush ( ) ; $ saved_settings = [ ] ; } else { foreach ( $ saved_settings as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ default_settings ) ) { if ( ! key_represents_an_array ( $ key , $ default_settings ) ) { $ this -> forget ( $ key ) ; } } } } foreach ( $ default_settings as $ key => $ value ) { if ( ! preg_key_exists ( $ key , $ saved_settings ) ) { if ( ! key_represents_an_array ( $ key , $ saved_settings ) ) { $ this -> set ( $ key , $ value ) ; } } } } }
Cleans settings that are no longer used in primary config file
59,131
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\'t obtain exclusive index lock' ) ; } return $ lock ; }
Obtain exclusive write lock on the index
59,132
public static function releaseWriteLock ( Zend_Search_Lucene_Storage_Directory $ lockDirectory ) { $ lock = $ lockDirectory -> getFileObject ( self :: WRITE_LOCK_FILE ) ; $ lock -> unlock ( ) ; }
Release exclusive write lock
59,133
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 reading index lock' ) ; } return $ lock ; }
Obtain shared read lock on the index
59,134
public static function releaseReadLock ( Zend_Search_Lucene_Storage_Directory $ lockDirectory ) { $ lock = $ lockDirectory -> getFileObject ( self :: READ_LOCK_FILE ) ; $ lock -> unlock ( ) ; }
Release shared read lock
59,135
public static function escalateReadLock ( Zend_Search_Lucene_Storage_Directory $ lockDirectory ) { self :: _startReadLockProcessing ( $ lockDirectory ) ; $ lock = $ lockDirectory -> getFileObject ( self :: READ_LOCK_FILE ) ; $ lock -> unlock ( ) ; for ( $ retries = 0 ; $ retries < 10 ; $ retries ++ ) { if ( $ lock -> lock ( LOCK_EX , true ) ) { self :: _stopReadLockProcessing ( $ lockDirectory ) ; return true ; } usleep ( 1 ) ; } $ lock -> lock ( LOCK_SH ) ; self :: _stopReadLockProcessing ( $ lockDirectory ) ; return false ; }
Escalate Read lock to exclusive level
59,136
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
59,137
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
59,138
public static function releaseOptimizationLock ( Zend_Search_Lucene_Storage_Directory $ lockDirectory ) { $ lock = $ lockDirectory -> getFileObject ( self :: OPTIMIZATION_LOCK_FILE ) ; $ lock -> unlock ( ) ; }
Release exclusive optimization lock
59,139
public static function getActualGeneration ( Zend_Search_Lucene_Storage_Directory $ directory ) { include_once 'Zend/Search/Lucene/Exception.php' ; try { for ( $ count = 0 ; $ count < self :: GENERATION_RETRIEVE_COUNT ; $ count ++ ) { $ genFile = $ directory -> getFileObject ( 'segments.gen' , false ) ; $ format = $ genFile -> readInt ( ) ; if ( $ format != ( int ) 0xFFFFFFFE ) { throw new Zend_Search_Lucene_Exception ( 'Wrong segments.gen file format' ) ; } $ gen1 = $ genFile -> readLong ( ) ; $ gen2 = $ genFile -> readLong ( ) ; if ( $ gen1 == $ gen2 ) { return $ gen1 ; } usleep ( self :: GENERATION_RETRIEVE_PAUSE * 1000 ) ; } throw new Zend_Search_Lucene_Exception ( 'Index is under processing now' ) ; } catch ( Zend_Search_Lucene_Exception $ e ) { if ( strpos ( $ e -> getMessage ( ) , 'is not readable' ) !== false ) { try { $ segmentsFile = $ directory -> getFileObject ( 'segments' , false ) ; return 0 ; } catch ( Zend_Search_Lucene_Exception $ e ) { if ( strpos ( $ e -> getMessage ( ) , 'is not readable' ) !== false ) { return - 1 ; } else { throw new Zend_Search_Lucene_Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } } } else { throw new Zend_Search_Lucene_Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } } return - 1 ; }
Get current generation number
59,140
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_Lucene_Exception ( 'Unsupported index format' ) ; } $ this -> _formatVersion = $ formatVersion ; }
Set index format version . Index is converted to this format at the nearest upfdate time
59,141
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 ( 'Wrong segments file format' ) ; } $ segmentsFile -> readLong ( ) ; $ segmentsFile -> readInt ( ) ; $ segments = $ segmentsFile -> readInt ( ) ; $ this -> _docCount = 0 ; for ( $ count = 0 ; $ count < $ segments ; $ count ++ ) { $ segName = $ segmentsFile -> readString ( ) ; $ segSize = $ segmentsFile -> readInt ( ) ; $ this -> _docCount += $ segSize ; $ this -> _segmentInfos [ $ segName ] = new Zend_Search_Lucene_Index_SegmentInfo ( $ this -> _directory , $ segName , $ segSize ) ; } $ this -> _formatVersion = self :: FORMAT_2_1 ; }
Read segments file for pre - 2 . 1 Lucene index format
59,142
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 == ( int ) 0xFFFFFFFD ) { $ this -> _formatVersion = self :: FORMAT_2_1 ; } else { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Unsupported segments file format' ) ; } $ segmentsFile -> readLong ( ) ; $ segmentsFile -> readInt ( ) ; $ segments = $ segmentsFile -> readInt ( ) ; $ this -> _docCount = 0 ; for ( $ count = 0 ; $ count < $ segments ; $ count ++ ) { $ segName = $ segmentsFile -> readString ( ) ; $ segSize = $ segmentsFile -> readInt ( ) ; $ delGen = $ segmentsFile -> readLong ( ) ; if ( $ this -> _formatVersion == self :: FORMAT_2_3 ) { $ docStoreOffset = $ segmentsFile -> readInt ( ) ; if ( $ docStoreOffset != ( int ) 0xFFFFFFFF ) { $ docStoreSegment = $ segmentsFile -> readString ( ) ; $ docStoreIsCompoundFile = $ segmentsFile -> readByte ( ) ; $ docStoreOptions = array ( 'offset' => $ docStoreOffset , 'segment' => $ docStoreSegment , 'isCompound' => ( $ docStoreIsCompoundFile == 1 ) ) ; } else { $ docStoreOptions = null ; } } else { $ docStoreOptions = null ; } $ hasSingleNormFile = $ segmentsFile -> readByte ( ) ; $ numField = $ segmentsFile -> readInt ( ) ; $ normGens = array ( ) ; if ( $ numField != ( int ) 0xFFFFFFFF ) { for ( $ count1 = 0 ; $ count1 < $ numField ; $ count1 ++ ) { $ normGens [ ] = $ segmentsFile -> readLong ( ) ; } include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Separate norm files are not supported. Optimize index to use it with Zend_Search_Lucene.' ) ; } $ isCompoundByte = $ segmentsFile -> readByte ( ) ; if ( $ isCompoundByte == 0xFF ) { $ isCompound = false ; } else if ( $ isCompoundByte == 0x00 ) { $ isCompound = null ; } else if ( $ isCompoundByte == 0x01 ) { $ isCompound = true ; } $ this -> _docCount += $ segSize ; $ this -> _segmentInfos [ $ segName ] = new Zend_Search_Lucene_Index_SegmentInfo ( $ this -> _directory , $ segName , $ segSize , $ delGen , $ docStoreOptions , $ hasSingleNormFile , $ isCompound ) ; } }
Read segments file
59,143
private function _close ( ) { if ( $ this -> _closed ) { return ; } $ this -> commit ( ) ; Zend_Search_Lucene_LockManager :: releaseReadLock ( $ this -> _directory ) ; if ( $ this -> _closeDirOnExit ) { $ this -> _directory -> close ( ) ; } $ this -> _directory = null ; $ this -> _writer = null ; $ this -> _segmentInfos = null ; $ this -> _closed = true ; }
Close current index and free resources
59,144
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 ) ; } return $ this -> _writer ; }
Returns an instance of Zend_Search_Lucene_Index_Writer for the index
59,145
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 ) ; $ segmentStartDocId += $ segmentInfo -> count ( ) ; } if ( count ( $ subResults ) == 0 ) { return array ( ) ; } else if ( count ( $ subResults ) == 1 ) { return reset ( $ subResults ) ; } else { $ result = call_user_func_array ( 'array_merge' , $ subResults ) ; } return $ result ; }
Returns IDs of all documents containing term .
59,146
private function _updateDocCount ( ) { $ this -> _docCount = 0 ; foreach ( $ this -> _segmentInfos as $ segInfo ) { $ this -> _docCount += $ segInfo -> count ( ) ; } }
Update document counter
59,147
public function optimize ( ) { $ this -> commit ( ) ; if ( count ( $ this -> _segmentInfos ) > 1 || $ this -> hasDeletions ( ) ) { $ this -> _getIndexWriter ( ) -> optimize ( ) ; $ this -> _updateDocCount ( ) ; } }
Optimize index .
59,148
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 ) ; } ) -> when ( $ withCounts , function ( Builder $ query ) use ( $ withCounts ) { return $ query -> withCount ( $ withCounts ) ; } ) -> when ( $ where , function ( Builder $ query ) use ( $ where ) { return $ query -> where ( $ where ) ; } ) -> when ( $ sortOptions , function ( Builder $ query ) use ( $ sortOptions ) { return $ query -> orderBy ( $ sortOptions -> orderBy , $ sortOptions -> sortOrder ) ; } ) ; }
Returns builder that satisfied requested conditions with eager loaded requested relations and relations counts ordered by requested rules .
59,149
protected function getNestedWhereConditions ( $ builder , array $ criteria ) { $ subQuery = $ builder -> forNestedWhere ( ) ; foreach ( $ criteria as $ key => $ criterionData ) { switch ( true ) { case $ criterionData instanceof Criterion : $ criterion = $ criterionData ; break ; case is_string ( $ key ) && ( ( ! is_array ( $ criterionData ) && ! is_object ( $ criterionData ) ) || $ criterionData instanceof Carbon ) : $ criterion = new Criterion ( [ Criterion :: ATTRIBUTE => $ key , Criterion :: VALUE => $ criterionData ] ) ; break ; case is_int ( $ key ) && is_array ( $ criterionData ) && $ this -> isNestedCriteria ( $ criterionData ) : $ boolean = 'and' ; if ( isset ( $ criterionData [ Criterion :: BOOLEAN ] ) ) { $ boolean = $ criterionData [ Criterion :: BOOLEAN ] ; unset ( $ criterionData [ Criterion :: BOOLEAN ] ) ; } $ subQuery -> addNestedWhereQuery ( $ this -> getNestedWhereConditions ( $ subQuery , $ criterionData ) , $ boolean ) ; continue 2 ; default : $ criterion = $ this -> parseCriterion ( $ criterionData ) ; } if ( ! $ this -> isCriterionValid ( $ criterion ) ) { throw new BadCriteriaException ( $ this ) ; } switch ( $ criterion -> operator ) { case 'in' : $ subQuery -> whereIn ( $ criterion -> attribute , $ criterion -> value , $ criterion -> boolean ) ; break ; case 'not in' : $ subQuery -> whereNotIn ( $ criterion -> attribute , $ criterion -> value , $ criterion -> boolean ) ; break ; default : $ subQuery -> where ( $ criterion -> attribute , $ criterion -> operator , $ criterion -> value , $ criterion -> boolean ) ; break ; } } return $ subQuery ; }
Returns query builder with applied criteria . This method work recursively and group nested criteria in one level .
59,150
protected function isNestedCriteria ( array $ criterionData ) : bool { $ isValid = true ; foreach ( $ criterionData as $ key => $ possibleCriterion ) { $ isValid = $ isValid && ( ( is_int ( $ key ) && is_array ( $ possibleCriterion ) ) || ( $ key === Criterion :: BOOLEAN && in_array ( $ possibleCriterion , [ 'and' , 'or' ] ) ) ) ; } return $ isValid ; }
Shows whether given criterion data is nested .
59,151
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 => $ criterionData [ 3 ] ?? 'and' , ] ) ; }
Transforms criterion data into DTO .
59,152
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 ( strtolower ( $ criterion -> operator ) , $ this -> singleOperators ) ; return is_string ( $ criterion -> attribute ) && is_string ( $ criterion -> boolean ) && ( $ isMultipleOperator || $ isSingleOperator ) ; }
Checks whether the criterion is valid .
59,153
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 ; } catch ( InvalidArgumentException $ e ) { } return false ; }
Return the raw markdown for a given documentation page .
59,154
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 .
59,155
public function populateMetaDataFromText ( & $ md , $ removeMetaData = false ) { if ( ! $ md ) { return ; } $ parser = new \ Mni \ FrontYAML \ Parser ( ) ; $ document = $ parser -> parse ( $ md , false ) ; $ yaml = $ document -> getYAML ( ) ; if ( $ yaml ) { foreach ( $ yaml as $ key => $ value ) { if ( ! property_exists ( get_class ( $ this ) , $ key ) ) { continue ; } $ this -> $ key = $ value ; } if ( $ removeMetaData ) { $ md = $ document -> getContent ( ) ; } return ; } $ extPattern = "/^(.+)\n\r*\n/Uis" ; $ matches = preg_match ( $ extPattern , $ md , $ block ) ; if ( $ matches && $ block [ 1 ] ) { $ metaDataFound = false ; $ lines = preg_split ( '/\v+/' , $ block [ 1 ] ) ; $ key = '' ; $ value = '' ; foreach ( $ lines as $ line ) { if ( strpos ( $ line , ':' ) !== false ) { list ( $ key , $ value ) = explode ( ':' , $ line , 2 ) ; $ key = trim ( $ key ) ; $ value = trim ( $ value ) ; } else { $ value .= ' ' . trim ( $ line ) ; } if ( property_exists ( get_class ( ) , $ key ) ) { $ this -> $ key = $ value ; $ metaDataFound = true ; } } if ( $ metaDataFound && $ removeMetaData ) { $ md = preg_replace ( $ extPattern , '' , $ md ) ; } } }
Return metadata from the first html block in the page then remove the block on request
59,156
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 $ this -> _conjunctions ; }
Finish an expression and return result
59,157
public function writeByte ( $ byte ) { $ this -> _data .= chr ( $ byte ) ; $ this -> _position = strlen ( $ this -> _data ) ; return 1 ; }
Writes a byte to the end of the file .
59,158
public function readBytes ( $ num ) { $ returnValue = substr ( $ this -> _data , $ this -> _position , $ num ) ; $ this -> _position += $ num ; return $ returnValue ; }
Read num bytes from the current position in the file and advances the file pointer .
59,159
public function readBinary ( ) { $ length = $ this -> readVInt ( ) ; $ returnValue = substr ( $ this -> _data , $ this -> _position , $ length ) ; $ this -> _position += $ length ; return $ returnValue ; }
Reads binary data from the current position in the file and advances the file pointer .
59,160
public function getStatus ( ) { if ( null === $ this -> username || null === $ this -> password ) { throw new Exception \ InvalidCredentialsException ( 'No API credentials provided' ) ; } $ res = $ this -> getAdapter ( ) -> getContent ( self :: SMS_STATUS_URL , 'POST' , $ headers = array ( ) , $ this -> getParameters ( ) ) ; return $ this -> parseStatusResults ( $ res ) ; }
Retrieves the queued delivery receipts
59,161
protected function parseStatusResults ( $ result , array $ extra_result_data = array ( ) ) { $ result = trim ( $ result ) ; $ this -> checkForUnrecoverableError ( $ result ) ; return $ this -> checkForStatusResult ( $ result ) ; }
Parses the data returned by the API for a status request .
59,162
protected function parseSendResults ( $ result , array $ extra_result_data = array ( ) ) { $ result = trim ( $ result ) ; $ this -> checkForUnrecoverableError ( $ result ) ; if ( ! $ this -> isMessageSent ( $ result ) ) { return array_merge ( $ this -> getDefaults ( ) , $ extra_result_data ) ; } $ sms_data = array ( 'status' => ResultInterface :: STATUS_SENT , ) ; $ arr = explode ( ' ' , $ result ) ; if ( 3 === count ( $ arr ) ) { list ( $ _ , $ ref ) = explode ( ':' , $ arr [ 2 ] ) ; $ sms_data [ 'id' ] = $ arr [ 1 ] ; $ sms_data [ 'user_ref' ] = $ ref ; } elseif ( 2 === count ( $ arr ) ) { $ sms_data [ 'id' ] = $ arr [ 1 ] ; } return array_merge ( $ this -> getDefaults ( ) , $ extra_result_data , $ sms_data ) ; }
Parses the data returned by the API for a send request .
59,163
public function normalize ( Zend_Search_Lucene_Analysis_Token $ token ) { foreach ( $ this -> _filters as $ filter ) { $ token = $ filter -> normalize ( $ token ) ; if ( $ token === null ) { return null ; } } return $ token ; }
Apply filters to the token . Can return null when the token was removed .
59,164
public function withAddedInterceptor ( string $ name , array $ functions ) : self { if ( ! isset ( $ this -> interceptors [ $ name ] ) ) { $ this -> interceptors [ $ name ] = [ ] ; } $ this -> interceptors [ $ name ] = array_merge ( $ this -> interceptors [ $ name ] , $ functions ) ; return $ this ; }
Add a function to the interceptor
59,165
public function removeInterceptor ( string $ name ) : self { if ( isset ( $ this -> interceptors [ $ name ] ) ) { unset ( $ this -> interceptors [ $ name ] ) ; } return $ this ; }
Remove the interceptor
59,166
public function callInterceptor ( string $ name , ... $ arguments ) { if ( ! empty ( $ this -> interceptors [ $ name ] ) ) { foreach ( $ this -> interceptors [ $ name ] as $ function ) { $ ret = Helper :: call ( $ function , ... $ arguments ) ; if ( $ ret !== null ) { return $ ret ; } } } return null ; }
Call the interceptor
59,167
public static function parse ( $ strQuery , $ encoding = null ) { self :: _getInstance ( ) ; self :: $ _instance -> reset ( ) ; include_once 'Zend/Search/Lucene/Search/QueryParserException.php' ; try { include_once 'Zend/Search/Lucene/Search/QueryParserContext.php' ; self :: $ _instance -> _encoding = ( $ encoding !== null ) ? $ encoding : self :: $ _instance -> _defaultEncoding ; self :: $ _instance -> _lastToken = null ; self :: $ _instance -> _context = new Zend_Search_Lucene_Search_QueryParserContext ( self :: $ _instance -> _encoding ) ; self :: $ _instance -> _contextStack = array ( ) ; self :: $ _instance -> _tokens = self :: $ _instance -> _lexer -> tokenize ( $ strQuery , self :: $ _instance -> _encoding ) ; if ( count ( self :: $ _instance -> _tokens ) == 0 ) { include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php' ; return new Zend_Search_Lucene_Search_Query_Insignificant ( ) ; } foreach ( self :: $ _instance -> _tokens as $ token ) { try { self :: $ _instance -> _currentToken = $ token ; self :: $ _instance -> process ( $ token -> type ) ; self :: $ _instance -> _lastToken = $ token ; } catch ( Exception $ e ) { if ( strpos ( $ e -> getMessage ( ) , 'There is no any rule for' ) !== false ) { throw new Zend_Search_Lucene_Search_QueryParserException ( 'Syntax error at char position ' . $ token -> position . '.' , 0 , $ e ) ; } include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } } if ( count ( self :: $ _instance -> _contextStack ) != 0 ) { throw new Zend_Search_Lucene_Search_QueryParserException ( 'Syntax Error: mismatched parentheses, every opening must have closing.' ) ; } return self :: $ _instance -> _context -> getQuery ( ) ; } catch ( Zend_Search_Lucene_Search_QueryParserException $ e ) { if ( self :: $ _instance -> _suppressQueryParsingExceptions ) { $ queryTokens = Zend_Search_Lucene_Analysis_Analyzer :: getDefault ( ) -> tokenize ( $ strQuery , self :: $ _instance -> _encoding ) ; include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php' ; $ query = new Zend_Search_Lucene_Search_Query_MultiTerm ( ) ; $ termsSign = ( self :: $ _instance -> _defaultOperator == self :: B_AND ) ? true : null ; include_once 'Zend/Search/Lucene/Index/Term.php' ; foreach ( $ queryTokens as $ token ) { $ query -> addTerm ( new Zend_Search_Lucene_Index_Term ( $ token -> getTermText ( ) ) , $ termsSign ) ; } return $ query ; } else { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } } }
Parses a query string
59,168
public function addTermEntry ( ) { include_once 'Zend/Search/Lucene/Search/QueryEntry/Term.php' ; $ entry = new Zend_Search_Lucene_Search_QueryEntry_Term ( $ this -> _currentToken -> text , $ this -> _context -> getField ( ) ) ; $ this -> _context -> addEntry ( $ entry ) ; }
Add term to a query
59,169
public function addPhraseEntry ( ) { include_once 'Zend/Search/Lucene/Search/QueryEntry/Phrase.php' ; $ entry = new Zend_Search_Lucene_Search_QueryEntry_Phrase ( $ this -> _currentToken -> text , $ this -> _context -> getField ( ) ) ; $ this -> _context -> addEntry ( $ entry ) ; }
Add phrase to a query
59,170
public function processModifierParameter ( ) { if ( $ this -> _lastToken === null ) { include_once 'Zend/Search/Lucene/Search/QueryParserException.php' ; throw new Zend_Search_Lucene_Search_QueryParserException ( 'Lexeme modifier parameter must follow lexeme modifier. Char position 0.' ) ; } switch ( $ this -> _lastToken -> type ) { case Zend_Search_Lucene_Search_QueryToken :: TT_FUZZY_PROX_MARK : $ this -> _context -> processFuzzyProximityModifier ( $ this -> _currentToken -> text ) ; break ; case Zend_Search_Lucene_Search_QueryToken :: TT_BOOSTING_MARK : $ this -> _context -> boost ( $ this -> _currentToken -> text ) ; break ; default : include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Lexeme modifier parameter must follow lexeme modifier. Char position 0.' ) ; } }
Process modifier parameter
59,171
protected function cached ( string $ key , Closure $ dataGetter ) { if ( $ this -> cacheRepository -> has ( $ key ) ) { return $ this -> cacheRepository -> get ( $ key ) ; } $ result = $ dataGetter ( ) ; $ this -> cacheRepository -> put ( $ key , $ result , $ this -> cacheTimeout ) ; return $ result ; }
Get data from cache . If it not exists in cache got it in repository and store in cache .
59,172
private function find ( $ id ) : ? Model { try { return $ this -> repository -> findOrFail ( $ id ) ; } catch ( ModelNotFoundException $ exception ) { return null ; } }
Find model in original repository .
59,173
protected function invalidate ( Model $ model ) : void { $ key = $ this -> prefix . ":" . $ model -> getKey ( ) ; if ( $ this -> cacheRepository -> has ( $ key ) ) { $ this -> cacheRepository -> forget ( $ key ) ; } $ this -> cacheRepository -> forget ( "$this->prefix.:all" ) ; }
Invalidate model in cache .
59,174
public function setMax ( string $ key , int $ max_size = - 1 ) : int { $ is_exist = ! $ this -> init ( $ key , $ max_size ) ; if ( $ is_exist && $ this -> resource_map [ $ key ] instanceof Channel ) { $ current_max = $ this -> status_map [ $ key ] [ 'max' ] ; $ this -> status_map [ $ key ] [ 'max' ] = $ max_size ; if ( $ max_size > $ current_max || $ max_size < 0 ) { if ( $ max_size < 0 ) { $ new_pool = new SplQueue ( ) ; } else { $ new_pool = new Channel ( $ max_size ) ; } $ old_chan = $ this -> resource_map [ $ key ] ; while ( ! $ old_chan -> isEmpty ( ) ) { $ new_pool -> push ( $ old_chan -> pop ( ) ) ; } $ old_chan -> close ( ) ; return 1 ; } elseif ( $ max_size < $ this -> status_map [ $ key ] [ 'max' ] ) { return - 1 ; } } return 0 ; }
expend will create the new chan
59,175
public static function mkdirs ( $ dir , $ mode = 0777 , $ recursive = true ) { if ( ( $ dir === null ) || $ dir === '' ) { return false ; } if ( is_dir ( $ dir ) || $ dir === '/' ) { return true ; } if ( self :: mkdirs ( dirname ( $ dir ) , $ mode , $ recursive ) ) { return mkdir ( $ dir , $ mode ) ; } return false ; }
Utility function to recursive directory creation
59,176
public function fileList ( ) { $ result = array ( ) ; $ dirContent = opendir ( $ this -> _dirPath ) ; while ( ( $ file = readdir ( $ dirContent ) ) !== false ) { if ( ( $ file == '..' ) || ( $ file == '.' ) ) { continue ; } if ( ! is_dir ( $ this -> _dirPath . '/' . $ file ) ) { $ result [ ] = $ file ; } } closedir ( $ dirContent ) ; return $ result ; }
Returns an array of strings one for each file in the directory .
59,177
public function purgeFile ( $ filename ) { if ( isset ( $ this -> _fileHandlers [ $ filename ] ) ) { $ this -> _fileHandlers [ $ filename ] -> close ( ) ; } unset ( $ this -> _fileHandlers [ $ filename ] ) ; }
Purge file if it s cached by directory object
59,178
public function renameFile ( $ from , $ to ) { global $ php_errormsg ; if ( isset ( $ this -> _fileHandlers [ $ from ] ) ) { $ this -> _fileHandlers [ $ from ] -> close ( ) ; } unset ( $ this -> _fileHandlers [ $ from ] ) ; if ( isset ( $ this -> _fileHandlers [ $ to ] ) ) { $ this -> _fileHandlers [ $ to ] -> close ( ) ; } unset ( $ this -> _fileHandlers [ $ to ] ) ; if ( file_exists ( $ this -> _dirPath . '/' . $ to ) ) { if ( ! unlink ( $ this -> _dirPath . '/' . $ to ) ) { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( 'Delete operation failed' ) ; } } $ trackErrors = ini_get ( 'track_errors' ) ; ini_set ( 'track_errors' , '1' ) ; $ success = @ rename ( $ this -> _dirPath . '/' . $ from , $ this -> _dirPath . '/' . $ to ) ; if ( ! $ success ) { ini_set ( 'track_errors' , $ trackErrors ) ; include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( $ php_errormsg ) ; } ini_set ( 'track_errors' , $ trackErrors ) ; return $ success ; }
Renames an existing file in the directory .
59,179
private function _retrieveNodeText ( DOMNode $ node , & $ text ) { if ( $ node -> nodeType == XML_TEXT_NODE ) { $ text .= $ node -> nodeValue ; if ( ! in_array ( $ node -> parentNode -> tagName , $ this -> _inlineTags ) ) { $ text .= ' ' ; } } else if ( $ node -> nodeType == XML_ELEMENT_NODE && $ node -> nodeName != 'script' ) { foreach ( $ node -> childNodes as $ childNode ) { $ this -> _retrieveNodeText ( $ childNode , $ text ) ; } } }
Get node text
59,180
public static function loadHTML ( $ data , $ storeContent = false , $ defaultEncoding = '' ) { return new Zend_Search_Lucene_Document_Html ( $ data , false , $ storeContent , $ defaultEncoding ) ; }
Load HTML document from a string
59,181
public static function loadHTMLFile ( $ file , $ storeContent = false , $ defaultEncoding = '' ) { return new Zend_Search_Lucene_Document_Html ( $ file , true , $ storeContent , $ defaultEncoding ) ; }
Load HTML document from a file
59,182
protected function _highlightTextNode ( DOMText $ node , $ wordsToHighlight , $ callback , $ params ) { include_once 'Zend/Search/Lucene/Analysis/Analyzer.php' ; $ analyzer = Zend_Search_Lucene_Analysis_Analyzer :: getDefault ( ) ; $ analyzer -> setInput ( $ node -> nodeValue , 'UTF-8' ) ; $ matchedTokens = array ( ) ; while ( ( $ token = $ analyzer -> nextToken ( ) ) !== null ) { if ( isset ( $ wordsToHighlight [ $ token -> getTermText ( ) ] ) ) { $ matchedTokens [ ] = $ token ; } } if ( count ( $ matchedTokens ) == 0 ) { return ; } $ matchedTokens = array_reverse ( $ matchedTokens ) ; foreach ( $ matchedTokens as $ token ) { $ node -> splitText ( $ token -> getEndOffset ( ) ) ; $ matchedWordNode = $ node -> splitText ( $ token -> getStartOffset ( ) ) ; $ fullCallbackparamsList = $ params ; array_unshift ( $ fullCallbackparamsList , $ matchedWordNode -> nodeValue ) ; $ highlightedWordNodeSetHtml = call_user_func_array ( $ callback , $ fullCallbackparamsList ) ; $ highlightedWordNodeSetDomDocument = new DOMDocument ( '1.0' , 'UTF-8' ) ; $ success = @ $ highlightedWordNodeSetDomDocument -> loadHTML ( '<html><head><meta http-equiv="Content-type" content="text/html; charset=UTF-8"/></head><body>' . $ highlightedWordNodeSetHtml . '</body></html>' ) ; if ( ! $ success ) { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( "Error occured while loading highlighted text fragment: '$highlightedWordNodeSetHtml'." ) ; } $ highlightedWordNodeSetXpath = new DOMXPath ( $ highlightedWordNodeSetDomDocument ) ; $ highlightedWordNodeSet = $ highlightedWordNodeSetXpath -> query ( '/html/body' ) -> item ( 0 ) -> childNodes ; for ( $ count = 0 ; $ count < $ highlightedWordNodeSet -> length ; $ count ++ ) { $ nodeToImport = $ highlightedWordNodeSet -> item ( $ count ) ; $ node -> parentNode -> insertBefore ( $ this -> _doc -> importNode ( $ nodeToImport , true ) , $ matchedWordNode ) ; } $ node -> parentNode -> removeChild ( $ matchedWordNode ) ; } }
Highlight text in text node
59,183
protected function _highlightNodeRecursive ( DOMNode $ contextNode , $ wordsToHighlight , $ callback , $ params ) { $ textNodes = array ( ) ; if ( ! $ contextNode -> hasChildNodes ( ) ) { return ; } foreach ( $ contextNode -> childNodes as $ childNode ) { if ( $ childNode -> nodeType == XML_TEXT_NODE ) { $ textNodes [ ] = $ childNode ; } else { if ( $ childNode -> nodeName != 'script' ) { $ this -> _highlightNodeRecursive ( $ childNode , $ wordsToHighlight , $ callback , $ params ) ; } } } foreach ( $ textNodes as $ textNode ) { $ this -> _highlightTextNode ( $ textNode , $ wordsToHighlight , $ callback , $ params ) ; } }
highlight words in content of the specified node
59,184
public function highlightExtended ( $ words , $ callback , $ params = array ( ) ) { include_once 'Zend/Search/Lucene/Analysis/Analyzer.php' ; if ( ! is_array ( $ words ) ) { $ words = array ( $ words ) ; } $ wordsToHighlightList = array ( ) ; $ analyzer = Zend_Search_Lucene_Analysis_Analyzer :: getDefault ( ) ; foreach ( $ words as $ wordString ) { $ wordsToHighlightList [ ] = $ analyzer -> tokenize ( $ wordString ) ; } $ wordsToHighlight = call_user_func_array ( 'array_merge' , $ wordsToHighlightList ) ; if ( count ( $ wordsToHighlight ) == 0 ) { return $ this -> _doc -> saveHTML ( ) ; } $ wordsToHighlightFlipped = array ( ) ; foreach ( $ wordsToHighlight as $ id => $ token ) { $ wordsToHighlightFlipped [ $ token -> getTermText ( ) ] = $ id ; } if ( ! is_callable ( $ callback ) ) { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( '$viewHelper parameter mast be a View Helper name, View Helper object or callback.' ) ; } $ xpath = new DOMXPath ( $ this -> _doc ) ; $ matchedNodes = $ xpath -> query ( "/html/body" ) ; foreach ( $ matchedNodes as $ matchedNode ) { $ this -> _highlightNodeRecursive ( $ matchedNode , $ wordsToHighlightFlipped , $ callback , $ params ) ; } }
Highlight text using specified View helper or callback function .
59,185
public function getHtmlBody ( ) { $ xpath = new DOMXPath ( $ this -> _doc ) ; $ bodyNodes = $ xpath -> query ( '/html/body' ) -> item ( 0 ) -> childNodes ; $ outputFragments = array ( ) ; for ( $ count = 0 ; $ count < $ bodyNodes -> length ; $ count ++ ) { $ outputFragments [ ] = $ this -> _doc -> saveXML ( $ bodyNodes -> item ( $ count ) ) ; } return implode ( $ outputFragments ) ; }
Get HTML body
59,186
private function _calculateMaxDistance ( $ prefixLength , $ termLength , $ length ) { $ this -> _maxDistances [ $ length ] = ( int ) ( ( 1 - $ this -> _minimumSimilarity ) * ( min ( $ termLength , $ length ) + $ prefixLength ) ) ; return $ this -> _maxDistances [ $ length ] ; }
Calculate maximum distance for specified word length
59,187
public static function createIndex ( Zend_Search_Lucene_Storage_Directory $ directory , $ generation , $ nameCount ) { if ( $ generation == 0 ) { foreach ( $ directory -> fileList ( ) as $ file ) { if ( $ file == 'deletable' || $ file == 'segments' || isset ( self :: $ _indexExtensions [ substr ( $ file , strlen ( $ file ) - 4 ) ] ) || preg_match ( '/\.f\d+$/i' , $ file ) ) { $ directory -> deleteFile ( $ file ) ; } } $ segmentsFile = $ directory -> createFile ( 'segments' ) ; $ segmentsFile -> writeInt ( ( int ) 0xFFFFFFFF ) ; $ segmentsFile -> writeLong ( round ( microtime ( true ) ) ) ; $ segmentsFile -> writeInt ( $ nameCount ) ; $ segmentsFile -> writeInt ( 0 ) ; $ deletableFile = $ directory -> createFile ( 'deletable' ) ; $ deletableFile -> writeInt ( 0 ) ; } else { $ genFile = $ directory -> createFile ( 'segments.gen' ) ; $ genFile -> writeInt ( ( int ) 0xFFFFFFFE ) ; $ genFile -> writeLong ( $ generation ) ; $ genFile -> writeLong ( $ generation ) ; $ segmentsFile = $ directory -> createFile ( Zend_Search_Lucene :: getSegmentFileName ( $ generation ) ) ; $ segmentsFile -> writeInt ( ( int ) 0xFFFFFFFD ) ; $ segmentsFile -> writeLong ( round ( microtime ( true ) ) ) ; $ segmentsFile -> writeInt ( $ nameCount ) ; $ segmentsFile -> writeInt ( 0 ) ; } }
Create empty index
59,188
private function _hasAnythingToMerge ( ) { $ segmentSizes = array ( ) ; foreach ( $ this -> _segmentInfos as $ segName => $ segmentInfo ) { $ segmentSizes [ $ segName ] = $ segmentInfo -> count ( ) ; } $ mergePool = array ( ) ; $ poolSize = 0 ; $ sizeToMerge = $ this -> maxBufferedDocs ; asort ( $ segmentSizes , SORT_NUMERIC ) ; foreach ( $ segmentSizes as $ segName => $ size ) { while ( $ size >= $ sizeToMerge ) { if ( $ poolSize >= $ sizeToMerge ) { return true ; } $ mergePool = array ( ) ; $ poolSize = 0 ; $ sizeToMerge *= $ this -> mergeFactor ; if ( $ sizeToMerge > $ this -> maxMergeDocs ) { return false ; } } $ mergePool [ ] = $ this -> _segmentInfos [ $ segName ] ; $ poolSize += $ size ; } if ( $ poolSize >= $ sizeToMerge ) { return true ; } return false ; }
Check if we have anything to merge
59,189
private function _maybeMergeSegments ( ) { if ( Zend_Search_Lucene_LockManager :: obtainOptimizationLock ( $ this -> _directory ) === false ) { return ; } if ( ! $ this -> _hasAnythingToMerge ( ) ) { Zend_Search_Lucene_LockManager :: releaseOptimizationLock ( $ this -> _directory ) ; return ; } $ this -> _updateSegments ( ) ; $ segmentSizes = array ( ) ; foreach ( $ this -> _segmentInfos as $ segName => $ segmentInfo ) { $ segmentSizes [ $ segName ] = $ segmentInfo -> count ( ) ; } $ mergePool = array ( ) ; $ poolSize = 0 ; $ sizeToMerge = $ this -> maxBufferedDocs ; asort ( $ segmentSizes , SORT_NUMERIC ) ; foreach ( $ segmentSizes as $ segName => $ size ) { while ( $ size >= $ sizeToMerge ) { if ( $ poolSize >= $ sizeToMerge ) { $ this -> _mergeSegments ( $ mergePool ) ; } $ mergePool = array ( ) ; $ poolSize = 0 ; $ sizeToMerge *= $ this -> mergeFactor ; if ( $ sizeToMerge > $ this -> maxMergeDocs ) { Zend_Search_Lucene_LockManager :: releaseOptimizationLock ( $ this -> _directory ) ; return ; } } $ mergePool [ ] = $ this -> _segmentInfos [ $ segName ] ; $ poolSize += $ size ; } if ( $ poolSize >= $ sizeToMerge ) { $ this -> _mergeSegments ( $ mergePool ) ; } Zend_Search_Lucene_LockManager :: releaseOptimizationLock ( $ this -> _directory ) ; }
Merge segments if necessary
59,190
private function _mergeSegments ( $ segments ) { $ newName = $ this -> _newSegmentName ( ) ; include_once 'Zend/Search/Lucene/Index/SegmentMerger.php' ; $ merger = new Zend_Search_Lucene_Index_SegmentMerger ( $ this -> _directory , $ newName ) ; foreach ( $ segments as $ segmentInfo ) { $ merger -> addSource ( $ segmentInfo ) ; $ this -> _segmentsToDelete [ $ segmentInfo -> getName ( ) ] = $ segmentInfo -> getName ( ) ; } $ newSegment = $ merger -> merge ( ) ; if ( $ newSegment !== null ) { $ this -> _newSegments [ $ newSegment -> getName ( ) ] = $ newSegment ; } $ this -> commit ( ) ; }
Merge specified segments
59,191
public function commit ( ) { if ( $ this -> _currentSegment !== null ) { $ newSegment = $ this -> _currentSegment -> close ( ) ; if ( $ newSegment !== null ) { $ this -> _newSegments [ $ newSegment -> getName ( ) ] = $ newSegment ; } $ this -> _currentSegment = null ; } $ this -> _updateSegments ( ) ; }
Commit current changes
59,192
public function optimize ( ) { if ( Zend_Search_Lucene_LockManager :: obtainOptimizationLock ( $ this -> _directory ) === false ) { return false ; } $ this -> _updateSegments ( ) ; $ this -> _mergeSegments ( $ this -> _segmentInfos ) ; Zend_Search_Lucene_LockManager :: releaseOptimizationLock ( $ this -> _directory ) ; return true ; }
Merges all segments together into new one
59,193
private function _newSegmentName ( ) { Zend_Search_Lucene_LockManager :: obtainWriteLock ( $ this -> _directory ) ; $ generation = Zend_Search_Lucene :: getActualGeneration ( $ this -> _directory ) ; $ segmentsFile = $ this -> _directory -> getFileObject ( Zend_Search_Lucene :: getSegmentFileName ( $ generation ) , false ) ; $ segmentsFile -> seek ( 12 ) ; $ segmentNameCounter = $ segmentsFile -> readInt ( ) ; $ segmentsFile -> seek ( 12 ) ; $ segmentsFile -> writeInt ( $ segmentNameCounter + 1 ) ; $ segmentsFile -> flush ( ) ; Zend_Search_Lucene_LockManager :: releaseWriteLock ( $ this -> _directory ) ; return '_' . base_convert ( $ segmentNameCounter , 10 , 36 ) ; }
Get name for new segment
59,194
public function using ( $ name ) { if ( isset ( $ this -> providers [ $ name ] ) ) { $ this -> provider = $ this -> providers [ $ name ] ; } return $ this ; }
Sets the provider to use .
59,195
public function getProvider ( ) { if ( null === $ this -> provider ) { if ( 0 === count ( $ this -> providers ) ) { throw new \ RuntimeException ( 'No provider registered.' ) ; } else { $ this -> provider = $ this -> providers [ key ( $ this -> providers ) ] ; } } return $ this -> provider ; }
Returns the provider to use .
59,196
public function getField ( $ fieldName ) { if ( ! array_key_exists ( $ fieldName , $ this -> _fields ) ) { include_once 'Zend/Search/Lucene/Exception.php' ; throw new Zend_Search_Lucene_Exception ( "Field name \"$fieldName\" not found in document." ) ; } return $ this -> _fields [ $ fieldName ] ; }
Returns Zend_Search_Lucene_Field object for a named field in this document .
59,197
public function addValueSortToCollection ( $ collection , $ dir = 'asc' ) { $ attributeCode = $ this -> getAttribute ( ) -> getAttributeCode ( ) ; $ attributeId = $ this -> getAttribute ( ) -> getId ( ) ; $ attributeTable = $ this -> getAttribute ( ) -> getBackend ( ) -> getTable ( ) ; $ linkField = $ this -> getAttribute ( ) -> getEntity ( ) -> getLinkField ( ) ; if ( $ this -> getAttribute ( ) -> isScopeGlobal ( ) ) { $ tableName = $ attributeCode . '_t' ; $ collection -> getSelect ( ) -> joinLeft ( [ $ tableName => $ attributeTable ] , "e.{$linkField}={$tableName}.{$linkField}" . " AND {$tableName}.attribute_id='{$attributeId}'" . " AND {$tableName}.store_id='0'" , [ ] ) ; $ valueExpr = $ tableName . '.value' ; } else { $ valueTable1 = $ attributeCode . '_t1' ; $ valueTable2 = $ attributeCode . '_t2' ; $ collection -> getSelect ( ) -> joinLeft ( [ $ valueTable1 => $ attributeTable ] , "e.{$linkField}={$valueTable1}.{$linkField}" . " AND {$valueTable1}.attribute_id='{$attributeId}'" . " AND {$valueTable1}.store_id='0'" , [ ] ) -> joinLeft ( [ $ valueTable2 => $ attributeTable ] , "e.{$linkField}={$valueTable2}.{$linkField}" . " AND {$valueTable2}.attribute_id='{$attributeId}'" . " AND {$valueTable2}.store_id='{$collection->getStoreId()}'" , [ ] ) ; $ valueExpr = $ collection -> getConnection ( ) -> getCheckSql ( $ valueTable2 . '.value_id > 0' , $ valueTable2 . '.value' , $ valueTable1 . '.value' ) ; } $ collection -> getSelect ( ) -> order ( $ valueExpr . ' ' . $ dir ) ; return $ this ; }
Add Value Sort To Collection Select
59,198
public function getTitle ( ) { if ( ! $ this -> title ) { $ this -> title = DocumentationHelper :: clean_page_name ( $ this -> key ) ; } return $ this -> title ; }
Get the title of this module .
59,199
public function Link ( $ short = false ) { if ( $ this -> getIsDefaultEntity ( ) ) { $ base = Controller :: join_links ( Director :: baseURL ( ) , Config :: inst ( ) -> get ( 'DocumentationViewer' , 'link_base' ) , $ this -> getLanguage ( ) , '/' ) ; } else { $ base = Controller :: join_links ( Director :: baseURL ( ) , Config :: inst ( ) -> get ( 'DocumentationViewer' , 'link_base' ) , $ this -> getLanguage ( ) , $ this -> getKey ( ) , '/' ) ; } if ( $ short && $ this -> stable ) { return $ base ; } return Controller :: join_links ( $ base , $ this -> getVersion ( ) , '/' ) ; }
Returns the web accessible link to this entity .