Author: elecharny Date: Sat Sep 8 17:08:48 2012 New Revision: 1382330 URL: http://svn.apache.org/viewvc?rev=1382330&view=rev Log: Removed the evaluation using the reverse index. Modified: directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/SubstringEvaluator.java Modified: directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/SubstringEvaluator.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/SubstringEvaluator.java?rev=1382330&r1=1382329&r2=1382330&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/SubstringEvaluator.java (original) +++ directory/apacheds/branches/apacheds-mvbt/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/search/evaluator/SubstringEvaluator.java Sat Sep 8 17:08:48 2012 @@ -27,7 +27,6 @@ import org.apache.directory.server.xdbm. import org.apache.directory.server.xdbm.IndexEntry; import org.apache.directory.server.xdbm.Store; import org.apache.directory.server.xdbm.search.Evaluator; -import org.apache.directory.shared.ldap.model.cursor.Cursor; import org.apache.directory.shared.ldap.model.entry.Attribute; import org.apache.directory.shared.ldap.model.entry.Entry; import org.apache.directory.shared.ldap.model.entry.Value; @@ -124,71 +123,25 @@ public class SubstringEvaluator implemen @SuppressWarnings("unchecked") - public boolean evaluate( IndexEntry indexEntry ) throws Exception + public boolean evaluate( IndexEntry indexEntryQM ) throws Exception { - if ( ( idx == null ) || ( !idx.hasReverse() ) ) - { - return evaluateWithoutIndex( ( IndexEntry ) indexEntry ); - } - else - { - return evaluateWithIndex( indexEntry ); - } - } - + IndexEntry indexEntry = ( IndexEntry ) indexEntryQM; - public boolean evaluate( Entry entry ) throws Exception - { - return evaluateWithoutIndex( entry ); - } - - - public Pattern getPattern() - { - return regex; - } - - - public SubstringNode getExpression() - { - return node; - } - - - private boolean evaluateWithIndex( IndexEntry indexEntry ) throws Exception - { - /* - * 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. - */ - Cursor> entries = idx.reverseCursor( indexEntry.getId() ); + Entry entry = indexEntry.getEntry(); - // cycle through the attribute values testing for a match - while ( entries.next() ) + // resuscitate the entry if it has not been and set entry in IndexEntry + if ( null == entry ) { - IndexEntry rec = entries.get(); - - // once match is found cleanup and return true - if ( regex.matcher( rec.getKey() ).matches() ) - { - entries.close(); - return true; - } + entry = db.lookup( indexEntry.getId() ); + indexEntry.setEntry( entry ); } - entries.close(); - - // we fell through so a match was not found - assertion was false. - return false; - } - + /* + * Don't make a call here to evaluateWithoutIndex( Entry ) for + * code reuse since we do want to set the value on the indexEntry on + * matches. + */ - // TODO - determine if comaparator and index entry should have the Value - // wrapper or the raw normalized value - private boolean evaluateWithoutIndex( Entry entry ) throws Exception - { // get the attribute Attribute attr = entry.get( attributeType ); @@ -201,14 +154,39 @@ public class SubstringEvaluator implemen * The test uses the comparator obtained from the appropriate * substring matching rule. */ - for ( Value value : attr ) + if ( attr.isHumanReadable() ) { - String strValue = ( String ) value.getNormValue(); + for ( Value value : attr ) + { + String strValue = ( String ) value.getNormValue(); - // Once match is found cleanup and return true - if ( regex.matcher( strValue ).matches() ) + // Once match is found cleanup and return true + if ( regex.matcher( strValue ).matches() ) + { + // before returning we set the normalized value + indexEntry.setKey( strValue ); + return true; + } + } + } + else + { + // Slightly more complex. We won't be able to use a regex to check + // the value. + for ( Value value : attr ) { - return true; + byte[] byteValue = ( byte[] ) value.getNormValue(); + + // Once match is found cleanup and return true + // @TODO : implement this check. + /* + if ( check( byteValue ) ) + { + // before returning we set the normalized value + indexEntry.setKey( byteValue ); + return true; + } + */ } } @@ -247,6 +225,8 @@ public class SubstringEvaluator implemen // Once match is found cleanup and return true if ( regex.matcher( strValue ).matches() ) { + // before returning we set the normalized value + indexEntry.setKey( strValue ); return true; } } @@ -259,25 +239,8 @@ public class SubstringEvaluator implemen } - // TODO - determine if comaparator and index entry should have the Value - // wrapper or the raw normalized value - private boolean evaluateWithoutIndex( IndexEntry indexEntry ) throws Exception + public boolean evaluate( Entry entry ) throws Exception { - Entry entry = indexEntry.getEntry(); - - // resuscitate the entry if it has not been and set entry in IndexEntry - if ( null == entry ) - { - entry = db.lookup( indexEntry.getId() ); - indexEntry.setEntry( entry ); - } - - /* - * Don't make a call here to evaluateWithoutIndex( Entry ) for - * code reuse since we do want to set the value on the indexEntry on - * matches. - */ - // get the attribute Attribute attr = entry.get( attributeType ); @@ -290,39 +253,14 @@ public class SubstringEvaluator implemen * The test uses the comparator obtained from the appropriate * substring matching rule. */ - if ( attr.isHumanReadable() ) + for ( Value value : attr ) { - for ( Value value : attr ) - { - String strValue = ( String ) value.getNormValue(); + String strValue = ( String ) value.getNormValue(); - // Once match is found cleanup and return true - if ( regex.matcher( strValue ).matches() ) - { - // before returning we set the normalized value - indexEntry.setKey( strValue ); - return true; - } - } - } - else - { - // Slightly more complex. We won't be able to use a regex to check - // the value. - for ( Value value : attr ) + // Once match is found cleanup and return true + if ( regex.matcher( strValue ).matches() ) { - byte[] byteValue = ( byte[] ) value.getNormValue(); - - // Once match is found cleanup and return true - // @TODO : implement this check. - /* - if ( check( byteValue ) ) - { - // before returning we set the normalized value - indexEntry.setKey( byteValue ); - return true; - } - */ + return true; } } @@ -361,8 +299,6 @@ public class SubstringEvaluator implemen // Once match is found cleanup and return true if ( regex.matcher( strValue ).matches() ) { - // before returning we set the normalized value - indexEntry.setKey( strValue ); return true; } } @@ -375,6 +311,18 @@ public class SubstringEvaluator implemen } + public Pattern getPattern() + { + return regex; + } + + + public SubstringNode getExpression() + { + return node; + } + + /** * @see Object#toString() */ @@ -382,7 +330,7 @@ public class SubstringEvaluator implemen { StringBuilder sb = new StringBuilder(); - sb.append( tabs ).append( "SubsctringEvaluator : " ).append( node ).append( "\n" ); + sb.append( tabs ).append( "SubstringEvaluator : " ).append( node ).append( "\n" ); return sb.toString(); }