Chapter 17: Searching 274 ) ) File searches As stated before Doctrine_Search can also be used for searching files. Lets say we have a directory which we want to be searchable. First we need to create an instance of Doctrine_Search_File which is a child of Doctrine_Search providing some extra functionality needed for the file searches. Listing 17-23 // test.php // ... $search = new Doctrine_Search_File(); Second thing to do is to generate the index table. By default Doctrine names the database index class as FileIndex. Lets check the SQL that is generated by the above models created: Listing 17-24 // test.php Listing 17-25 // ... $sql = Doctrine_Core::generateSqlFromArray(array('FileIndex')); The above code would output the following SQL query: CREATE TABLE file_index (url VARCHAR(255), keyword VARCHAR(200), field VARCHAR(50), position BIGINT, PRIMARY KEY(url, keyword, field, position)) ENGINE = INNODB You can create the actual table in the database by using the Doctrine_Core::createTablesFromArray() method: Listing 17-26 // test.php // ... Doctrine_Core::createTablesFromArray(array('FileIndex')); Now we can start using the file searcher. In this example lets just index the models directory: Listing 17-27 // test.php // ... $search->indexDirectory('models'); The indexDirectory() iterates recursively through given directory and analyzes all files within it updating the index table as necessary. Finally we can start searching for pieces of text within the indexed files: ----------------- Brought to you by
Chapter 17: Searching 275 // test.php Listing 17-28 // ... $results = $search->search('hasColumn'); print_r($results); The above example would produce the following output: $ php test.php Array (  => Array ( [relevance] => 2 [url] => models/generated/BaseNewsItem.php ) Listing 17-29 ) Conclusion Now that we have learned all about the Searchable behavior we are ready to learn in more detail about the NestedSet behavior in the Hierarchical Data (page 276) chapter. The NestedSet is a large topic like the Searchable behavior so it got its own dedicated chapter as well. ----------------- Brought to you by
Test4Direct provides latest PDF questions of IBM C2090-610 exam. You have an opportunity to pass the IBM C2090-610 exam in one go. Test4Direct is most accurate source to prepare IBM C2090-610 exam as your success will become site’s responsibility after purchasing C2090-610 exam product. There are also lots of discounts and promotion offers that you can avail. Let’s try a free demo http://www.test4direct.com/C2090-610.html
The comprehensive data will ensure that marketers can save on their marketing costs by using a single database for all their marketing purposes. With our Mailing Lists of Medical Associates you can expand your business, gain new customers, networking with associate medical directors, reduce sales cycle and improve sales, revenue and ROI.