Yahoo! Boss search APIThe Yahoo! Developer Network blog just published a blog post with new Boss features: Yahoo! Search BOSS Releases Key Terms. There are a few key details in this article.

  • Key terms are now available: Each result now includes the keyterms Yahoo’s search index has assigned to the web page. This is the same information Yahoo! uses for search suggestions. I was trying to recreate this by using key term extraction in Yahoo! Pipes. But this would have involved multiple requests and slowed the page down. Boss’s inclusion of keyterms opens a whole new world of semantic search options. I’m using them to display related results on V3GGIE.
  • Extended language/region support: I was in Romania a couple weeks ago discussing Yahoo! Boss with some students in Bucharest. I noticed we didn’t support the Romanian language in Boss. I was able to send a few emails asking for support and voila, the Yahoo! Boss has not only added Romanian, but also Turkish and Hebrew! That is some fast turn around and shows their commitment to the users.
  • Boss made easier: Christian Heilmann has been creating Boss plug-n-play projects. You can get a JavaScript Boss badge, grab all the keyterms in one arrray, and recently a build your own site search in 3 easy steps lesson.
  • The article also has a link to a new site I’m developing: Tartin3. This is still in the development stages and is a prototype for a much larger site InsiderFood.com. I’m hoping to take the covers off Insider Food within the next couple weeks.Insider Food is now Live - but in Beta mode as I fix bugs and make enhance the search logic

Disclaimer: I work for Yahoo! but I’m not on the Yahoo! Boss team. I’m their “customer”, as I use Boss for multiple projects outside Yahoo!. I also am a member of the International Yahoo! Developer Network, which allows me to demonstrate and teach some of the Yahoo! API’s and services.

Related articles by Zemanta

The Yahoo! Developer Network blog just published an article I wrote about Yahoo! BOSS. It discusses how to use the search filters and query attributes with the BOSS API.

I’ve used these methods on V3GGIE.com, a vegetarian search engine and will be launching a new niche search engine in the next few weeks.
Yahoo! BOSS plus your ideas make a unique search experience

Related articles by Zemanta

During the fog of a summer cold and pressing deadlines… I gave a presentation today at the Yahoo! Front End Engineering Summit about CSS3 Attribute Selectors. The presentation briefly touched on some of my previous posts on this site as well as a few new concepts and ideas.

Here is the full presentation (HTML): CSS3 Attribute Lovin’. Feel free to copy, share, or do whatever you like with it.

I’ll post some more information on the new topics soon. Right now I’ve got to get back to my massive list of outstanding bugs on my project.

Search pagination exampleYahoo’s BOSS search API makes it easy for you to create a customized search engine. Yahoo! also has a Design Pattern lLibrary to save time designing your pages. They’ve put a lot of effort into creating the best user experience for search pagination.

Pagination guidelines

Here’s a sample of the Design Library’s ideas for search pagination.

  • Display the navigation controls as a row of links.
  • Present links in the following order: ‘Prev’, page links, ‘Next’.
  • Display a left arrow after the label ‘Prev’.
  • Display a right arrow before the label ‘Next’.
  • Make the arrow(s) clickable.
  • The page links should contain a maximum set of 10 page links. If fewer pages of results exist, only show page links for the available pages.
  • When on pages 1-6, the page links should always start at ‘1′.

Search Pagination

The rationale for these rules is also interesting:

  • Displaying arrow graphics helps differentiate the links and provides larger click targets.
  • Disabled controls add little value in this context since
    • These links often appear blow the fold.
    • The first page of results makes up the vast majority of pageviews. Displaying a disabled “previous” control on all of these is of little added value.
    • Although a “First” link has value, it competes with the functionality presented in the random-access links.
    • The “Last” link is of little value as the results are sorted by relevance. This is is also problematic since the total number of results (and therefore, the last result) may not be known.

Add this pagination style to your search engine

See the final result on V3GGIE.com: Vegetarian Enchiladas Recipes

Most PHP pagination tutorials assume you are pulling content from a database. Ascanio Colonna created a good tutorial on building pagination with PHP that is agnostic to the data source. I’ve taken his code and modified it to match the Yahoo Design Pattern. I’ve also added the suggested YUI Module markup to stay consistent with the YUI Grids and any future YUI javascript.

The pagination.php file includes a function that creates the module. You’ll need to call this function from your results page with a series of parameters. These are easy to populate from the BOSS interface. It’s worth noting that I am ignoring the BOSS next/last page nodes in the web service and prefer to build my own urls.

The Pagination Code

Lets’ start by looking at the code inside your results.php file. This will call the pagination function and pass the desired parameters.

  1. if(!empty($searchQuery))
  2.   {
  3.         require ‘/include/pagination.php’;
  4.   if(isset($_REQUEST[‘page’])) {
  5.         $page = $_REQUEST[‘page’];
  6.         } else  {
  7.         $page = ‘1′;
  8.         }
  9.         $limit = $count;
  10.         $targetpage = ‘results.php’;
  11.         $pagestring = ‘?page=’;
  12.         $summary_name = ‘articles’;
  13.         $placement = ’summary’
  14.         // start pagination     
  15.           echo getPaginationString($page, $totalhits, $limit$targetpage, $pagestring, $summary_name, $placement);        
  16.  }

Here’s what you are working with:

require ‘/include/pagination.php’
Where does the pagination file sit on your server
$page logic
First look to see if there is page=x in the url. If so, $page = x, if not, you are on page 1.
$limit
How many results will appear on the page
$targetpage
what is the name of your results page? index.php, results.php?
$pagestring
I tried to minimize this to ?p= but couldn’t track down why it didn’t work. I’ve left it at the default ?page=…
$summary_name
This is what appears in the text “xxx (summary_name) results. This is not used in the Yahoo Design Library
$placement
You’ll probably want to use summary. This function also allows “footer” for a simplified output
echo getPaginationString(…)
Send the information to the function and display the results in the page.

Important Update!

The original code I posted had a serious security flaw. You should never output user’s input directly into your page. I had something like this href=”?query=$_REQUEST['query']“. This allows all sorts of Cross Site Scripting attacks. You must urlencode any text that comes from a user. This is safe: urlencode($_REQUEST['query']).

I apologize if anyone has used this code, as I wrote it on their site. They should immediately update the logic. -Ted


The pagination function

I have streamlined the original code from Asconio, as he was tying into pre-existing facebook styles. This code is for your unique web site.

Results Page

“;

if($lastpage > 1) // Paginator page selection is drawn only if more than 1 pages are there
{

$pagination .= ‘

    ‘;

    // First page selector
    if ($page > 2)

    // Previous page selector
    if ($page > 1)
    $pagination .= “

  • Prev
  • “;

    // Page selectors
    if ($page < 4) //not enough pages to bother
    {
    for ($counter = 1; $counter <= min(5, $lastpage); $counter++)
    {
    if ($counter == $page)
    $pagination .= “

  • $counter
  • “;
    else
    $pagination .= “

  • $counter
  • “;
    }
    }
    elseif ($page > $lastpage - 3)
    {
    for($counter = $lastpage - min(5, $lastpage); $counter <= $lastpage; $counter++)
    {
    if ($counter == $page)
    $pagination .= “

  • $counter
  • “;
    else
    $pagination .= “

  • $counter
  • “;
    }
    }
    else
    {
    for($counter = $page - 2; $counter <= $page + 2; $counter++)
    {
    if ($counter == $page)
    $pagination .= “

  • $counter
  • “;
    else
    $pagination .= “

  • $counter
  • “;
    }
    }

    //next button
    if ($page < $lastpage)
    $pagination .= “

  • Next
  • “;

    //last button
    if ($page < $lastpage - 1)

    $pagination .= ‘

‘;
}

$pagination = “

“;

return $pagination;

} ?>

I’ve added a few classes to the final output. The previous and next links have class”nextlink” or class=”prevlink”. The current page has the number within a strong tag with class=”current”. Finally, the parent module has class=”pagelinks mod”. This makes it pretty simple to style

Pagination CSS

I’m using the YUI Sam Skin sprite for the tabbed search box. I’ve added a couple arrows to this sprite for my search pagination.

  1. .pagelinks {
  2. text-align:center;
  3. border:1px solid #ccc;
  4. padding:5px 0 0 0;
  5. }
  6. .pagelinks ul li {
  7. display:inline;
  8. }
  9. .pagelinks ul a, .pagelinks ul strong {
  10. display;block; padding:3px 5px;
  11. }
  12. .pagelinks ul strong {
  13. background-color:green; color:#fff;
  14. }
  15. .pagelinks li.nextlink a,.pagelinks li.prevlink {
  16. padding-right:15px; font-size:120%; font-wieght:bold; background:url(/images/sprite.png) no-repeat 100% -1943px;
  17. }
  18. .pagelinks li.prevlink a {
  19. padding-right:0px; padding-left:15px; background-position:0 -1973px;
  20. }

I am also not a PHP expert and welcome suggestions on improving the code.

Related articles by Zemanta

Yahoo! makes it easy to create an accessible, handsome tabbed interface. I used their Tab View library to create the tabbed search form for V3GGIE.com. While Tab View can create the tabbed content dynamically, I’m using it to hide/show hard-coded individual forms.

Update: I’ve removed the tabbed interface from V3GGIE.com. This particular use of the tabbed module seemed to have created some confusion in users. The approach is still valid, just not the way I originally implemented it. See the tabbed search form on V3GGIE.com

Step 1. Create the basic HTML code.

The tabbed code is a simple pattern:

  1. Start with a parent div and give it an id and class=”yui-navset”.
    1. <div class=“yui-g yui-navset” id=“v3search”></div></li>
  2. Create an unordered list inside this div with class=”yui-nav”.
  3. Each list includes a deep link to a corresponding div that is also a child of the parent div. The link text in an em tag.
    1. <li><a href=“#vesearch”><em>V3GGIE Search</em></a></li>
  4. Create a div with class=”yui-content” and create a set of content containing divs. Each div has an id.
    1. <div class=“yui-content”>
    2.                         <div id=“vesearch”></div>
    3.                         <div id=“losearch”></div>
    4.                         <div id=“rcsearch”></div>
    5.                 </div>
  5. Insert the Tabview CSS at the top of the page, the Tab View JS at the bottom of the page, create a small js that instantiates the tab-view module.
  6. For easier styling, use the sam_skin CSS package and add class=”yui-skin-sam” to the body.

Step 2. Use PHP to make it more interesting

Each page calls this chunk of code to insert the tabbed form, it also sets a variable ($selected), determining which tab is selected on page load. I’m also inserting the last search query into the text input to make it easier on the user. This is easily done by grabbing the query from the Request object.

The finished code:

  1. <div class=“yui-g yui-navset” id=“v3search”>
  2. <!–<?php print $selected ;?>–>
  3.         <ul class=“yui-nav”>
  4.         <li> &gt;<a href=“#vesearch”><em>V3GGIE Search</em></a></li>
  5.         <li> &gt;<a href=“#losearch”><em>Local</em></a></li>
  6.         <li> &gt;<a href=“#rcsearch”><em>Recipes</em></a></li>
  7.         <li> &gt;<a href=“#nesearch”><em>News</em></a></li>
  8.         <li> &gt;<a href=“#blsearch”><em>Blogs</em></a></li>
  9.         </ul>
  10.         <div class=“yui-content”>
  11.         <div id=“vesearch”>
  12.    <form name=“b” action=“/results.php” method=“get”>
  13.    <label for=“vquery”>Search for Vegetarian information
  14.    <input id=“vquery” size=“50″ name=“query” value=“&lt;?php print $inputtext; ?&gt;” type=“text”></label>
  15.       <input class=“searchsubmit” value=“Search” type=“submit”
  16.    </form>
  17.    </div>
  18.         <div id=“losearch”>
  19.    <form name=“b” action=“/local/results.php” method=“get”>
  20.    <label for=“lquery”>Where do you want to eat?
  21.    <input size=“50″ id=“lquery” name=“query” value=“&lt;?php print $inputtext; ?&gt;” type=“text”></label>
  22.       <input class=“searchsubmit” value=“Search” type=“submit”
  23.         <p>Try “San Francisco Pho”, “Paris Fromage”,  or “92104 tofu”</p>
  24.    </form>
  25.    </div>
  26.         <div id=“rcsearch”>
  27.    <form name=“b” action=“/recipes/results.php” method=“get”>
  28.    <label for=“rquery”>What are you hungry for?
  29.    <input size=“50″ name=“query” id=“rquery” value=“&lt;?php print $inputtext; ?&gt;” type=“text”></label>
  30.       <input class=“searchsubmit” value=“Search” type=“submit”
  31.           <p>Try “corn chowder” or “vegan pizza”</p>
  32.    </form>
  33.    </div>
  34.         <div id=“nesearch”>
  35.    <form name=“b” action=“/news/results.php” method=“get”>
  36.    <label for=“nquery”>Get Vegetarian news?
  37.    <input size=“50″ id=“nquery” name=“query” value=“&lt;?php print $inputtext; ?&gt;” type=“text”></label>
  38.       <input class=“searchsubmit” value=“Search” type=“submit”>
  39.           
  40.           <p>Try “Vegetarian Chinese Olympics”</p>
  41.    </form>
  42.    </div>
  43.         <div id=“blsearch”>
  44.    <form name=“b” action=“/blogs/results.php” method=“get”>
  45.    <label for=“bquery”>What are the blogs saying?
  46.    <input size=“50″ id=“bquery” name=“query” value=“&lt;?php print $inputtext; ?&gt;” type=“text”></label>
  47.       <input class=“searchsubmit” value=“Search” type=“submit”
  48.           
  49.           <p> Try a subject: “PETA”, “Tempeh”, or “Paris -Hilton Vegetarian”</p>
  50.    </form>
  51.    </div>
  52.    </div>
  53.    </div>

View the source as a text file

The Final Product

We now have a tabbed module that allows the user to find recipes, news, blogs, and local restaurants from any page. This is an easy introduction to the YUI libraries. However, I came across the following surprises:

  • The order of the tabs must match the order of the target divs. I moved my tabs around and discovered they were toggling the wrong forms.
  • The links that generate the tabs need to have em tags surrounding the text
  • You’ll need to download the entire YUI package to gain access to the CSS and sprites needed for the library. The examples on the YUI site assume relative links to files, you will either need to duplicate that file structure or upload the skin’s sprite and change the CSS accordingly.



About

Advanced CSS resource guides.

This site features helpful hints, in-depth exercises, and book reviews. It's the site that I'd want to have handy to remember how to do something and what to look out for.

Please note: In the process of copying content from one site to another, some of the coding examples have been mangled. If you see a page that needs attention, please leave a comment to let me know. I am actively updating the pages to make sure they are accurate.