/** * Parses the $query into an SearchQuery Object, and send it to the * SearchManager Obect, which prepare and execute the search, and * returns the results. * * Example of returned value: * <pre> * array( * 'category' => array ( * 'amount' => integer * 'results' => array ('type' => (string) $markup->type, 'path' => (string) $markup->path, 'name' => (string) $markup->name, 'size' => (string) $markup->size) * ) * ) * </pre> * * FIXME: to be fixed using a generic Searchresult object. * * * @see SearchQuery * @see SearchManager * * @param string $query * @return array $results */ public function search($query) { $searchQuery = new SearchQuery(); $searchQuery->parseQuery($query); $searchManager = new SearchManager(); return $searchManager->search($searchQuery); }
public function testSearchFileRecollPlugin() { $query = "filename:*foo* filename:*lol* type:pdf OR type:xml AND ext:html OR ext:xml"; $searchQuery = new SearchQuery(); $searchQuery->setQueryString($this->query); $searchQuery->setQueryTokens($this->tokens); // we want to check if the SearchManager is well working, // means if it is able to load all the required library. $searchManager = new SearchManager(); $searchManager->search($searchQuery); // we also want to check if the parsing process // gives us a well formatted string. $recollPlugin = new SearchFileRecollPlugin(); $recollPlugin->search($searchQuery); $this->assertEquals($query, $recollPlugin->getSearchQuery()); // FileSearchListener::fileCreated() $this->assertFalse(is_file($this->fixture_file_path)); $this->assertTrue($this->fixture_file->createNewFile()); $this->assertTrue(is_file($this->fixture_file_path)); $searchQuery->setQueryString('testFile'); $searchQuery->setQueryTokens(null); $recollPlugin->resetSearchQuery(); $recollPlugin->search($searchQuery); $results = $recollPlugin->getResults(); $this->assertEquals($results[0]['name'], 'testFile.txt'); // FileSearchListener::fileDeleted() $this->assertTrue(is_file($this->fixture_file_path)); $this->assertTrue($this->fixture_file->delete()); $this->assertFalse(is_file($this->fixture_file_path)); $searchQuery->setQueryString('testFile'); $searchQuery->setQueryTokens(null); $recollPlugin->resetSearchQuery(); $recollPlugin->search($searchQuery); $results = $recollPlugin->getResults(); $this->assertTrue(empty($results)); // FileSearchListener::directoryCreated() $this->assertFalse(is_dir($this->fixture_dir_path)); $this->assertTrue($this->fixture_dir->mkdir()); $this->assertTrue(is_dir($this->fixture_dir_path)); $searchQuery->setQueryString('testDir'); $searchQuery->setQueryTokens(null); $recollPlugin->resetSearchQuery(); $recollPlugin->search($searchQuery); $results = $recollPlugin->getResults(); $this->assertEquals($results[0]['name'], 'testDir'); // FileSearchListener::fileMoved() $this->assertFalse(is_file($this->fixture_file_path)); $this->assertTrue($this->fixture_file->createNewFile()); $this->assertTrue(is_file($this->fixture_file_path)); $newFile = FSI::getFile('home://~fakeUser/testDir/testFile2.txt'); $this->assertTrue($this->fixture_file->moveTo($newFile)); $this->assertTrue(is_file($this->fixture_newFile_path)); $this->assertFalse(is_file($this->fixture_file_path)); $searchQuery->setQueryString('testFile2'); $searchQuery->setQueryTokens(null); $recollPlugin->resetSearchQuery(); $recollPlugin->search($searchQuery); $results = $recollPlugin->getResults(); $this->assertEquals($results[0]['name'], 'testFile2.txt'); $searchQuery->setQueryString('testFile'); $searchQuery->setQueryTokens(null); $recollPlugin->resetSearchQuery(); $recollPlugin->search($searchQuery); $results = $recollPlugin->getResults(); $this->assertNotEquals($results[0]['name'], 'testFile.txt'); $newFile->delete(); // FileSearchListener::fileRenamed() $this->assertFalse(is_file($this->fixture_file_path)); $this->assertTrue($this->fixture_file->createNewFile()); $this->assertTrue(is_file($this->fixture_file_path)); $this->assertTrue($this->fixture_file->renameTo('testFileRenamed.txt')); $searchQuery->setQueryString('testFile'); $searchQuery->setQueryTokens(null); $recollPlugin->resetSearchQuery(); $recollPlugin->search($searchQuery); $results = $recollPlugin->getResults(); $this->assertNotEquals($results[0]['name'], 'testFile.txt'); $this->assertEquals($results[0]['name'], 'testFileRenamed.txt'); // FileSearchListener::fileWritten() $this->fixture_file->putContents('take it easy!'); // TODO: check if the content's file is up to date. }