Jump to content

Search the Community

Showing results for tags 'recursive'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 3 results

  1. Hello, Here is my code: <?php require 'vendor/autoload.php'; $client = new Elasticsearch/Client(); $root = realpath('~/elkdata/for_elk_test_2014_11_24/Agencies'); $iter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD); $paths = array($root); foreach ($iter as $path => $dir) { if ($dir -> isDir()) { $paths[] = $path; } } //Create the index and mappings $mapping['index'] = 'rvuehistoricaldocuments2009-2013'; //mapping code $mapping['body'] = array ( 'mappings' => array ( 'documents' => array ( '_source' => array ( 'enabled' => true ), 'properties' => array( 'doc_name' => array( 'type' => 'string', 'analyzer' => 'standard' ), 'description' => array( 'type' => 'string' ) ) ) ) ); $client ->indices()->create($mapping) //Now index the documents for ($i = 0; $i <= count($paths); $i++) { $params ['body'][] = array( 'index' => array( 'type' => 'documents' 'body' => array( 'foo' => 'bar' //Document body goes here ) ) ); //Every 1000 documents stop and send the bulk request. if($1 % 1000) { $responses = $client->bulk($params); // erase the old bulk request $params = array(); // unset the bulk response when you are done to save memory unset($responses); } } ?> I am looking to index a large amount of documents using elastic search and php. I have a very complex directory filled with other directories that i need to index into an array. I wanted to see if my code looked right, and if not what am I doing wrong? Thanks, Austin Harmon
  2. Hi, I am converting an adjacency table to a xml with this code (coming from phpfreaks, thank you Barand!) <?php $data = array( 1 => 0, 2 => 1, 3 => 1, 4 => 2, 5 => 3, 6 => 5 ); echo "<?xml version='1.0' encoding='iso-8859-1'?>\n"; echo "<tree id='0'>\n"; tree(0); echo "</tree>\n"; function tree ($parent, $level=0) { global $data; $children = array_keys($data, $parent); if ($children) foreach ($children as $kid) { $indent = str_repeat("\t", $level+1); echo "$indent<item text='$kid' id='$kid'>\n"; tree($kid, $level+1); echo "$indent</item>\n"; } } ?> Returning <?xml version='1.0' encoding='iso-8859-1'?> <tree id='0'> <item text='1' id='1'> <item text='2' id='2'> <item text='4' id='4'> </item> </item> <item text='3' id='3'> <item text='5' id='5'> <item text='6' id='6'> </item> </item> </item> </item> </tree> Which is inappropriately formatted for my purpose. I would need: <?xml version='1.0' encoding='iso-8859-1'?> <tree id='0'> <item text='1' id='1'> <item text='2' id='2'> <item text='4' id='4'/> </item> <item text='3' id='3'> <item text='5' id='5'> <item text='6' id='6'/> </item> </item> </item> </tree> All nodes with children should end with </item>, leafs without end with />). I included an else-statement, after the foreach, but that obviously only doubles the leafs. else { $leaf = $parent; $indent = str_repeat("\t", $level+1); echo "$indent<item text='$leaf' id='$leaf'/>\n"; } Including further if-statements, left me with a completely screwed xml. Now I run out of ideas how to check for leafs/children and handle them appropriately. Any help ist appreciated!
  3. HELP! HELP!. I CAN'T EAT IF I DON'T GET THIS CODE. By my previous understanding, due to the order of execution of recursive functions, when it is called it does not go on to execute the remaining part of the code but creates a new instance of the function in memory, the execution of the rest part of the function occurs at the last instance when the base case is fulfilled. In this light the code snippet $row++; } // call display on each of this node's children // note a node will only have children in its list if expanded $num_children = sizeof($this->m_childlist); for($i = 0; $i<$num_children; $i++) { $row = $this->m_childlist[$i]->display($row, $sublist); // Note that this is the recursive call, meaning this call to display() function is inside the display function as can be seen from the main code below } return $row; } will create several instances of the display() function which display the tree, but only return $row at last instance which in turn returns $row to the instance that calls it until it get to the first. But the writer of the book says the snippet of code sends $row from one call to the next and then the next. How is this possible when the return of $row occurs after the call to the recursive function. What am I getting wrong? The entire class code is shown below: <?php // functions for loading, contructing and // displaying the tree are in this file class treenode { // each node in the tree has member variables containing // all the data for a post except the body of the message var $m_postid; var $m_title; var $m_poster; var $m_posted; var $m_children; var $m_childlist; var $m_depth; function treenode($postid, $title, $poster, $posted, $children, $expand, $depth, $expanded, $sublist) { // the constructor sets up the member variables, but more // importantly recursively creates lower parts of the tree $this->m_postid = $postid; $this->m_title = $title; $this->m_poster = $poster; $this->m_posted = $posted; $this->m_children =$children; $this->m_childlist = array(); $this->m_depth = $depth; // we only care what is below this node if it // has children and is marked to be expanded // sublists are always expanded if(($sublist||$expand) && $children) { $conn = db_connect(); $query = "select * from header where parent = $postid order by posted"; $result = mysql_query($query); for ($count=0; $row = @mysql_fetch_array($result); $count++) { if($sublist||$expanded[ $row['postid'] ] == true) $expand = true; else $expand = false; $this->m_childlist[$count]= new treenode($row['postid'],$row['title'], $row['poster'],$row['posted'], $row['children'], $expand, $depth+1, $expanded, $sublist); } } } function display($row, $sublist = false) { // as this is an object, it is responsible for displaying itself // $row tells us what row of the display we are up to // so we know what color it should be // $sublist tells us whether we are on the main page // or the message page. Message pages should have // $sublist = true. // On a sublist, all messages are expanded and there are // no "+" or "-" symbols. // if this is the empty root node skip displaying if($this->m_depth>-1) { //color alternate rows echo '<tr><td bgcolor="'; if ($row%2) echo '#cccccc">'; else echo '#ffffff">'; // indent replies to the depth of nesting for($i = 0; $i<$this->m_depth; $i++) { echo '<img src="images/spacer.gif" height="22" width="22" alt="" valign="bottom">'; } // display + or - or a spacer if ( !$sublist && $this->m_children && sizeof($this->m_childlist)) // we're on the main page, have some children, and they're expanded { // we are expanded - offer button to collapse echo '<a href="index.php?collapse='. $this->m_postid.'#'.$this->m_postid.'" ><img src="images/minus.gif" valign="bottom" height="22" width="22" alt="Collapse Thread" border="0"></a>'; } else if(!$sublist && $this->m_children) { // we are collapsed - offer button to expand echo '<a href="index.php?expand='. $this->m_postid.'#'.$this->m_postid.'"><img src="images/plus.gif" height="22" width="22" alt="Expand Thread" border="0"></a>'; } else { // we have no children, or are in a sublist, do not give button echo '<img src="images/spacer.gif" height="22" width="22" alt="" valign="bottom">'; } echo " <a name = $this->m_postid ><a href = 'view_post.php?postid=$this->m_postid'>$this->m_title - $this->m_poster - ".reformat_date($this->m_posted).'</a>'; echo '</td></tr>'; // increment row counter to alternate colors $row++; } // call display on each of this node's children // note a node will only have children in its list if expanded $num_children = sizeof($this->m_childlist); for($i = 0; $i<$num_children; $i++) { $row = $this->m_childlist[$i]->display($row, $sublist); } return $row; } }; ?>lt;
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.