Skip to content

Commit

Permalink
Additional testing of the snapshot comparison for endpoints that don'…
Browse files Browse the repository at this point in the history
…t support look up? (#945)

For search engines that don't support query by id, like vectara or search api, you are required to store document fields and then we (in the background) use the splainer solr configuration to do a query by id, but just hit the Quepid /search end point!
  • Loading branch information
epugh authored Feb 6, 2024
1 parent 85ad0c9 commit aa7d899
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 21 deletions.
6 changes: 5 additions & 1 deletion app/assets/javascripts/controllers/queriesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ angular.module('QuepidApp')
fullDiffName = 'Highest ratest results for each query';
} else {
var snapshot = querySnapshotSvc.snapshots[queryViewSvc.diffSetting];
fullDiffName = snapshot.name();
// When reopening the snapshot selection UI we clear out the querySnapshotSvc.snapshots
// while reloading the data.
if (snapshot) {
fullDiffName = snapshot.name();
}
}
return fullDiffName;
};
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/services/docCacheSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ angular.module('QuepidApp')
}

var docIds = Object.keys(docsToFetch);
var resolver = docResolverSvc.createResolver(docIds, settings, 15);


if ( docIds.length > 0 ) {
var resolver = docResolverSvc.createResolver(docIds, settings, 15);
return resolver.fetchDocs()
.then(function () {
angular.forEach(resolver.docs, function (doc) {
Expand Down
42 changes: 26 additions & 16 deletions app/assets/javascripts/services/querySnapshotSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
angular.module('QuepidApp')
.service('querySnapshotSvc', [
'$http', '$q',
'settingsSvc', 'docCacheSvc', 'caseTryNavSvc',
'settingsSvc', 'docCacheSvc', 'caseTryNavSvc', 'fieldSpecSvc',
'SnapshotFactory',
function querySnapshotSvc(
$http, $q,
settingsSvc, docCacheSvc, caseTryNavSvc,
settingsSvc, docCacheSvc, caseTryNavSvc, fieldSpecSvc,
SnapshotFactory
) {
// caches normal docs for all snapshots
Expand All @@ -26,8 +26,14 @@ angular.module('QuepidApp')
svc.importSnapshots = importSnapshots;
svc.importSnapshotsToSpecificCase = importSnapshotsToSpecificCase;
svc.get = get;
svc.mapFieldSpecToSolrFormat = mapFieldSpecToSolrFormat;

function mapFieldSpecToSolrFormat(fieldSpec) {
let convertedfieldSpec = fieldSpec.replace(/id:_([^,]+)/, 'id:$1');
return convertedfieldSpec;
}

var addSnapshotResp = function(snapshots) {
var addSnapshotResp = function(snapshots) {
angular.forEach(snapshots, function(snapshot) {
// locally store snapshot data
var snapObj = new SnapshotFactory(snapshot);
Expand All @@ -45,20 +51,24 @@ angular.module('QuepidApp')
// however if that isnt' possible, then we require you to store the doc fields
// in the snapshot, and we look them up from the Snapshot. To be clever
// we pretend to be a "solr'" endpoint to drive the lookup.
if (settingsSvc.supportLookupById(settings.searchEngine) === false){
var settingsForLookup = angular.copy(settings);
settingsForLookup.apiMethod = 'GET';
settingsForLookup.searchEngine = 'solr';
settingsForLookup.searchEndpointId = null;
settingsForLookup.customHeaders = null;

let snapshotId = snapshots[0].id;
settingsForLookup.searchUrl = `${caseTryNavSvc.getQuepidRootUrl()}/api/cases/${caseTryNavSvc.getCaseNo()}/snapshots/${snapshotId}/search`;

settings = settingsForLookup;
if (snapshots.length > 0 ) {
if (settingsSvc.supportLookupById(settings.searchEngine) === false){
var settingsForLookup = angular.copy(settings);
settingsForLookup.apiMethod = 'GET';
settingsForLookup.searchEngine = 'solr';

let solrSpecificFieldSpecStr = svc.mapFieldSpecToSolrFormat(settingsForLookup.fieldSpec);
settingsForLookup.fieldSpec = fieldSpecSvc.createFieldSpec(solrSpecificFieldSpecStr);
settingsForLookup.searchEndpointId = null;
settingsForLookup.customHeaders = null;

let snapshotId = snapshots[0].id;
settingsForLookup.searchUrl = `${caseTryNavSvc.getQuepidRootUrl()}/api/cases/${caseTryNavSvc.getCaseNo()}/snapshots/${snapshotId}/search`;

settings = settingsForLookup;
}
}



return docCacheSvc.update(settings);
} else {
return $q(function(resolve) {
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/api/v1/import/cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def create
end

if @case.save
# so annoying to import a case and then have to do the wizard!
# If you import a case, you presumably know what you are doing.
@current_user.update completed_case_wizard: true
respond_with @case
else
render json: @case.errors, status: :bad_request
Expand Down
1 change: 1 addition & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class PagesController < ApplicationController
skip_before_action :require_login
skip_before_action :verify_authenticity_token, only: [ :theme_textmate, :mode_json ]
skip_before_action :check_for_announcement
# before_action :check_page, only: [:show]

# def show
Expand Down
1 change: 1 addition & 0 deletions app/controllers/proxy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class ProxyController < ApplicationController
skip_before_action :require_login
skip_before_action :verify_authenticity_token, only: [ :fetch ]
skip_before_action :check_for_announcement
# curl -X GET "http://localhost:3000/proxy/fetch?url=https://quepid-solr.dev.o19s.com/solr/tmdb/select&q=*:*"
# curl -X POST "http://localhost:3000/proxy/fetch?url=https://quepid-solr.dev.o19s.com/solr/tmdb/query" -d '{"query":"star"}'
# curl -X GET "http://localhost:3000/proxy/fetch?url=http://quepid-solr.dev.o19s.com:8985/solr/media/select&q=*:*" -u 'solr:SolrRocks'
Expand Down
28 changes: 27 additions & 1 deletion spec/javascripts/angular/services/docCacheSvc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,33 @@ describe('Service: docCacheSvc', function () {
$rootScope.$apply();
expect(called).toBe(1);
var mockResolver = docResolverSvc.mockResolver;
expect(mockResolver.docs.length).toBe(0);
// We only resolve if there are docs to be resolved. In this test
// we have one new doc to be resolved so one match.
expect(mockResolver.docs.length).toBe(3);
});

it('resolves partially ignoringredundant ids', function() {
checkSetupFromScratch();

docCacheSvc.addIds(['1', '2', '3', '4']);

var called = 0;
docCacheSvc.update(ignoredSettings)
.then(function() {
expect(docCacheSvc.getDoc('1').id).toBe('1');
expect(docCacheSvc.getDoc('2').id).toBe('2');
expect(docCacheSvc.getDoc('3').id).toBe('3');
expect(docCacheSvc.getDoc('4').id).toBe('4');
called++;
});

$rootScope.$apply();
expect(called).toBe(1);
var mockResolver = docResolverSvc.mockResolver;
console.log("looking at mock reoslver")
console.log(mockResolver.docs)
// We only resolved doc 4
expect(mockResolver.docs.length).toBe(1);
});
});

Expand Down
11 changes: 10 additions & 1 deletion spec/javascripts/angular/services/querySnapshotSvc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe('Service: querySnapshotSvc', function () {
}
});

it('gets saved search results in saved order', function fetchAfterResolveTest() {
fit('gets saved search results in saved order', function fetchAfterResolveTest() {
var snap5 = querySnapshotSvc.snapshots['5'];
var snap5query0Results = snap5.getSearchResults('0');
expect(snap5query0Results[0].id).toEqual('1');
Expand Down Expand Up @@ -515,4 +515,13 @@ describe('Service: querySnapshotSvc', function () {
expect(Object.keys(querySnapshotSvc.snapshots).length).toBe(2);
});
});

describe('Mapping fieldSpec back to /search endpoint expectations', function() {
it('handles various patterns', function() {
expect(querySnapshotSvc.mapFieldSpecToSolrFormat('id:id title:title body')).toBe('id:id title:title body');
expect(querySnapshotSvc.mapFieldSpecToSolrFormat('id:_id title:title body')).toBe('id:id title:title body');
expect(querySnapshotSvc.mapFieldSpecToSolrFormat('title:title id:_id body')).toBe('title:title id:id body');
expect(querySnapshotSvc.mapFieldSpecToSolrFormat('id title:title body')).toBe('id title:title body');
});
});
});

0 comments on commit aa7d899

Please sign in to comment.