Drupal

How to index data in the database for search?

- Indexing is an important feature of MySQL. It supports different type of indexes like primary key index, unique index, normal index and full-text index. Indexes help to speed up the retrieval of data from MySQL database server.

- Drupal's search engine indexes the text content of the nodes on your site

- The search engine indexes at intervals you choose by setting "cron runs."  Cron is not a part of Drupal. It's a scheduler that resides on your server and runs tasks at intervals, which you specify. 

how does search works in drupal?

Site-wide Boolean keyword search of Nodes and User names

- Indexing isn't instant in the drupal search
- Your new content will not be indexed instantly after it has been added to the site.
- Go to Configuration > Search settings click the "Re-index site" button.
- The correct way to get your site's content indexed is to go to Configuration > Cron. Drupal's Search module requires a cron job to run correctly.

Search Query Types
- AND Searches
- OR Searches

How does memcache store data?

  Memcached's APIs provide a giant hash table distributed across multiple machines. When the table is full, subsequent inserts cause older data to be purged in least recently used (LRU) order.

  The servers keep the values in RAM; if a server runs out of RAM, it discards the oldest values. Therefore, clients must treat Memcached as a transitory cache; they cannot assume that data stored in Memcached is still there when they need it.

Difference between memcache and varnish?

  Memcached can be used as an in-memory, distributed back-end for your application cache.
  Varnish can be used as a reverse proxy to externally cache HTTP requests.

  It seems to me that Varnish is behind the web server, caching web pages and doesn't require change in code, just configuration.
  On the other side, Memcached is general purpose caching system and mostly used to cache result from database and does require change in get method (first cache lookup).

Creating custom hooks in Drupal?

1) Alter hooks
   a common way to edit the contents of a particular object or variable by settings     variables in the hook by reference, typically by using drupal_alter()

2) Intercepting hooks
  Allowing external modules to perform actions during the execution, cannot get variables by reference, typically by using module_invoke_all(), module_invoke()

a) Simple invoking:
---------------------------
module_invoke_all() => Calling all modules implementing the hook

Drupal Template Structure

HTML
|->  HTML Head
|->  Page
      |-> Node
              |-> Field
              |-> Field
              |->Node Links
              |->Comment Wrapper
                    |-> Comment
                    |-> Comment
                    |-> Comment
      |-> Region
            |-> Block
            |-> Block

Preprocess Functions (theme_hook) Drupal

Allow one module to alter the variable used by another module when it call a theme hook.

template_preprocess_node(&$variables) 
  -> Process variables for node.tpl.php

template_preprocess_page(&$variables)
   -> Process variables for page.tpl.php

[module]_preprocess_[theme hookname]  (&$variables)

multi-hook preprocess functions
[module]_preprocess (&$variables, $hook)

Order of preprocess execution
-------------------------------------
All Preprocess functions run before all process functions