func evalWhereClause(mWhere map[string]interface{}) []uint64 { // create an array to hold the idx's of all the data that meet our search tempKeysMatched := make([][]uint64, 0) // loop through the where clause, applying the appropriate logic where necessary for key, val := range mWhere { switch key { case "$OR": tempKeysMatched = append(tempKeysMatched, evalOrClause(val.([]interface{}))) case "$NOT": tempKeysMatched = append(tempKeysMatched, evalNotClause(val.(map[string]interface{}))) case "$NOR": tempKeysMatched = append(tempKeysMatched, evalNorClause(val.([]interface{}))) default: // check to see if the values of the keys are anything special if testMap(val) { // it's a map! m := val.(map[string]interface{}) // it should only have one key! for key1, val1 := range m { switch key1 { case "$IN": tempKeysMatched = append(tempKeysMatched, evalInClause(key, val1.([]interface{}))) case "$NIN": tempKeysMatched = append(tempKeysMatched, evalNinClause(key, val1.([]interface{}))) default: // ermm... this should never happen.... I NEED AN ADULT! log.Panic(error_.New("Not a valid query! Only $IN and $NIN are valid sub-documents!")) } } } else { // not a map! // the default is treated as an $AND, so add it to the temp index // we will run an intersection on the temp index last. // NOTE(@adam-hanna): we only support strings for now! tempKeysMatched = append(tempKeysMatched, index.QueryIndex(key, val.(string))) } } } // assume that where the user didn't input a logical operator, that an $AND was implied. // therefore, run the interesection... return arrayOperations.SortedIntersectUint64Arr(tempKeysMatched) }
func evalInClause(colName string, inVal []interface{}) []uint64 { // build the array that will hold the idx's aTemp := make([][]uint64, 0) // loop through the acceptable values, adding the matching idx's to our array for idx := range inVal { // NOTE(@adam-hanna): we only support strings for now! aTemp = append(aTemp, index.QueryIndex(colName, inVal[idx].(string))) } // find union bc our keys are allowed to be any of these unsortedKeys := arrayOperations.UnionUint64Arr(aTemp) // the above may be unsorted, so we need to sort it! if !sort.IsSorted(uintArray(unsortedKeys)) { // the array is not sorted, sort it! sort.Sort(uintArray(unsortedKeys)) } return unsortedKeys }