Views PHP – a simple way to customize apachesolr views results by content type

Custom apachesolr results

Custom apachesolr results

We’ve been getting some questions about how we customize our apachesolr results by content type.  The answer:  very simply.  We use views php.  Views php allows us several new field type in views including a place to put custom PHP. It also has the advantage of allowing you to pull in variables already loaded into your view.  Thus while it is possible to write queries to the database in the php area, it is not necessary.  Moreover if you have need to tables not typically available in views you may use the data module to gain access.

For the video inclined here is a link to our 2 minutes on views php http://www.youtube.com/watch?v=cAehdUVrVDs

While there are several fields available in the Views PHP field I tend to use the output field area.  To hide the actual complete results

Using available variables in views php

Using available variables in views php

this makes it so that you can add a few lines of logic and have the results better reflect the information.  For our librarians we output their profile picture linked to their email address, for our web results we provide link descriptions etc.

Excluding results from display allows the results to be available to views php without cluttering the patrons view

Excluding results from display allows the results to be available to views php without cluttering the patrons view

Just remember to exclude your fields from display so that the user isn’t presented with  hundreds of fields and you’re good to go.

 

This entry was posted in Planet_Drupal and tagged , , , , . Bookmark the permalink.

6 Responses to Views PHP – a simple way to customize apachesolr views results by content type

  1. Pingback: Drupal 6 + Modules we Love Volume 1, Views | Wordpress VS Drupal

  2. David says:

    oh yeah, i was using the wrong field type and figured that out after watching your video.

    are there any modules or added functionality that would simply my life so i could do something like this:

    [code]
    field_cost_budget_value);
    ?>
    [/code]

    • alibama says:

      you want to do something like this
      print sum($row->field_cost_budget_value);
      views group by allows + views calc lets you do this

      Make certain your Global PHP field is BELOW the fields you want access to = it needs to come at

      Let me see whether I can rev up a separate tutorial on it

  3. David says:

    i mean this:


    field_cost_budget_value);
    ?>