1.8. M2_Search

The heavy lifting in the built-in search of Moski2.net is based on the Apache Lucene implementation in Zend Framework. This makes for a powerful search engine, capable of searching all your content types automatically.

To use the search engine on your site you must configure it in the developer settings of the app and then implement one of the following methods in your site code:

M2_Search::getBlock([$options])

This method is for plopping into your HTML code. It will display a text field for entering a query, and when the user hits the return button, search results are displayed as a regular unordered list (sorted by relevance, though).

$options is an optional array that allows you to control a few things:

Table 20. Keys for M2_Search::getBlock

KeyDescription
useSubmitButton

Set to 1 if you wish to append a submit button to the search form.

trans

An array of translation strings for the search form. Possible keys are:

  • SEARCH: The text that prepends the search form. Pass an empty string if you do not with to prepend the form with text.

  • SUBMIT: The text on the submit button (if you have set useSubmitButton to 1.)

  • NO_RESULTS: The text to display if no search results are found.

The defaults for these keys are language dependent (Danish and English) and will automatically adjust to the current language of your site.


M2_Search::search($options)

If you want complete control over the search form and presentation of the results, you can perform the search and retrieve the results as an array instead.

$options is a hash that must contain the 'query' key, holding the search query.

Table 21. Keys for $options

KeyDescriptionRequired
query

The search string.

Yes

limitToTypes

An optional array of content types (IDs or root id attributes)

No


The method returns an array, where the 'hits' key is an array of results, each represented as an array holding the following keys:

Table 22. Keys for search result arrays

KeyDescription
title

Title of the result. Typically this is the linkField of the content type in question.

url

Full URL to the result, based on the template you provided in the administrative interface when configuring the search.

nid

ID of the record (node ID).

typeID

ID of the content type.

dataIf you supplied an "includeData" parameter with the search and set it to 1, you will get a full array of details about the matched node.

The return value also contains a "__profiling__" hash with profiling information about search performance.