home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Lucene example source code file (albumFilteredQuery.xsl)

This example Lucene source code file (albumFilteredQuery.xsl) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lucene tags/keywords

anded, booleanquery, booleanquery, cachedfilter, cachedfilter, clause, clause, document, filter, filteredquery, query, termsfilter, termsquery, termsquery

The Lucene albumFilteredQuery.xsl source code

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/Document">
<!-- This template uses an efficient, cached filter for the "genre" field".
	Other query fields are fed directly through an analyzer and so do not need to adhere to  
	traditional Lucene query syntax. Terms within a field are ORed while different fields are ANDed
 -->	
<FilteredQuery>
	<Query>
		<BooleanQuery>
			<xsl:if test="count(artist)>0">
			    <Clause occurs="must">
			      <TermsQuery fieldName="artist">
			   </Clause>
		   </xsl:if>
			<xsl:if test="count(album)>0">
			    <Clause occurs="must">
			      <TermsQuery fieldName="album">
			   </Clause>
		   </xsl:if>
			<xsl:if test="count(releaseDate)>0">
			    <Clause occurs="must">
			      <TermsQuery fieldName="releaseDate">
			   </Clause>
		   </xsl:if>
	</BooleanQuery>
	</Query>
	<Filter>
		<CachedFilter>
			<!-- Example filter to be cached for fast, repeated use -->
			<TermsFilter fieldName="genre">			
				<xsl:value-of select="genre"/>
			</TermsFilter>
		</CachedFilter>		
	</Filter>	
</FilteredQuery>
</xsl:template>
</xsl:stylesheet>

Other Lucene examples (source code examples)

Here is a short list of links related to this Lucene albumFilteredQuery.xsl source code file:



my book on functional programming

 

new blog posts

 

Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.