@@ -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
131125const 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 "" ;
0 commit comments