*/
public boolean evaluate( ExprNode node, IndexRecord record )
throws NamingException
{
RE regex = null;
SubstringNode snode = ( SubstringNode ) node;
String oid = oidRegistry.getOid( snode.getAttribute() );
AttributeType type = attributeTypeRegistry.lookup( oid );
Normalizer normalizer = type.getSubstr().getNormalizer();
if ( db.hasUserIndexOn( snode.getAttribute() ) )
{
Index idx = db.getUserIndex( snode.getAttribute() );
/*
* Note that this is using the reverse half of the index giving a
* considerable performance improvement on this kind of operation.
* Otherwise we would have to scan the entire index if there were
* no reverse lookups.
*/
NamingEnumeration list = idx.listReverseIndices( record.getEntryId() );
// compile the regular expression to search for a matching attribute
try
{
regex = snode.getRegex( normalizer );
}
catch ( RESyntaxException e )
{
NamingException ne = new NamingException( "SubstringNode '"
+ node + "' had " + "incorrect syntax" );
ne.setRootCause( e );
throw ne;
}
// cycle through the attribute values testing for a match
while ( list.hasMore() )
{
IndexRecord rec = ( IndexRecord ) list.next();
// once match is found cleanup and return true
if ( regex.match( ( String ) rec.getIndexKey() ) )
{
list.close();
return true;
}
}
// we fell through so a match was not found - assertion was false.
return false;
}
// --------------------------------------------------------------------
// Index not defined beyond this point
// --------------------------------------------------------------------
// resusitate the entry if it has not been and set entry in IndexRecord
if ( null == record.getAttributes() )
{
Attributes attrs = db.lookup( record.getEntryId() );
record.setAttributes( attrs );
}
// get the attribute
Attribute attr = record.getAttributes().get( snode.getAttribute() );
// if the attribute does not exist just return false
if ( null == attr )
{
return false;
}
// compile the regular expression to search for a matching attribute
try
{
regex = snode.getRegex( normalizer );
}
catch ( RESyntaxException e )
{
NamingException ne = new NamingException( "SubstringNode '"
+ node + "' had " + "incorrect syntax" );