Menu

Difficulty with the SEARCH Feature

Gary
2012-12-10
2012-12-10
  • Gary

    Gary - 2012-12-10

    As I am only vaguely familiar with PHP, I attempted to simply replace the existing XMl portion of the example file with the video and audio content of my own. I placed each video item under 'video results' and audio items under 'audio results.

    My result was that no matter what I type in the Search, the results are EVERY Video and Audio item in my inventory. LOL

    Any help would be greatly appreciated. An Example would be Fantastic!!
    Many Thanks!

     
  • kavulix

    kavulix - 2012-12-10

    The search script doesn't have to be programmed in php. You could use perl or python or any server-side scripting language. The search script included in the openrokn package is not a functioning script. It was only included to show which parameters (?keywords=the+query) are used by openrokn when a search is performed.

    The meta-data (title, description, bitrate, length, etc) for video and audio files is typically stored in a database. If your media is already indexed in a db then coding the search script should be as simple as making a sql query. If you haven't yet indexed your media in a db then I suppose you could search the xml files but it won't be as efficient or as simple as making a single sql query. You can probably find a free php script on the internet to perform the xml search but you'll need to modify it to output the results in orml.

    If you've already indexed your media then I'd be happy to post a complete php example if you'll post an example of your sql table structure (i.e., table names and column names).

    header("Content-type: application/xml");
    $xml = new DOMDocument("1.0", "UTF-8");
    $xml->formatOutput = true; //this will add line breaks and indentation to output
    $orml = $xml->createElement("orml");
    $orml->setAttribute("version", "1.2");
    $orml->setAttribute("xmlns", "http://sourceforge.net/p/openrokn/home/ORML");
    $xml->appendChild($orml);
    $feed = $xml->createElement("channel");
    $orml->appendChild($feed);
    $poster = $xml->createElement("item");
    $poster->setAttribute("type", "poster");
    $poster->setAttribute("style", "flat-episodic-16x9");
    $poster->setAttribute("title", $title);
    $feed->appendChild($poster);
    // connect to sql server
    $link = mysql_connect($SQL_HOST, $SQL_USER, $SQL_PASS) or die($xml->saveXML());
    // select mysql db
    mysql_select_db($SQL_DBNAME) or die($xml->saveXML());
    $query = "SELECT * FROM `media` WHERE `title` LIKE '%$keywords%' ORDER BY `title` ASC LIMIT 30";
    // perform the sql query
    $result = mysql_query($query) or die($xml->saveXML());
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        // create orml code here for each search result
        $item = $xml->createElement("item");
        $item->setAttribute("type", $row['type']);
        $item->setAttribute("title", $row['title']);
        $item->setAttribute("url", "http://yoursite.com/" . $row['filename']);
        $poster->appendChild($item);
    }
    mysql_free_result($result);
    mysql_close($link);
    // output orml feed/search results
    echo $xml->saveXML();
    
     

    Last edit: kavulix 2012-12-10

Log in to post a comment.