-
Notifications
You must be signed in to change notification settings - Fork 23
fix(facets): limit Collections facet to classic ADS databases #2382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thostetler
merged 1 commit into
adsabs:master
from
thostetler:chore/collections-facet-ads-only
Sep 30, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| define(['underscore', 'js/components/api_query', 'js/widgets/facet/actions', 'js/wraps/database_facet'], function( | ||
| _, | ||
| ApiQuery, | ||
| Actions, | ||
| DatabaseFacet | ||
| ) { | ||
| describe('Database (Collections) Facet (database_facet.spec.js)', function() { | ||
| var makeResponse = function(facetFields, facetLimit) { | ||
| return { | ||
| responseHeader: { | ||
| status: 0, | ||
| QTime: 4, | ||
| params: { | ||
| 'facet.limit': facetLimit || '20', | ||
| q: 'star', | ||
| 'facet.field': 'database', | ||
| 'facet.offset': '0', | ||
| 'facet.mincount': '1', | ||
| facet: 'true', | ||
| wt: 'json', | ||
| }, | ||
| }, | ||
| response: { numFound: 10, start: 0, docs: [] }, | ||
| facet_counts: { | ||
| facet_queries: {}, | ||
| facet_fields: { database: facetFields }, | ||
| facet_dates: {}, | ||
| facet_ranges: {}, | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| var fullFacetFields = [ | ||
| 'astronomy', | ||
| 5000, | ||
| 'astrophysics', | ||
| 4800, | ||
| 'physics', | ||
| 1200, | ||
| 'planetary', | ||
| 900, | ||
| 'heliophysics', | ||
| 700, | ||
| 'general', | ||
| 300, | ||
| 'earthscience', | ||
| 100, | ||
| ]; | ||
|
|
||
| var getPreprocessors = function(widget) { | ||
| var preprocessors = widget.store.getState().config.preprocessors; | ||
| return _.isFunction(preprocessors) ? [preprocessors] : preprocessors; | ||
| }; | ||
|
|
||
| var runPreprocessors = function(widget, facetList) { | ||
| return _.reduce( | ||
| getPreprocessors(widget), | ||
| function(list, fn) { | ||
| return fn(list); | ||
| }, | ||
| facetList | ||
| ); | ||
| }; | ||
|
|
||
| it('shows only the classic ADS collections', function() { | ||
| var widget = DatabaseFacet(); | ||
| widget.store.dispatch(Actions().data_received(makeResponse(fullFacetFields))); | ||
|
|
||
| expect(widget.store.getState().children).to.eql(['astronomy', 'physics', 'general']); | ||
| }); | ||
|
|
||
| it('drops SciX collections from the rendered facet list', function() { | ||
| var widget = DatabaseFacet(); | ||
| widget.store.dispatch(Actions().data_received(makeResponse(fullFacetFields))); | ||
|
|
||
| var state = widget.store.getState(); | ||
| _.each(['astrophysics', 'planetary', 'heliophysics', 'earthscience'], function(value) { | ||
| expect(state.facets[value]).to.equal(undefined); | ||
| }); | ||
| }); | ||
|
|
||
| it('preserves the counts of the collections it keeps', function() { | ||
| var widget = DatabaseFacet(); | ||
| widget.store.dispatch(Actions().data_received(makeResponse(fullFacetFields))); | ||
|
|
||
| var facets = widget.store.getState().facets; | ||
| expect(facets.astronomy.count).to.eql(5000); | ||
| expect(facets.physics.count).to.eql(1200); | ||
| expect(facets.general.count).to.eql(300); | ||
| }); | ||
|
|
||
| it('is an allowlist, so an unknown collection is not shown', function() { | ||
| var widget = DatabaseFacet(); | ||
| var filtered = runPreprocessors(widget, [ | ||
| { value: 'astronomy', name: 'astronomy', count: 1 }, | ||
| { value: 'brand_new_scix_collection', name: 'brand_new_scix_collection', count: 1 }, | ||
| ]); | ||
|
|
||
| expect(_.pluck(filtered, 'value')).to.eql(['astronomy']); | ||
| }); | ||
|
|
||
| it('handles an empty facet list', function() { | ||
| var widget = DatabaseFacet(); | ||
| expect(runPreprocessors(widget, [])).to.eql([]); | ||
| }); | ||
|
|
||
| it('marks pagination finished so the "more" button stays hidden', function() { | ||
| var widget = DatabaseFacet(); | ||
| widget.store.dispatch(Actions().data_received(makeResponse(fullFacetFields, '20'))); | ||
|
|
||
| expect(widget.store.getState().pagination.finished).to.eql(true); | ||
| }); | ||
|
|
||
| it('leaves a filter on a hidden collection untouched in the outgoing query', function() { | ||
| var widget = DatabaseFacet(); | ||
| var query = new ApiQuery({ | ||
| q: 'star', | ||
| fq: ['{!type=aqp v=$fq_database}'], | ||
| fq_database: ['(database:astrophysics OR database:planetary)'], | ||
| }); | ||
|
|
||
| widget.store.dispatch(Actions().data_received(makeResponse(fullFacetFields))); | ||
| var outgoing = widget.customizeQuery(query); | ||
|
|
||
| expect(outgoing.get('fq')).to.eql(['{!type=aqp v=$fq_database}']); | ||
| expect(outgoing.get('fq_database')).to.eql(['(database:astrophysics OR database:planetary)']); | ||
| expect(outgoing.get('q')).to.eql(['star']); | ||
| }); | ||
|
|
||
| it('computes pagination.finished from the raw bucket count, not the filtered list', function() { | ||
| var widget = DatabaseFacet(); | ||
| var fullPage = []; | ||
| _.times(20, function(i) { | ||
| fullPage.push(i === 0 ? 'astronomy' : 'scix_collection_' + i, 100 - i); | ||
| }); | ||
|
|
||
| widget.store.dispatch(Actions().data_received(makeResponse(fullPage, '20'))); | ||
|
|
||
| var state = widget.store.getState(); | ||
| expect(state.children).to.eql(['astronomy']); | ||
| expect(state.pagination.finished).to.eql(false); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.