public IEnumerable <KeyValuePair <byte[], byte[]> > Find(string indexName, byte[] lookupValue)
{
KeyValueStore indexStore = GetSecondaryIndex(indexName);
// Loop over the values
foreach (var pair in indexStore.EnumerateFromKey(lookupValue))
{
var key = pair.Key;
var value = pair.Value;
// construct our index key pattern (lookupvalue | key)
if (ByteArray.CompareMemCmp(key, 0, lookupValue, 0, lookupValue.Length) == 0)
{
int offset = 0;
byte[] objectKey = null;
if (indexStore.RazorFormatVersion < 2)
{
if (ByteArray.CompareMemCmp(key, key.Length - value.Length, value, 0, value.Length) == 0)
{
objectKey = pair.Value;
}
}
else
{
int indexKeyLen = Helper.Decode7BitInt(pair.Value, ref offset);
if (lookupValue.Length == indexKeyLen)
{
// Lookup the value of the actual object using the key that was found
// get the object key from the index value tail
objectKey = ItemKeyFromIndex(pair, indexKeyLen);
}
}
if (objectKey != null)
{
var primaryValue = this.Get(objectKey);
if (primaryValue != null)
{
yield return(new KeyValuePair <byte[], byte[]>(objectKey, primaryValue));
}
}
}
else
{
// if the above condition was not met then we must have enumerated past the end of the indexed value
yield break;
}
}
}