Skip to content

Commit 6dcf1ef

Browse files
committed
added "pdf" keyword support in search
1 parent 5493d0c commit 6dcf1ef

4 files changed

Lines changed: 50 additions & 44 deletions

File tree

vis/js/templates/listentry/PaperButtons.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { connect } from "react-redux";
44
import useMatomo from "../../utils/useMatomo";
55
import { getPaperPDFClickHandler } from "../../utils/data";
66
import { mapDispatchToListEntriesProps } from "../../utils/eventhandlers";
7+
import Highlight from "../../components/Highlight";
78

89
const PaperButtons = ({ paper, handlePDFClick }) => {
910
const { trackEvent } = useMatomo();
@@ -20,7 +21,7 @@ const PaperButtons = ({ paper, handlePDFClick }) => {
2021
<div className="paper_buttons_row">
2122
{!!onPDFClick && (
2223
<button className="paper_button" onClick={handlePDFButtonClick}>
23-
<i className="fa fa-eye"></i>&nbsp;&nbsp;PDF
24+
<i className="fa fa-eye"></i>&nbsp;&nbsp;<Highlight>PDF</Highlight>
2425
</button>
2526
)}
2627
</div>

vis/js/utils/data.js

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,54 +83,48 @@ const getParamFilterFunction = (param, field) => {
8383
};
8484
};
8585

86+
const SEARCHED_PROPS = [
87+
"title",
88+
"authors_string",
89+
"published_in",
90+
"year",
91+
"subject_orig",
92+
"tags",
93+
"comments_for_filtering",
94+
"resulttype",
95+
"paper_abstract",
96+
];
97+
8698
/**
8799
* Creates a paper filtering function from the search words.
88100
*
89-
* Function taken from legacy list.js
90-
* @param {Array} search_words array of search words (plaintext strings)
101+
* @param {Array} searchedKeywords array of search keywords (plaintext strings)
91102
*
92-
* @returns {Function} filtering function
103+
* @returns {Function} filtering function that returns true if paper contains all the searched keywords
93104
*/
94-
const getWordFilterFunction = (search_words) => {
95-
return (d) => {
96-
const abstract = getPropertyOrEmptyString(d, "paper_abstract");
97-
const title = getPropertyOrEmptyString(d, "title");
98-
const authors = getPropertyOrEmptyString(d, "authors_string");
99-
const journals = getPropertyOrEmptyString(d, "published_in");
100-
const year = getPropertyOrEmptyString(d, "year");
101-
const keywords = getPropertyOrEmptyString(d, "subject_orig");
102-
const tags = getPropertyOrEmptyString(d, "tags");
103-
const comments = getPropertyOrEmptyString(d, "comments_for_filtering");
104-
const resulttype = getPropertyOrEmptyString(d, "resulttype");
105-
// TODO: make these two properties language-aware
106-
const open_access = d.oa ? "open access" : "";
107-
const free_access = d.free_access ? "free access" : "";
108-
109-
let i = 0;
110-
let word_found = true;
111-
while (word_found && i < search_words.length) {
112-
word_found =
113-
abstract.indexOf(search_words[i]) !== -1 ||
114-
title.indexOf(search_words[i]) !== -1 ||
115-
authors.indexOf(search_words[i]) !== -1 ||
116-
journals.indexOf(search_words[i]) !== -1 ||
117-
year.indexOf(search_words[i]) !== -1 ||
118-
keywords.indexOf(search_words[i]) !== -1 ||
119-
tags.indexOf(search_words[i]) !== -1 ||
120-
comments.indexOf(search_words[i]) !== -1 ||
121-
resulttype.indexOf(search_words[i]) !== -1 ||
122-
open_access.indexOf(search_words[i]) !== -1 ||
123-
free_access.indexOf(search_words[i]) !== -1;
124-
i++;
105+
const getWordFilterFunction = (searchedKeywords) => {
106+
return (paper) => {
107+
const paperKeywords = SEARCHED_PROPS.map((prop) =>
108+
getPropertyOrEmptyString(paper, prop)
109+
);
110+
111+
if (paper.oa) {
112+
paperKeywords.push("open access");
113+
paperKeywords.push("pdf");
125114
}
115+
if (paper.free_access) {
116+
paperKeywords.push("free access");
117+
}
118+
119+
const paperString = paperKeywords.join(" ");
126120

127-
return word_found;
121+
return !searchedKeywords.some((keyword) => !paperString.includes(keyword));
128122
};
129123
};
130124

131125
const getPropertyOrEmptyString = (object, property) => {
132126
if (Object.prototype.hasOwnProperty.call(object, property)) {
133-
return object[property].toString().toLowerCase();
127+
return object[property].toString().toLowerCase().trim();
134128
}
135129

136130
return "";

vis/stylesheets/components/_buttons.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ img#close-button {
177177
width: 100px;
178178
font-weight: normal;
179179

180+
.highlighted {
181+
color: $okm-red;
182+
}
183+
180184
&:hover {
181185
color: $okm-red;
182186
background-color: white;

vis/test/snapshot/__snapshots__/list-base.test.js.snap

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-in, p
435435
<i
436436
className="fa fa-eye"
437437
/>
438-
  PDF
438+
  
439+
PDF
439440
</button>
440441
</div>
441442
<div
@@ -865,7 +866,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
865866
<i
866867
className="fa fa-eye"
867868
/>
868-
  PDF
869+
  
870+
PDF
869871
</button>
870872
</div>
871873
<div
@@ -1150,7 +1152,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
11501152
<i
11511153
className="fa fa-eye"
11521154
/>
1153-
  PDF
1155+
  
1156+
PDF
11541157
</button>
11551158
</div>
11561159
<div
@@ -1567,7 +1570,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
15671570
<i
15681571
className="fa fa-eye"
15691572
/>
1570-
  PDF
1573+
  
1574+
PDF
15711575
</button>
15721576
</div>
15731577
<div
@@ -2776,7 +2780,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
27762780
<i
27772781
className="fa fa-eye"
27782782
/>
2779-
  PDF
2783+
  
2784+
PDF
27802785
</button>
27812786
</div>
27822787
<div
@@ -3041,7 +3046,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
30413046
<i
30423047
className="fa fa-eye"
30433048
/>
3044-
  PDF
3049+
  
3050+
PDF
30453051
</button>
30463052
</div>
30473053
<div
@@ -3317,7 +3323,8 @@ exports[`List entries component snapshot (BASE) matches a snapshot (zoomed-out)
33173323
<i
33183324
className="fa fa-eye"
33193325
/>
3320-
  PDF
3326+
  
3327+
PDF
33213328
</button>
33223329
</div>
33233330
<div

0 commit comments

Comments
 (0)