Last updated 10 November 2010. Created on 10 November 2010.
Edited by maxmmize. Log in to edit this page.

Truncating
If you want to truncate (limit) your search result description you can do so in a variety of ways but I will concentrate on the most effective, immediate and easiest assuming the audience being those with a PHP handicap. (like me)

First, copy your search-result.tpl.php file and place it in your template folder. If you already have one there, then just adjust the code you have accordingly.

Second open your file using whatever editor you like. I use Dreamweaver. Your code should look something like this:

<?php if ($snippet) : ?>  
    <p class="search-snippet"><?php print $snippet ?></p>  
  <?php endif; ?>  
  <?php if ($info) : ?>  
  <p class="search-info"><?php print $info; ?></p>  
  <?php endif; ?>  

All you should be worried about here is modifying this piece of code:

<?php print $snippet ?>

For this demonstration we will want to truncate the description length to 100 characters and let PHP handle finding the previous or last whole word within the 100 character limit.

Simply change your code to this:

<?php print substr($snippet, 0, 100); ?>

This is saying: display the string, $snippet for a total of 100 characters and start your character count at the first character (0). To clarify, if I wanted it to start counting at a different character I just replace 0 with the start character, that would result in a chunk of your description.

That's it.

If you are looking to really zazzle your description then just follow the below guide:

Content in the description variable will be: 123456789

I want to display: 12
substr($snippet, 0, 2);

I want to display: 56789
substr($snippet, 4);

I want to display: 89
substr($snippet, -2);

I want to display: 456
substr($snippet, 3, -4);

Lengthening

Same as above but you need to make sure your nutch and Solr instance is actually saving and sending the amount of description you need.

Make sure you have this in your schema.xml files both in nutch and Solr. More info can be found here: http://wiki.apache.org/solr/SchemaXml
<copyField source="body" dest="teaser" maxChars="800"/>

Also, try and make sure you have these defaults:

<property>
  <name>fetcher.store.content</name>
  <value>true</value>
  <description>If true, fetcher will store content.</description>
</property>

<property>
  <name>http.content.limit</name>
  <value>65536</value>
  <description>The length limit for downloaded content, in bytes.
  If this value is nonnegative (>=0), content longer than it will be truncated;
  otherwise, no truncation at all.
  </description>

You can also use these same ideas for your title. To lengthen or truncate your title you just need to modify your nutch-site.xml to include:

<property>
  <name>indexer.max.title.length</name>
  <value>100</value>
  <description>The maximum number of characters of a title that are indexed.
  </description>
</property>

Adjust it to whatever value you want and truncate the title in your search-result.tpl.php. Use the same code above.

I also wanted to truncate the title to cut off any title after a pipe (|) So, I used this:
<?php $title; $parts = explode( '|', $title ); print $parts[0]; ?>

This will truncate the result to the first pipe (|). So instead of this:

My title is freakin long and I have issues | I also Use | Pipes | A lot

I get:

My title is freakin long and I have issues

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

maxmmize’s picture

If you are having issues with highlighting and your teaser length you can solve this issue very easily here: http://drupal.org/node/970928

Audience:

Those who want highlighting but also want to get past the 100 character limit per keyword.