Skip to content

Commit

Permalink
feat(ui): Delete affiliations to exclude in more filters, see #13
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Oct 20, 2023
1 parent e4beee8 commit f69b4c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 35 deletions.
34 changes: 10 additions & 24 deletions client/src/pages/home/filters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default function Filters({ sendQuery }) {
if (searchParams.size === 0) {
setSearchParams({
affiliations: [],
affiliationsToExclude: [],
affiliationsToInclude: [],
dataIdentifiers: identifiers,
datasources: sources.map((source) => source.key),
Expand All @@ -38,7 +37,6 @@ export default function Filters({ sendQuery }) {
} else {
setCurrentSearchParams({
affiliations: searchParams.getAll('affiliations'),
affiliationsToExclude: searchParams.getAll('affiliationsToExclude'),
affiliationsToInclude: searchParams.getAll('affiliationsToInclude'),
dataIdentifiers: searchParams.getAll('dataIdentifiers'),
datasources: searchParams.getAll('datasources'),
Expand Down Expand Up @@ -113,28 +111,16 @@ export default function Filters({ sendQuery }) {
</Row>
{
currentSearchParams.moreOptions && (
<>
<Row gutters>
<Col n="5">
<TagInput
hint="All these affiliations must be present, AND operator"
label="Affiliations to include mandatory"
onTagsChange={(affiliationsToInclude) => setSearchParams({ ...currentSearchParams, affiliationsToInclude })}
tags={currentSearchParams.affiliationsToInclude}
/>
</Col>
</Row>
<Row gutters>
<Col n="5">
<TagInput
hint="None of these affiliations must be present, AND operator"
label="Affiliations to exclude"
onTagsChange={(affiliationsToExclude) => setSearchParams({ ...currentSearchParams, affiliationsToExclude })}
tags={currentSearchParams.affiliationsToExclude}
/>
</Col>
</Row>
</>
<Row gutters>
<Col n="5">
<TagInput
hint="All these affiliations must be present, AND operator"
label="Affiliations to include mandatory"
onTagsChange={(affiliationsToInclude) => setSearchParams({ ...currentSearchParams, affiliationsToInclude })}
tags={currentSearchParams.affiliationsToInclude}
/>
</Col>
</Row>
)
}
<Row gutters alignItems="bottom">
Expand Down
7 changes: 2 additions & 5 deletions client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,18 @@ const getRorAffiliations = (affiliations) => {
const getData = async (options) => {
const promises = [getBsoPublications({ options, index: VITE_BSO_PUBLICATIONS_INDEX })];
const { notRorAffiliations, rorAffiliations } = getRorAffiliations(options.affiliations);
const { notRorAffiliations: notRorAffiliationsToExclude, rorAffiliations: rorAffiliationsToExclude } = getRorAffiliations(options.affiliationsToExclude);
const { notRorAffiliations: notRorAffiliationsToInclude, rorAffiliations: rorAffiliationsToInclude } = getRorAffiliations(options.affiliationsToInclude);
if (notRorAffiliations.length || notRorAffiliationsToExclude.length || notRorAffiliationsToInclude.length) {
if (notRorAffiliations.length || notRorAffiliationsToInclude.length) {
promises.push(getOpenAlexPublications({
...options,
affiliations: notRorAffiliations,
affiliationsToExclude: notRorAffiliationsToExclude,
affiliationsToInclude: notRorAffiliationsToInclude,
}, false));
}
if (rorAffiliations.length || rorAffiliationsToExclude.length || rorAffiliationsToInclude.length) {
if (rorAffiliations.length || rorAffiliationsToInclude.length) {
promises.push(getOpenAlexPublications({
...options,
affiliations: rorAffiliations,
affiliationsToExclude: rorAffiliationsToExclude,
affiliationsToInclude: rorAffiliationsToInclude,
}, true));
}
Expand Down
7 changes: 1 addition & 6 deletions client/src/utils/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const getBsoQuery = (options, pit, searchAfter) => {
options.affiliations.forEach((affiliation) => {
query.query.bool.should.push({ multi_match: { fields: affiliationsFields, query: `"${affiliation}"`, operator: 'and' } });
});
options.affiliationsToExclude.forEach((affiliationToExclude) => {
query.query.bool.must_not.push({ multi_match: { fields: affiliationsFields, query: affiliationToExclude, operator: 'and' } });
});
options.affiliationsToInclude.forEach((affiliationToInclude) => {
query.query.bool.must.push({ multi_match: { fields: affiliationsFields, query: `"${affiliationToInclude}"`, operator: 'and' } });
});
Expand Down Expand Up @@ -212,16 +209,14 @@ const getOpenAlexPublications = (options, isRor = false, page = '1', previousRes
} else if (options?.endYear) {
url += `,publication_year:-${Number(options.endYear)}`;
}
if (options.affiliations.length || options.affiliationsToExclude.length || options.affiliationsToInclude.length) {
if (options.affiliations.length || options.affiliationsToInclude.length) {
if (isRor) {
url += '';
if (options.affiliations.length) url += `,institutions.ror:${options.affiliations.join('|')}`;
if (options.affiliationsToExclude.length) url += options.affiliationsToExclude.map((affiliation) => `,institutions.ror:!${affiliation}`).join('');
if (options.affiliationsToInclude.length) url += options.affiliationsToInclude.map((affiliation) => `,institutions.ror:${affiliation}`).join('');
} else {
url += ',raw_affiliation_string.search:';
if (options.affiliations.length) url += `(${options.affiliations.map((aff) => `"${aff}"`).join(' OR ')})`;
if (options.affiliationsToExclude.length) url += `${options.affiliationsToExclude.map((aff) => ` AND NOT ${aff}`).join('')}`;
if (options.affiliationsToInclude.length) url += `${options.affiliationsToInclude.map((aff) => ` AND "${aff}"`).join('')}`;
}
}
Expand Down

0 comments on commit f69b4c3

Please sign in to comment.