MMBase Lucene Module: Samples

Samples intro

The example abuses the MyNews example to show how you could configure the module. When the 'MyNews_Index' is searched for a string in 'indexed.text' the module is searching through both news and mags, or if you specifically want this in mags or news only. So ideally all your searchable content should have the same kind of fields, or if this isn't the case you can rename them to get a uniform naming. In the example I renamed the 'intro' field to be called introduction in the search index. Each 'table' mentioned in the config file will result in a 'document' to be created by Lucene in it's index, each of these will have the corresponding MMBase node number and (builder) name indexed automatically. When you search the results will be a list of node numbers.

Relations can be indexed also, like attachments in the example, this can be any kind of builder. If you specify type is 'binary' on the field then this field will be treated like a binary file and all text will be extracted from it and indexed. Now PDF and Word are supported. Related content will be indexed in the Lucene document of the parent of the relation, so you won't get the node number of the related MMBase object in your results.

Sample JSP2 taglib code

Sample search result

Sample indexing configuration

<?xml version="1.0" encoding="UTF-8"?>
<luceneindexdefinition defaultindex="MyNews_Index">
	<!-- example based on MyNews -->
	<index name="MyNews_Index">
		<table name="news">
			<field name="title">indexed.text</field>
			<field name="subtitle">indexed.text</field>
			<field name="intro">indexed.text</field>
			<field name="body">indexed.text</field>

			<related name="people">
				<field name="firstname">indexed.news.people</field>
				<field name="lastname">indexed.news.people</field>
				<field name="email">indexed.news.people</field>
				<field name="account">indexed.news.people</field>
				<related name="images">
					<field name="title">indexed.news.people</field>
					<field name="description">
						indexed.news.people
					</field>
				</related>
			</related>

			<related name="urls">
				<field type="boolean" name="number">news.url</field>
				<field name="name">indexed.text</field>
				<field name="description">indexed.text</field>
				<field name="url">indexed.text</field>
			</related>

			<related name="images">
				<field type="boolean" name="number">news.image</field>
				<field name="title">indexed.text</field>
				<field name="description">indexed.text</field>
			</related>

			<related name="attachments">
				<field type="boolean" name="number">
					news.attachment
				</field>
				<field name="title">indexed.text</field>
				<field name="description">indexed.text</field>
				<field name="handle" type="binary">indexed.text</field>
			</related>
		</table>
	</index>
</luceneindexdefinition>