|

NoSQL databases: 10 Things you Should Know About Them

NoSQL databases: 10 Things you Should Know About Them: 5 pros and 5 cons by Guy Harrison: Five advantages of NoSQL Elastic scaling Big data Goodbye DBAs (see you later?) Economics Flexible data models Five challenges of NoSQL Maturity Support Analytics and business intelligence Administration Expertise A few amendments though: Elastic scaling: part …

Post original

Usar Solr desde PHP

Solr es un servidor de búsquedas basado en Lucene que nos puede venir muy bien cuando nuestro proyecto web necesite un motor de búsqueda en condiciones, siendo una alternativa a Sphinx. Aunque está basado en Java, existe una librería que permite trabajar con ella, otra posibilidad sería utilizar Zend Search, ya que usa el formato de Lucene, aunque en una versión anterior a la que utiliza Solr, por lo que nos encontramos con incompatibilidades.

El uso de la librería es bastante sencillo:

  require_once( 'Apache/Solr/Service.php' );
  
  // 
  // 
  // Try to connect to the named server, port, and url
  // 
  $solr = new Apache_Solr_Service( 'localhost', '8983', '/solr' );
  
  if ( ! $solr->ping() ) {
    echo 'Solr service not responding.';
    exit;
  }
  
  //
  //
  // Create two documents to represent two auto parts.
  // In practice, documents would likely be assembled from a 
  //   database query. 
  //
  $parts = array(
    'spark_plug' => array(
      'partno' => 1,
      'name' => 'Spark plug',
      'model' => array( 'Boxster', '924' ),
      'year' => array( 1999, 2000 ),
      'price' => 25.00,
      'inStock' => true,
    ),
    'windshield' => array(
      'partno' => 2,
      'name' => 'Windshield',
      'model' => '911',
      'year' => array( 1999, 2000 ),
      'price' => 15.00,
      'inStock' => false,
    )
  );
    
  $documents = array();
  
  foreach ( $parts as $item => $fields ) {
    $part = new Apache_Solr_Document();
    
    foreach ( $fields as $key => $value ) {
      if ( is_array( $value ) ) {
        foreach ( $value as $datum ) {
          $part->setMultiValue( $key, $datum );
        }
      }
      else {
        $part->$key = $value;
      }
    }
    
    $documents[] = $part;
  }
    
  //
  //
  // Load the documents into the index
  // 
  try {
    $solr->addDocuments( $documents );
    $solr->commit();
    $solr->optimize();
  }
  catch ( Exception $e ) {
    echo $e->getMessage();
  }
  
  //
  // 
  // Run some queries. Provide the raw path, a starting offset
  //   for result documents, and the maximum number of result
  //   documents to return. You can also use a fourth parameter
  //   to control how results are sorted and highlighted, 
  //   among other options.
  //
  $offset = 0;
  $limit = 10;
  
  $queries = array(
    'partno: 1 OR partno: 2',
    'model: Boxster',
    'name: plug'
  );

  foreach ( $queries as $query ) {
    $response = $solr->search( $query, $offset, $limit );
    
    if ( $response->getHttpStatus() == 200 ) { 
      // print_r( $response->getRawResponse() );
      
      if ( $response->response->numFound > 0 ) {
        echo "$query 
"; foreach ( $response->response->docs as $doc ) { echo "$doc->partno $doc->name
"; } echo '
'; } } else { echo $response->getHttpStatusMessage(); } }

También recomiendo que en el esquema de Solr añadamos el filtro de caracteres mapping-ISOLatin1Accent.txt, para que no tengamos problemas a la hora de buscar palabras acentuadas sin usar los acentos (cancion => canción).

Solr PHP Client

|

NoSQL Guide for Beginners

NoSQL Guide for Beginners: Alexandre Porcelli has a great post for NoSQL beginners: one of the most frequent question that people use to ask me about nosql is: what is the best nosql tool that enables me start with using my programming language (java, .net, php, python, etc..)? its almost impossible to have a quick answer ‘cos it involves many thin …

Post original

|

InfiniteGraph Use Case: Modeling Stackoverflow

InfiniteGraph Use Case: Modeling Stackoverflow: I didn’t hear much about InfiniteGraph after its 1.0 release, except this post that uses Stackoverflow data as input to demo some features of graph databases: The vertices in the graph are represented as the Users, Questions and Answers above while the edges are represented as the interactions between …

Post original

|

Picasa jQuery Plugin

A simple jQuery plugin to get albums and images from Picasa without the need for PHP, Ruby, or any other server side language. Makes it easy to create a simple, dynamic, free, client-side-only image gallery. …

Post original

|

Create a Twitter AJAX Button with MooTools, jQuery, or Dojo

There’s nothing like a subtle, slick website widget that effectively uses CSS and JavaScript to enhance the user experience.  Of course widgets like that take many hours to perfect, but it doesn’t take long for that effort to be rewarded with above-average user retention and buzz.  One of the widgets I love is Twitter’s “Follow” button.  Let me sho …

Post original