Tuesday, January 31, 2012

Comparison matrix of search methods in Drupal

Comparison matrix of search methods in Drupal:

Here is a summary of the search methods presented in this article -- see sections below for more detail.
MethodUsed forStrengthsWeaknesses
Core "Search" module Site-wide Boolean keyword search of Nodes and User names
  • Easy to deploy
  • Core Drupal module (officially maintained)
  • Uses indexing (fairly efficient)
  • Displays results appropriate to permissions of searcher
  • Includes minimal field-based search in Advanced search of Node content
  • Can configure ordering of search results
  • Full hook API
  • =========
  • Indexes only Node content, not other pages on site
  • Indexes all Nodes, whether you want it to or not
  • Requires exact full-word keyword match for Nodes (Stemming modules can overcome this), but allows substring match for Users
  • Doesn't take into account how Theme renders Node
  • =======
Contributed "Search by Page" module Site-wide Boolean keyword search of pages
  • Easy to deploy
  • Flexible - indexes what you want it to index
  • Relies on core Search module for indexing and searching technology
  • Displays results appropriate to permissions of searcher
  • Takes into account how Theme renders page
  • Full hook API
  • =========
  • Requires exact full-word keyword match (Stemming modules can overcome this)
  • No field-based or faceted searching capabilities
  • No capability for influencing ordering of search results
  • ========
Third-party crawler-based search engines (e.g. Google) Site-wide Boolean keyword search of pages
  • Easy to deploy
  • Indexes content as rendered by your theme
  • You don't have to maintain the index
  • Some control over what content is indexed
  • Good substring matching capabilities
  • ==========
  • Searches only publicly-available content
  • Headers, sidebars, etc. are indexed along with content, which could lead to false positive matches
  • Little or no control over when your site is indexed, order of search results, or how results are displayed
  • No faceted or field-based searching
  • =========
Search appliances Site-wide Boolean, keyword, and/or faceted search of nodes or page content, depending on appliance
  • Efficient, so good for high-volume sites
  • Many appliances offer faceted searching
  • ========
  • More difficult to deploy than other methods
  • ==========
Contributed "Faceted Search" module Faceted search of one or more Node types
  • Faceted searching
  • Easy to set up
  • Flexible
  • =========
  • Probably not too useful for site-wide searching, for most sites
  • ==========
Contributed "Views" module with exposed filters Field-based search of Nodes, Users, Files, or Comments
  • Field-based searching
  • Easy to set up
  • Flexible
  • =========
  • Probably not too useful for full-site searching, for most sites
  • ==========

Thursday, January 19, 2012

Using taxonomy_get_tree,taxonomy_get_children in Drupal

Using taxonomy_get_tree in Drupal;

@param $vid
 *   Which vocabulary to generate the tree for.
 *
 * @param $parent
 *   The term ID under which to generate the tree. If 0, generate the tree
 *   for the entire vocabulary.
 *
 * @param $depth
 *   Internal use only.
 *
 * @param $max_depth
 *   The number of levels of the tree to return. Leave NULL to return all levels.
 *
 * @return
 *   An array of all term objects in the tree. Each term object is extended
 *   to have "depth" and "parents" attributes in addition to its normal ones.
 *   Results are statically cached.
$taxo =taxonomy_get_tree($vid, $parent = 0, $depth = -1, $max_depth = NULL);
$name = $taxo[0]->name;
$tid = $taxo[0]->tid;
$description= $taxo[0]->description;

@param $tid
 *   $tid is from taxonomy_get_tree.
 *   $tid is the parent id
$taxo_child = taxonomy_get_children($tid, $vid = 0, $key = 'tid')

Converting Number to Letter

Converting Number to Letter:
Example,Converting 28 to Twenty Eight in php..

function N2L($number) {
   $result = array();
   $tens = floor($number / 10);
   $units = $number % 10;

   $words = array(
       'units' => array('', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eightteen', 'Nineteen'),
       'tens' => array('', '', 'Twenty', 'Thirty', 'Fourty', 'Fifty', 'Sixty', 'Seventy', 'Eigthy', 'Ninety')
   );

   if ($tens < 2){
       $result[] = $words['units'][$tens * 10 + $units];
   }

   else{
       $result[] = $words['tens'][$tens];

       if ($units > 0){
           $result[count($result) - 1] .= '-' . $words['units'][$units];
       }
   }

   if (empty($result[0])){
       $result[0] = '';
   }

   return trim(implode(' ', $result));
}