comparison query.cpp @ 468:4dbd7917bf9e api-inversion

YAY! audioDB::index_query_loop is now disentangled. Hardwired lsh_in_core to true, and invented a new QID flag for !lsh_exact. All tests continue to pass. The plans now: - extract the audiodb_query_spec() function from inside audioDB::query, and move audioDB::query (and the timestamps function) to audioDB.cpp; - write libtests/0036 and libtests/0037 in terms of audiodb_query_spec(); - rewrite all the other libtests in terms of audiodb_query_spec(); - delete audiodb_query() [ and maybe rename audiodb_query_spec(), I dunno]; - implement example bindings (probably to Lisp, because that's what I know best); - see if anyone other than me can work out how the API works. If not, provide documentation; - revise API in the light of user feedback.
author mas01cr
date Wed, 31 Dec 2008 15:44:12 +0000
parents 11fccb6a3bd5
children d3afc91d205d
comparison
equal deleted inserted replaced
466:11fccb6a3bd5 468:4dbd7917bf9e
114 } 114 }
115 } 115 }
116 116
117 qspec.qid.datum = &datum; 117 qspec.qid.datum = &datum;
118 qspec.qid.sequence_length = sequenceLength; 118 qspec.qid.sequence_length = sequenceLength;
119 qspec.qid.flags = usingQueryPoint ? 0 : ADB_QUERY_ID_FLAG_EXHAUSTIVE; 119 qspec.qid.flags = 0;
120 qspec.qid.flags |= usingQueryPoint ? 0 : ADB_QID_FLAG_EXHAUSTIVE;
121 qspec.qid.flags |= lsh_exact ? 0 : ADB_QID_FLAG_ALLOW_FALSE_POSITIVES;
120 qspec.qid.sequence_start = queryPoint; 122 qspec.qid.sequence_start = queryPoint;
121 123
122 switch(queryType) { 124 switch(queryType) {
123 case O2_POINT_QUERY: 125 case O2_POINT_QUERY:
124 qspec.qid.sequence_length = 1; 126 qspec.qid.sequence_length = 1;
226 } 228 }
227 229
228 // Test for index (again) here 230 // Test for index (again) here
229 if((qspec.refine.flags & ADB_REFINE_RADIUS) && audiodb_index_exists(adb->path, qspec.refine.radius, qspec.qid.sequence_length)){ 231 if((qspec.refine.flags & ADB_REFINE_RADIUS) && audiodb_index_exists(adb->path, qspec.refine.radius, qspec.qid.sequence_length)){
230 VERB_LOG(1, "Calling indexed query on database %s, radius=%f, sequence_length=%d\n", adb->path, qspec.refine.radius, qspec.qid.sequence_length); 232 VERB_LOG(1, "Calling indexed query on database %s, radius=%f, sequence_length=%d\n", adb->path, qspec.refine.radius, qspec.qid.sequence_length);
231 if(index_query_loop(adb, &qspec, &qstate) < 0) { 233 if(audiodb_index_query_loop(adb, &qspec, &qstate) < 0) {
232 error("index_query_loop failed"); 234 error("index_query_loop failed");
233 } 235 }
234 } else { 236 } else {
235 VERB_LOG(1, "Calling brute-force query on database %s\n", dbName); 237 VERB_LOG(1, "Calling brute-force query on database %s\n", dbName);
236 if(audiodb_query_loop(adb, &qspec, &qstate)) { 238 if(audiodb_query_loop(adb, &qspec, &qstate)) {
506 } 508 }
507 509
508 audiodb_datum_qpointers(&d, sequence_length, vector_data, vector, qpointers); 510 audiodb_datum_qpointers(&d, sequence_length, vector_data, vector, qpointers);
509 511
510 /* Finally, if applicable, set up the moving qpointers. */ 512 /* Finally, if applicable, set up the moving qpointers. */
511 if(spec->qid.flags & ADB_QUERY_ID_FLAG_EXHAUSTIVE) { 513 if(spec->qid.flags & ADB_QID_FLAG_EXHAUSTIVE) {
512 /* the qpointers are already at the start, and so correct. */ 514 /* the qpointers are already at the start, and so correct. */
513 } else { 515 } else {
514 /* adjust the qpointers to point to the correct place in the sequence */ 516 /* adjust the qpointers to point to the correct place in the sequence */
515 *vector = *vector_data + spec->qid.sequence_start * d.dim; 517 *vector = *vector_data + spec->qid.sequence_start * d.dim;
516 qpointers->l2norm = qpointers->l2norm_data + spec->qid.sequence_start; 518 qpointers->l2norm = qpointers->l2norm_data + spec->qid.sequence_start;
657 audiodb_free_datum(&d); 659 audiodb_free_datum(&d);
658 return 1; 660 return 1;
659 } 661 }
660 audiodb_free_datum(&d); 662 audiodb_free_datum(&d);
661 } 663 }
662 Uns32T qPos = (spec->qid.flags & ADB_QUERY_ID_FLAG_EXHAUSTIVE) ? pp.qpos : 0; 664 Uns32T qPos = (spec->qid.flags & ADB_QID_FLAG_EXHAUSTIVE) ? pp.qpos : 0;
663 Uns32T sPos = pp.spos; // index into l2norm table 665 Uns32T sPos = pp.spos; // index into l2norm table
664 // Test power thresholds before computing distance 666 // Test power thresholds before computing distance
665 if( ( (!power_refine) || audiodb_powers_acceptable(&spec->refine, qpointers->power[qPos], dbpointers.power[sPos])) && 667 if( ( (!power_refine) || audiodb_powers_acceptable(&spec->refine, qpointers->power[qPos], dbpointers.power[sPos])) &&
666 ( qPos<qpointers->nvectors-sequence_length+1 && sPos<(*adb->track_lengths)[pp.trackID]-sequence_length+1 ) ){ 668 ( qPos<qpointers->nvectors-sequence_length+1 && sPos<(*adb->track_lengths)[pp.trackID]-sequence_length+1 ) ){
667 // Compute distance 669 // Compute distance
782 if((!(spec->refine.flags & ADB_REFINE_RADIUS)) || 784 if((!(spec->refine.flags & ADB_REFINE_RADIUS)) ||
783 thisDist <= (spec->refine.radius+O2_DISTANCE_TOLERANCE)) { 785 thisDist <= (spec->refine.radius+O2_DISTANCE_TOLERANCE)) {
784 adb_result_t r; 786 adb_result_t r;
785 r.key = (*adb->keys)[track].c_str(); 787 r.key = (*adb->keys)[track].c_str();
786 r.dist = thisDist; 788 r.dist = thisDist;
787 if(spec->qid.flags & ADB_QUERY_ID_FLAG_EXHAUSTIVE) { 789 if(spec->qid.flags & ADB_QID_FLAG_EXHAUSTIVE) {
788 r.qpos = j; 790 r.qpos = j;
789 } else { 791 } else {
790 r.qpos = spec->qid.sequence_start; 792 r.qpos = spec->qid.sequence_start;
791 } 793 }
792 r.ipos = k; 794 r.ipos = k;