From e5fca671ab27a6bbe239c480e4f23a8ee7934191 Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Fri, 6 Nov 2020 21:06:09 +0100 Subject: [PATCH 1/8] Add paged fetchers and complex search paged fetchers --- .../importer/PagedSearchBasedFetcher.java | 12 ++- .../PagedSearchBasedParserFetcher.java | 69 ++++++++++++++-- .../jabref/logic/importer/fetcher/ArXiv.java | 24 +++++- .../fetcher/AstrophysicsDataSystem.java | 11 ++- .../logic/importer/fetcher/GoogleScholar.java | 79 +++++++++++-------- .../jabref/logic/importer/fetcher/IEEE.java | 38 +++++++-- .../importer/fetcher/SpringerFetcher.java | 26 ++++-- .../logic/importer/fetcher/ArXivTest.java | 17 ++++ .../importer/fetcher/GoogleScholarTest.java | 17 ++++ .../logic/importer/fetcher/IEEETest.java | 16 ++++ .../importer/fetcher/SpringerFetcherTest.java | 16 ++++ 11 files changed, 261 insertions(+), 64 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java index 4532ed42f2b..54176d4fce3 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java @@ -1,5 +1,6 @@ package org.jabref.logic.importer; +import org.jabref.logic.importer.fetcher.ComplexSearchQuery; import org.jabref.model.entry.BibEntry; import org.jabref.model.paging.Page; @@ -7,11 +8,20 @@ public interface PagedSearchBasedFetcher extends SearchBasedFetcher { /** * @param query search query send to endpoint - * @param pageNumber requested site number + * @param pageNumber requested site number indexed from 0 * @return Page with search results */ Page performSearchPaged(String query, int pageNumber) throws FetcherException; + /** + * @param query search query send to endpoint + * @param pageNumber requested site number indexed from 0 + * @return Page with search results + */ + default Page performComplexSearchPaged(ComplexSearchQuery query, int pageNumber) throws FetcherException { + return performSearchPaged(query.toString(), pageNumber); + } + /** * @return default pageSize */ diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java index d825d82c013..13e5f5cc7d9 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java @@ -1,16 +1,75 @@ package org.jabref.logic.importer; +import java.io.IOException; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; +import java.util.Collections; +import java.util.List; + +import org.jabref.logic.importer.fetcher.ComplexSearchQuery; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.paging.Page; +import org.jabref.model.strings.StringUtil; public interface PagedSearchBasedParserFetcher extends SearchBasedParserFetcher, PagedSearchBasedFetcher { + @Override + default Page performSearchPaged(String query, int pageNumber) throws FetcherException { + if (StringUtil.isBlank(query)) { + return new Page(query, pageNumber, Collections.emptyList()); + } + + // ADR-0014 + URL urlForQuery; + try { + urlForQuery = getURLForQuery(query, pageNumber); + } catch (URISyntaxException | MalformedURLException e) { + throw new FetcherException(String.format("Search URI crafted from query %s is malformed", query), e); + } + return new Page<>(query, pageNumber, getBibEntries(urlForQuery)); + } + + private List getBibEntries(URL urlForQuery) throws FetcherException { + try (InputStream stream = getUrlDownload(urlForQuery).asInputStream()) { + List fetchedEntries = getParser().parseEntries(stream); + fetchedEntries.forEach(this::doPostCleanup); + return fetchedEntries; + } catch (IOException e) { + throw new FetcherException("A network error occurred while fetching from " + urlForQuery, e); + } catch (ParseException e) { + throw new FetcherException("An internal parser error occurred while fetching from " + urlForQuery, e); + } + } + + @Override + default Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { + // ADR-0014 + URL urlForQuery; + try { + urlForQuery = getComplexQueryURL(complexSearchQuery, pageNumber); + } catch (URISyntaxException | MalformedURLException e) { + throw new FetcherException("Search URI crafted from complex search query is malformed", e); + } + return new Page<>(complexSearchQuery.toString(), pageNumber, getBibEntries(urlForQuery)); + } + + /** + * Constructs a URL based on the query, size and page number. + * + * @param query the search query + * @param pageNumber the number of the page indexed from 0 + */ + URL getURLForQuery(String query, int pageNumber) throws URISyntaxException, MalformedURLException; + /** * Constructs a URL based on the query, size and page number. - * @param query the search query - * @param size the size of the page - * @param pageNumber the number of the page - * */ - URL getURLForQuery(String query, int size, int pageNumber) throws URISyntaxException, MalformedURLException, FetcherException; + * + * @param complexSearchQuery the search query + * @param pageNumber the number of the page indexed from 0 + */ + default URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery, int pageNumber) throws URISyntaxException, MalformedURLException { + return getURLForQuery(complexSearchQuery.toString(), pageNumber); + } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java index 58c6bbc7498..fa163d110ca 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java @@ -22,7 +22,7 @@ import org.jabref.logic.importer.IdBasedFetcher; import org.jabref.logic.importer.IdFetcher; import org.jabref.logic.importer.ImportFormatPreferences; -import org.jabref.logic.importer.SearchBasedFetcher; +import org.jabref.logic.importer.PagedSearchBasedFetcher; import org.jabref.logic.util.io.XMLUtil; import org.jabref.logic.util.strings.StringSimilarity; import org.jabref.model.entry.BibEntry; @@ -31,6 +31,7 @@ import org.jabref.model.entry.identifier.ArXivIdentifier; import org.jabref.model.entry.identifier.DOI; import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.model.paging.Page; import org.jabref.model.strings.StringUtil; import org.jabref.model.util.OptionalUtil; @@ -52,7 +53,7 @@ * arxiv2bib which is live * dspace-portalmec */ -public class ArXiv implements FulltextFetcher, SearchBasedFetcher, IdBasedFetcher, IdFetcher { +public class ArXiv implements FulltextFetcher, PagedSearchBasedFetcher, IdBasedFetcher, IdFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(ArXiv.class); @@ -157,6 +158,10 @@ private List searchForEntries(String searchQuery) throws FetcherExce return queryApi(searchQuery, Collections.emptyList(), 0, 10); } + private List searchForEntries(String searchQuery, int pageNumber) throws FetcherException { + return queryApi(searchQuery, Collections.emptyList(), getPageSize() * pageNumber, getPageSize()); + } + private List queryApi(String searchQuery, List ids, int start, int maxResults) throws FetcherException { Document result = callApi(searchQuery, ids, start, maxResults); @@ -263,6 +268,19 @@ public List performSearch(String query) throws FetcherException { */ @Override public List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { + return new ArrayList<>(performComplexSearchPaged(complexSearchQuery, 0).getContent()); + } + + @Override + public Page performSearchPaged(String query, int pageNumber) throws FetcherException { + List searchResult = searchForEntries(query, pageNumber).stream() + .map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator())) + .collect(Collectors.toList()); + return new Page<>(query, pageNumber, searchResult); + } + + @Override + public Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { List searchTerms = new ArrayList<>(); complexSearchQuery.getAuthors().forEach(author -> searchTerms.add("au:" + author)); complexSearchQuery.getTitlePhrases().forEach(title -> searchTerms.add("ti:" + title)); @@ -271,7 +289,7 @@ public List performComplexSearch(ComplexSearchQuery complexSearchQuery complexSearchQuery.getToYear().ifPresent(year -> searchTerms.add(year.toString())); searchTerms.addAll(complexSearchQuery.getDefaultFieldPhrases()); String complexQueryString = String.join(" AND ", searchTerms); - return performSearch(complexQueryString); + return performSearchPaged(complexQueryString, pageNumber); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java index 93bfd874622..6603bd482ec 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java @@ -91,12 +91,12 @@ public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLE } @Override - public URL getURLForQuery(String query, int size, int pageNumber) throws URISyntaxException, MalformedURLException, FetcherException { + public URL getURLForQuery(String query, int pageNumber) throws URISyntaxException, MalformedURLException { URIBuilder builder = new URIBuilder(API_SEARCH_URL); builder.addParameter("q", query); builder.addParameter("fl", "bibcode"); - builder.addParameter("rows", String.valueOf(size)); - builder.addParameter("start", String.valueOf(size * pageNumber)); + builder.addParameter("rows", String.valueOf(getPageSize())); + builder.addParameter("start", String.valueOf(getPageSize() * pageNumber)); return builder.build().toURL(); } @@ -105,7 +105,7 @@ public URL getURLForQuery(String query, int size, int pageNumber) throws URISynt * @return URL which points to a search request for given entry */ @Override - public URL getURLForEntry(BibEntry entry) throws URISyntaxException, MalformedURLException, FetcherException { + public URL getURLForEntry(BibEntry entry) throws URISyntaxException, MalformedURLException { StringBuilder stringBuilder = new StringBuilder(); Optional title = entry.getFieldOrAlias(StandardField.TITLE).map(t -> "title:\"" + t + "\""); @@ -300,12 +300,11 @@ private List performSearchByIds(Collection identifiers) throws @Override public Page performSearchPaged(String query, int pageNumber) throws FetcherException { - if (StringUtil.isBlank(query)) { return new Page<>(query, pageNumber); } try { - List bibcodes = fetchBibcodes(getURLForQuery(query, getPageSize(), pageNumber)); + List bibcodes = fetchBibcodes(getURLForQuery(query, pageNumber)); Collection results = performSearchByIds(bibcodes); return new Page<>(query, pageNumber, results); } catch (URISyntaxException e) { diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java index a35e1353373..ee6bf78529e 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java @@ -17,13 +17,14 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.FulltextFetcher; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.PagedSearchBasedFetcher; import org.jabref.logic.importer.ParserResult; -import org.jabref.logic.importer.SearchBasedFetcher; import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.l10n.Localization; import org.jabref.logic.net.URLDownload; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; +import org.jabref.model.paging.Page; import org.jabref.model.util.DummyFileUpdateMonitor; import org.apache.http.client.utils.URIBuilder; @@ -38,7 +39,7 @@ *

* Search String infos: https://scholar.google.com/intl/en/scholar/help.html#searching */ -public class GoogleScholar implements FulltextFetcher, SearchBasedFetcher { +public class GoogleScholar implements FulltextFetcher, PagedSearchBasedFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(GoogleScholar.class); private static final Pattern LINK_TO_BIB_PATTERN = Pattern.compile("(https:\\/\\/scholar.googleusercontent.com\\/scholar.bib[^\"]*)"); @@ -128,37 +129,7 @@ public Optional getHelpPage() { @Override public List performSearch(String query) throws FetcherException { - LOGGER.debug("Using URL {}", query); - obtainAndModifyCookie(); - List foundEntries = new ArrayList<>(20); - - URIBuilder uriBuilder = null; - try { - uriBuilder = new URIBuilder(BASIC_SEARCH_URL); - } catch (URISyntaxException e) { - throw new FetcherException("Error while fetching from " + getName() + " at URL " + BASIC_SEARCH_URL, e); - } - - uriBuilder.addParameter("hl", "en"); - uriBuilder.addParameter("btnG", "Search"); - uriBuilder.addParameter("q", query); - String queryURL = uriBuilder.toString(); - - try { - addHitsFromQuery(foundEntries, queryURL); - } catch (IOException e) { - // if there are too much requests from the same IP address google is answering with a 503 and redirecting to a captcha challenge - // The caught IOException looks for example like this: - // java.io.IOException: Server returned HTTP response code: 503 for URL: https://ipv4.google.com/sorry/index?continue=https://scholar.google.com/scholar%3Fhl%3Den%26btnG%3DSearch%26q%3Dbpmn&hl=en&q=CGMSBI0NBDkYuqy9wAUiGQDxp4NLQCWbIEY1HjpH5zFJhv4ANPGdWj0 - if (e.getMessage().contains("Server returned HTTP response code: 503 for URL")) { - throw new FetcherException("Fetching from Google Scholar at URL " + queryURL + " failed.", - Localization.lang("This might be caused by reaching the traffic limitation of Google Scholar (see 'Help' for details)."), e); - } else { - throw new FetcherException("Error while fetching from " + getName() + " at URL " + queryURL, e); - } - } - - return foundEntries; + return new ArrayList<>(performSearchPaged(query, 0).getContent()); } @Override @@ -259,4 +230,46 @@ private void obtainAndModifyCookie() throws FetcherException { throw new FetcherException("Cookie configuration for Google Scholar failed.", e); } } + + @Override + public Page performSearchPaged(String query, int pageNumber) throws FetcherException { + LOGGER.debug("Using URL {}", query); + obtainAndModifyCookie(); + List foundEntries = new ArrayList<>(20); + + URIBuilder uriBuilder = null; + try { + uriBuilder = new URIBuilder(BASIC_SEARCH_URL); + } catch (URISyntaxException e) { + throw new FetcherException("Error while fetching from " + getName() + " at URL " + BASIC_SEARCH_URL, e); + } + + uriBuilder.addParameter("hl", "en"); + uriBuilder.addParameter("start", String.valueOf(pageNumber * getPageSize())); + uriBuilder.addParameter("num", String.valueOf(getPageSize())); + uriBuilder.addParameter("btnG", "Search"); + uriBuilder.addParameter("q", query); + String queryURL = uriBuilder.toString(); + + try { + addHitsFromQuery(foundEntries, queryURL); + } catch (IOException e) { + // if there are too much requests from the same IP address google is answering with a 503 and redirecting to a captcha challenge + // The caught IOException looks for example like this: + // java.io.IOException: Server returned HTTP response code: 503 for URL: https://ipv4.google.com/sorry/index?continue=https://scholar.google.com/scholar%3Fhl%3Den%26btnG%3DSearch%26q%3Dbpmn&hl=en&q=CGMSBI0NBDkYuqy9wAUiGQDxp4NLQCWbIEY1HjpH5zFJhv4ANPGdWj0 + if (e.getMessage().contains("Server returned HTTP response code: 503 for URL")) { + throw new FetcherException("Fetching from Google Scholar at URL " + queryURL + " failed.", + Localization.lang("This might be caused by reaching the traffic limitation of Google Scholar (see 'Help' for details)."), e); + } else { + throw new FetcherException("Error while fetching from " + getName() + " at URL " + queryURL, e); + } + } + + return new Page<>(query, pageNumber, foundEntries); + } + + @Override + public Page performComplexSearchPaged(ComplexSearchQuery query, int pageNumber) throws FetcherException { + return null; + } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java index 2b1b0a0f33e..d2754eb9e52 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java @@ -15,8 +15,10 @@ import java.util.stream.Collectors; import org.jabref.logic.help.HelpFile; +import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.FulltextFetcher; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.PagedSearchBasedParserFetcher; import org.jabref.logic.importer.Parser; import org.jabref.logic.importer.SearchBasedParserFetcher; import org.jabref.logic.net.URLDownload; @@ -27,6 +29,7 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.identifier.DOI; import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.model.paging.Page; import kong.unirest.json.JSONArray; import kong.unirest.json.JSONObject; @@ -41,7 +44,7 @@ * * @implNote API documentation */ -public class IEEE implements FulltextFetcher, SearchBasedParserFetcher { +public class IEEE implements FulltextFetcher, PagedSearchBasedParserFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(IEEE.class); private static final String STAMP_BASE_STRING_DOCUMENT = "/stamp/stamp.jsp?tp=&arnumber="; @@ -193,13 +196,7 @@ public TrustLevel getTrustLevel() { @Override public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException { - URIBuilder uriBuilder = new URIBuilder("https://ieeexploreapi.ieee.org/api/v1/search/articles"); - uriBuilder.addParameter("apikey", API_KEY); - uriBuilder.addParameter("querytext", query); - - URLDownload.bypassSSLVerification(); - - return uriBuilder.build().toURL(); + return getURLForQuery(query, 0); } @Override @@ -234,8 +231,31 @@ public Optional getHelpPage() { @Override public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery) throws URISyntaxException, MalformedURLException { + return getComplexQueryURL(complexSearchQuery, 0); + } + + @Override + public URL getURLForQuery(String query, int pageNumber) throws URISyntaxException, MalformedURLException { URIBuilder uriBuilder = new URIBuilder("https://ieeexploreapi.ieee.org/api/v1/search/articles"); uriBuilder.addParameter("apikey", API_KEY); + uriBuilder.addParameter("querytext", query); + uriBuilder.addParameter("max_records", String.valueOf(getPageSize())); + // Starts to index at 1 for the first entry + uriBuilder.addParameter("start_record", String.valueOf(getPageSize() * pageNumber) + 1); + + URLDownload.bypassSSLVerification(); + + return uriBuilder.build().toURL(); + } + + @Override + public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery, int pageNumber) throws URISyntaxException, MalformedURLException { + URIBuilder uriBuilder = new URIBuilder("https://ieeexploreapi.ieee.org/api/v1/search/articles"); + uriBuilder.addParameter("apikey", API_KEY); + uriBuilder.addParameter("max_records", String.valueOf(getPageSize())); + // Starts to index at 1 for the first entry + uriBuilder.addParameter("start_record", String.valueOf(getPageSize() * pageNumber) + 1); + if (!complexSearchQuery.getDefaultFieldPhrases().isEmpty()) { uriBuilder.addParameter("querytext", String.join(" AND ", complexSearchQuery.getDefaultFieldPhrases())); } @@ -256,4 +276,6 @@ public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery) throws URIS URLDownload.bypassSSLVerification(); return uriBuilder.build().toURL(); } + + } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java index 2b15fd4eb4e..bb7b4c41f17 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java @@ -11,8 +11,8 @@ import java.util.stream.Collectors; import org.jabref.logic.help.HelpFile; +import org.jabref.logic.importer.PagedSearchBasedParserFetcher; import org.jabref.logic.importer.Parser; -import org.jabref.logic.importer.SearchBasedParserFetcher; import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.OS; import org.jabref.model.entry.BibEntry; @@ -33,7 +33,7 @@ * * @implNote see API documentation for more details */ -public class SpringerFetcher implements SearchBasedParserFetcher { +public class SpringerFetcher implements PagedSearchBasedParserFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(SpringerFetcher.class); @@ -159,12 +159,7 @@ public Optional getHelpPage() { @Override public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException { - URIBuilder uriBuilder = new URIBuilder(API_URL); - uriBuilder.addParameter("q", query); // Search query - uriBuilder.addParameter("api_key", API_KEY); // API key - uriBuilder.addParameter("p", "20"); // Number of results to return - // uriBuilder.addParameter("s", "1"); // Start item (not needed at the moment) - return uriBuilder.build().toURL(); + return getURLForQuery(query, 0); } @Override @@ -202,4 +197,19 @@ public Parser getParser() { return entries; }; } + + @Override + public URL getURLForQuery(String query, int pageNumber) throws URISyntaxException, MalformedURLException { + URIBuilder uriBuilder = new URIBuilder(API_URL); + uriBuilder.addParameter("q", query); // Search query + uriBuilder.addParameter("api_key", API_KEY); // API key + uriBuilder.addParameter("s", String.valueOf(getPageSize() * pageNumber + 1)); // Start entry, starts indexing at 1 + uriBuilder.addParameter("p", String.valueOf(getPageSize())); // Page size + return uriBuilder.build().toURL(); + } + + @Override + public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery, int pageNumber) throws URISyntaxException, MalformedURLException { + return getURLForQuery(constructComplexQueryString(complexSearchQuery), pageNumber); + } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java index 20b0b6e401e..108e683d89d 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java @@ -9,10 +9,12 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.SearchBasedFetcher; +import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.identifier.ArXivIdentifier; import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.model.paging.Page; import org.jabref.testutils.category.FetcherTest; import org.junit.jupiter.api.BeforeEach; @@ -20,6 +22,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; @@ -284,6 +287,20 @@ public void supportsPhraseSearchAndMatchesExact() throws Exception { assertEquals(Collections.singletonList(expected), resultWithPhraseSearch); } + /** + * Ensure that different page return different entries + */ + @Test + public void pageSearchReturnsUniqueResultsPerPage() throws Exception { + String query = "Software"; + Page firstPage = fetcher.performSearchPaged(query, 0); + Page secondPage = fetcher.performSearchPaged(query, 1); + + for (BibEntry entry: firstPage.getContent()) { + assertFalse(secondPage.getContent().contains(entry)); + } + } + @Test public void supportsBooleanANDSearch() throws Exception { BibEntry expected = new BibEntry(StandardEntryType.Article) diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java index 9c0ef78b411..7a221607f94 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java @@ -13,6 +13,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.model.paging.Page; import org.jabref.support.DisabledOnCIServer; import org.jabref.testutils.category.FetcherTest; @@ -20,6 +21,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -81,6 +83,21 @@ void findManyEntries() throws FetcherException { assertEquals(20, foundEntries.size()); } + /** + * Ensure that different page return different entries + */ + @Test + @DisabledOnCIServer("CI server is blocked by Google") + public void pageSearchReturnsUniqueResultsPerPage() throws Exception { + String query = "Software"; + Page firstPage = finder.performSearchPaged(query, 0); + Page secondPage = finder.performSearchPaged(query, 1); + + for (BibEntry entry: firstPage.getContent()) { + assertFalse(secondPage.getContent().contains(entry)); + } + } + @Override public SearchBasedFetcher getFetcher() { return finder; diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java b/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java index 9aab79989ba..b8ba64e81d5 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java @@ -10,12 +10,14 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.model.paging.Page; import org.jabref.testutils.category.FetcherTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -125,6 +127,20 @@ void searchByQueryFindsEntry() throws Exception { assertEquals(Collections.singletonList(expected), fetchedEntries); } + /** + * Ensure that different page return different entries + */ + @Test + public void pageSearchReturnsUniqueResultsPerPage() throws Exception { + String query = "Software"; + Page firstPage = fetcher.performSearchPaged(query, 0); + Page secondPage = fetcher.performSearchPaged(query, 1); + + for (BibEntry entry: firstPage.getContent()) { + assertFalse(secondPage.getContent().contains(entry)); + } + } + @Override public SearchBasedFetcher getFetcher() { return fetcher; diff --git a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java index 9b91714bc06..5e2ba0fae30 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java @@ -9,6 +9,7 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.model.paging.Page; import org.jabref.testutils.category.FetcherTest; import kong.unirest.json.JSONObject; @@ -18,6 +19,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @FetcherTest @@ -132,6 +134,20 @@ public void supportsBooleanANDSearch() throws Exception { .map(Optional::get).forEach(authorField -> assertTrue(authorField.contains("Redmiles"))); } + /** + * Ensure that different page return different entries + */ + @Test + public void pageSearchReturnsUniqueResultsPerPage() throws Exception { + String query = "Software"; + Page firstPage = fetcher.performSearchPaged(query, 0); + Page secondPage = fetcher.performSearchPaged(query, 1); + + for (BibEntry entry: firstPage.getContent()) { + assertFalse(secondPage.getContent().contains(entry)); + } + } + @Override public SearchBasedFetcher getFetcher() { return fetcher; From 1fdbc6d4f9724c4f00e26abd60c0026d9070708f Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Sat, 7 Nov 2020 14:08:24 +0100 Subject: [PATCH 2/8] Fix Checkstyle Signed-off-by: Dominik Voigt --- src/main/java/org/jabref/logic/importer/fetcher/IEEE.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java index ee8eddcbc73..92a10bbdb25 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java @@ -15,12 +15,10 @@ import java.util.stream.Collectors; import org.jabref.logic.help.HelpFile; -import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.FulltextFetcher; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.PagedSearchBasedParserFetcher; import org.jabref.logic.importer.Parser; -import org.jabref.logic.importer.SearchBasedParserFetcher; import org.jabref.logic.net.URLDownload; import org.jabref.logic.util.BuildInfo; import org.jabref.logic.util.OS; @@ -29,7 +27,6 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.identifier.DOI; import org.jabref.model.entry.types.StandardEntryType; -import org.jabref.model.paging.Page; import kong.unirest.json.JSONArray; import kong.unirest.json.JSONObject; @@ -279,6 +276,4 @@ public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery, int pageNum URLDownload.bypassSSLVerification(); return uriBuilder.build().toURL(); } - - } From 215c1772311e6c9e004685e935013bba4f066aab Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Sat, 7 Nov 2020 14:15:10 +0100 Subject: [PATCH 3/8] Fix Checkstyle Signed-off-by: Dominik Voigt --- src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java | 3 +-- .../org/jabref/logic/importer/fetcher/GoogleScholarTest.java | 2 +- .../org/jabref/logic/importer/fetcher/SpringerFetcherTest.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java index 108e683d89d..a623e2e26f1 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java @@ -9,7 +9,6 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.SearchBasedFetcher; -import org.jabref.model.database.BibDatabase; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.identifier.ArXivIdentifier; @@ -296,7 +295,7 @@ public void pageSearchReturnsUniqueResultsPerPage() throws Exception { Page firstPage = fetcher.performSearchPaged(query, 0); Page secondPage = fetcher.performSearchPaged(query, 1); - for (BibEntry entry: firstPage.getContent()) { + for (BibEntry entry : firstPage.getContent()) { assertFalse(secondPage.getContent().contains(entry)); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java index 7a221607f94..c26b8389dc4 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java @@ -93,7 +93,7 @@ public void pageSearchReturnsUniqueResultsPerPage() throws Exception { Page firstPage = finder.performSearchPaged(query, 0); Page secondPage = finder.performSearchPaged(query, 1); - for (BibEntry entry: firstPage.getContent()) { + for (BibEntry entry : firstPage.getContent()) { assertFalse(secondPage.getContent().contains(entry)); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java index 5e2ba0fae30..0eb65994cf5 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java @@ -143,7 +143,7 @@ public void pageSearchReturnsUniqueResultsPerPage() throws Exception { Page firstPage = fetcher.performSearchPaged(query, 0); Page secondPage = fetcher.performSearchPaged(query, 1); - for (BibEntry entry: firstPage.getContent()) { + for (BibEntry entry : firstPage.getContent()) { assertFalse(secondPage.getContent().contains(entry)); } } From 4d862650dcd87cc45344770b73225d78c8dcc2d1 Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Sat, 7 Nov 2020 17:04:02 +0100 Subject: [PATCH 4/8] Make method calls consistent Signed-off-by: Dominik Voigt --- .../jabref/logic/importer/fetcher/ArXiv.java | 8 +- .../fetcher/AstrophysicsDataSystem.java | 14 +-- .../logic/importer/fetcher/GoogleScholar.java | 87 ++++++++++--------- .../importer/fetcher/SpringerFetcher.java | 32 +++---- 4 files changed, 63 insertions(+), 78 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java index 2ad56791d85..c4d66a86bf3 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java @@ -154,10 +154,6 @@ private List searchForEntries(BibEntry entry) throws FetcherExceptio return Collections.emptyList(); } - private List searchForEntries(String searchQuery) throws FetcherException { - return queryApi(searchQuery, Collections.emptyList(), 0, 10); - } - private List searchForEntries(String searchQuery, int pageNumber) throws FetcherException { return queryApi(searchQuery, Collections.emptyList(), getPageSize() * pageNumber, getPageSize()); } @@ -255,9 +251,7 @@ public Optional getHelpPage() { @Override public List performSearch(String query) throws FetcherException { - return searchForEntries(query).stream().map( - (arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator())) - .collect(Collectors.toList()); + return new ArrayList<>(performSearchPaged(query, 0).getContent()); } /** diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java index 6603bd482ec..7e7b6a0d831 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java @@ -194,19 +194,7 @@ public List performSearch(BibEntry entry) throws FetcherException { @Override public List performSearch(String query) throws FetcherException { - - if (StringUtil.isBlank(query)) { - return Collections.emptyList(); - } - - try { - List bibcodes = fetchBibcodes(getURLForQuery(query)); - return performSearchByIds(bibcodes); - } catch (URISyntaxException e) { - throw new FetcherException("Search URI is malformed", e); - } catch (IOException e) { - throw new FetcherException("A network error occurred", e); - } + return new ArrayList<>(performSearchPaged(query, 0).getContent()); } /** diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java index ee6bf78529e..9e44cc0e80f 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java @@ -134,44 +134,7 @@ public List performSearch(String query) throws FetcherException { @Override public List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { - try { - obtainAndModifyCookie(); - List foundEntries = new ArrayList<>(10); - - URIBuilder uriBuilder = new URIBuilder(BASIC_SEARCH_URL); - uriBuilder.addParameter("hl", "en"); - uriBuilder.addParameter("btnG", "Search"); - uriBuilder.addParameter("q", constructComplexQueryString(complexSearchQuery)); - complexSearchQuery.getFromYear().ifPresent(year -> uriBuilder.addParameter("as_ylo", year.toString())); - complexSearchQuery.getToYear().ifPresent(year -> uriBuilder.addParameter("as_yhi", year.toString())); - complexSearchQuery.getSingleYear().ifPresent(year -> { - uriBuilder.addParameter("as_ylo", year.toString()); - uriBuilder.addParameter("as_yhi", year.toString()); - }); - - try { - addHitsFromQuery(foundEntries, uriBuilder.toString()); - - if (foundEntries.size() == 10) { - uriBuilder.addParameter("start", "10"); - addHitsFromQuery(foundEntries, uriBuilder.toString()); - } - } catch (IOException e) { - LOGGER.info("IOException for URL {}", uriBuilder.toString()); - // if there are too much requests from the same IP adress google is answering with a 503 and redirecting to a captcha challenge - // The caught IOException looks for example like this: - // java.io.IOException: Server returned HTTP response code: 503 for URL: https://ipv4.google.com/sorry/index?continue=https://scholar.google.com/scholar%3Fhl%3Den%26btnG%3DSearch%26q%3Dbpmn&hl=en&q=CGMSBI0NBDkYuqy9wAUiGQDxp4NLQCWbIEY1HjpH5zFJhv4ANPGdWj0 - if (e.getMessage().contains("Server returned HTTP response code: 503 for URL")) { - throw new FetcherException("Fetching from Google Scholar failed.", - Localization.lang("This might be caused by reaching the traffic limitation of Google Scholar (see 'Help' for details)."), e); - } else { - throw new FetcherException("Error while fetching from " + getName(), e); - } - } - return foundEntries; - } catch (URISyntaxException e) { - throw new FetcherException("Error while fetching from " + getName(), e); - } + return new ArrayList<>(performComplexSearchPaged(complexSearchQuery, 0).getContent()); } private String constructComplexQueryString(ComplexSearchQuery complexSearchQuery) { @@ -237,7 +200,7 @@ public Page performSearchPaged(String query, int pageNumber) throws Fe obtainAndModifyCookie(); List foundEntries = new ArrayList<>(20); - URIBuilder uriBuilder = null; + URIBuilder uriBuilder; try { uriBuilder = new URIBuilder(BASIC_SEARCH_URL); } catch (URISyntaxException e) { @@ -246,9 +209,9 @@ public Page performSearchPaged(String query, int pageNumber) throws Fe uriBuilder.addParameter("hl", "en"); uriBuilder.addParameter("start", String.valueOf(pageNumber * getPageSize())); + uriBuilder.addParameter("q", query); uriBuilder.addParameter("num", String.valueOf(getPageSize())); uriBuilder.addParameter("btnG", "Search"); - uriBuilder.addParameter("q", query); String queryURL = uriBuilder.toString(); try { @@ -269,7 +232,47 @@ public Page performSearchPaged(String query, int pageNumber) throws Fe } @Override - public Page performComplexSearchPaged(ComplexSearchQuery query, int pageNumber) throws FetcherException { - return null; + public Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { + try { + obtainAndModifyCookie(); + List foundEntries = new ArrayList<>(10); + + String complexQueryString = constructComplexQueryString(complexSearchQuery); + URIBuilder uriBuilder = new URIBuilder(BASIC_SEARCH_URL); + uriBuilder.addParameter("hl", "en"); + uriBuilder.addParameter("btnG", "Search"); + uriBuilder.addParameter("q", complexQueryString); + uriBuilder.addParameter("start", String.valueOf(pageNumber * getPageSize())); + uriBuilder.addParameter("num", String.valueOf(getPageSize())); + complexSearchQuery.getFromYear().ifPresent(year -> uriBuilder.addParameter("as_ylo", year.toString())); + complexSearchQuery.getToYear().ifPresent(year -> uriBuilder.addParameter("as_yhi", year.toString())); + complexSearchQuery.getSingleYear().ifPresent(year -> { + uriBuilder.addParameter("as_ylo", year.toString()); + uriBuilder.addParameter("as_yhi", year.toString()); + }); + + try { + addHitsFromQuery(foundEntries, uriBuilder.toString()); + + if (foundEntries.size() == 10) { + uriBuilder.addParameter("start", "10"); + addHitsFromQuery(foundEntries, uriBuilder.toString()); + } + } catch (IOException e) { + LOGGER.info("IOException for URL {}", uriBuilder.toString()); + // if there are too much requests from the same IP adress google is answering with a 503 and redirecting to a captcha challenge + // The caught IOException looks for example like this: + // java.io.IOException: Server returned HTTP response code: 503 for URL: https://ipv4.google.com/sorry/index?continue=https://scholar.google.com/scholar%3Fhl%3Den%26btnG%3DSearch%26q%3Dbpmn&hl=en&q=CGMSBI0NBDkYuqy9wAUiGQDxp4NLQCWbIEY1HjpH5zFJhv4ANPGdWj0 + if (e.getMessage().contains("Server returned HTTP response code: 503 for URL")) { + throw new FetcherException("Fetching from Google Scholar failed.", + Localization.lang("This might be caused by reaching the traffic limitation of Google Scholar (see 'Help' for details)."), e); + } else { + throw new FetcherException("Error while fetching from " + getName(), e); + } + } + return new Page<>(complexQueryString, pageNumber, foundEntries); + } catch (URISyntaxException e) { + throw new FetcherException("Error while fetching from " + getName(), e); + } } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java index bb7b4c41f17..5c8ced78b2d 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java @@ -164,7 +164,22 @@ public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLE @Override public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery) throws URISyntaxException, MalformedURLException { - return getURLForQuery(constructComplexQueryString(complexSearchQuery)); + return getComplexQueryURL(complexSearchQuery, 0); + } + + @Override + public URL getURLForQuery(String query, int pageNumber) throws URISyntaxException, MalformedURLException { + URIBuilder uriBuilder = new URIBuilder(API_URL); + uriBuilder.addParameter("q", query); // Search query + uriBuilder.addParameter("api_key", API_KEY); // API key + uriBuilder.addParameter("s", String.valueOf(getPageSize() * pageNumber + 1)); // Start entry, starts indexing at 1 + uriBuilder.addParameter("p", String.valueOf(getPageSize())); // Page size + return uriBuilder.build().toURL(); + } + + @Override + public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery, int pageNumber) throws URISyntaxException, MalformedURLException { + return getURLForQuery(constructComplexQueryString(complexSearchQuery), pageNumber); } private String constructComplexQueryString(ComplexSearchQuery complexSearchQuery) { @@ -197,19 +212,4 @@ public Parser getParser() { return entries; }; } - - @Override - public URL getURLForQuery(String query, int pageNumber) throws URISyntaxException, MalformedURLException { - URIBuilder uriBuilder = new URIBuilder(API_URL); - uriBuilder.addParameter("q", query); // Search query - uriBuilder.addParameter("api_key", API_KEY); // API key - uriBuilder.addParameter("s", String.valueOf(getPageSize() * pageNumber + 1)); // Start entry, starts indexing at 1 - uriBuilder.addParameter("p", String.valueOf(getPageSize())); // Page size - return uriBuilder.build().toURL(); - } - - @Override - public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery, int pageNumber) throws URISyntaxException, MalformedURLException { - return getURLForQuery(constructComplexQueryString(complexSearchQuery), pageNumber); - } } From 9a87a5e5845ed534562b2f7cbf9653ace7133a27 Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Wed, 11 Nov 2020 16:15:59 +0100 Subject: [PATCH 5/8] Add test interface for paged fetchers Move common methods into default implementation Signed-off-by: Dominik Voigt --- .../importer/PagedSearchBasedFetcher.java | 13 ++++++++ .../PagedSearchBasedParserFetcher.java | 24 ++++++++++++-- .../jabref/logic/importer/fetcher/ArXiv.java | 20 +++--------- .../fetcher/AstrophysicsDataSystem.java | 13 -------- .../logic/importer/fetcher/GoogleScholar.java | 10 ------ .../jabref/logic/importer/fetcher/IEEE.java | 10 ------ .../importer/fetcher/SpringerFetcher.java | 10 ------ .../logic/importer/fetcher/ArXivTest.java | 20 +++--------- .../fetcher/AstrophysicsDataSystemTest.java | 13 +++----- .../importer/fetcher/GoogleScholarTest.java | 23 ++++---------- .../logic/importer/fetcher/IEEETest.java | 24 +++++--------- .../fetcher/PagedSearchFetcherTest.java | 31 +++++++++++++++++++ .../importer/fetcher/SpringerFetcherTest.java | 24 +++++--------- 13 files changed, 101 insertions(+), 134 deletions(-) create mode 100644 src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java index 54176d4fce3..5bcc8b5c916 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java @@ -1,5 +1,8 @@ package org.jabref.logic.importer; +import java.util.ArrayList; +import java.util.List; + import org.jabref.logic.importer.fetcher.ComplexSearchQuery; import org.jabref.model.entry.BibEntry; import org.jabref.model.paging.Page; @@ -28,4 +31,14 @@ default Page performComplexSearchPaged(ComplexSearchQuery query, int p default int getPageSize() { return 20; } + + @Override + default List performSearch(String query) throws FetcherException { + return new ArrayList<>(performSearchPaged(query, 0).getContent()); + } + + @Override + default List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { + return new ArrayList<>(performComplexSearchPaged(complexSearchQuery, 0).getContent()); + } } diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java index 13e5f5cc7d9..f771696b768 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java @@ -66,10 +66,30 @@ default Page performComplexSearchPaged(ComplexSearchQuery complexSearc /** * Constructs a URL based on the query, size and page number. * - * @param complexSearchQuery the search query - * @param pageNumber the number of the page indexed from 0 + * @param complexSearchQuery the search query + * @param pageNumber the number of the page indexed from 0 */ default URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery, int pageNumber) throws URISyntaxException, MalformedURLException { return getURLForQuery(complexSearchQuery.toString(), pageNumber); } + + @Override + default List performSearch(String query) throws FetcherException { + return SearchBasedParserFetcher.super.performSearch(query); + } + + @Override + default List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { + return SearchBasedParserFetcher.super.performComplexSearch(complexSearchQuery); + } + + @Override + default URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException, FetcherException { + return getURLForQuery(query, 0); + } + + @Override + default URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery) throws URISyntaxException, MalformedURLException, FetcherException { + return getComplexQueryURL(complexSearchQuery, 0); + } } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java index c4d66a86bf3..a03ad526164 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java @@ -250,8 +250,11 @@ public Optional getHelpPage() { } @Override - public List performSearch(String query) throws FetcherException { - return new ArrayList<>(performSearchPaged(query, 0).getContent()); + public Page performSearchPaged(String query, int pageNumber) throws FetcherException { + List searchResult = searchForEntries(query, pageNumber).stream() + .map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator())) + .collect(Collectors.toList()); + return new Page<>(query, pageNumber, searchResult); } /** @@ -260,19 +263,6 @@ public List performSearch(String query) throws FetcherException { * @param complexSearchQuery the search query defining all fielded search parameters * @return A list of entries matching the complex query */ - @Override - public List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { - return new ArrayList<>(performComplexSearchPaged(complexSearchQuery, 0).getContent()); - } - - @Override - public Page performSearchPaged(String query, int pageNumber) throws FetcherException { - List searchResult = searchForEntries(query, pageNumber).stream() - .map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator())) - .collect(Collectors.toList()); - return new Page<>(query, pageNumber, searchResult); - } - @Override public Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { List searchTerms = new ArrayList<>(); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java index 7e7b6a0d831..05e07a03acb 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java @@ -82,14 +82,6 @@ public String getName() { * @param query query string, matching the apache solr format * @return URL which points to a search request for given query */ - @Override - public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException, FetcherException { - URIBuilder builder = new URIBuilder(API_SEARCH_URL); - builder.addParameter("q", query); - builder.addParameter("fl", "bibcode"); - return builder.build().toURL(); - } - @Override public URL getURLForQuery(String query, int pageNumber) throws URISyntaxException, MalformedURLException { URIBuilder builder = new URIBuilder(API_SEARCH_URL); @@ -192,11 +184,6 @@ public List performSearch(BibEntry entry) throws FetcherException { } } - @Override - public List performSearch(String query) throws FetcherException { - return new ArrayList<>(performSearchPaged(query, 0).getContent()); - } - /** * @param url search ul for which bibcode will be returned * @return list of bibcodes matching the search request. May be empty diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java index 9e44cc0e80f..fa804a7ad07 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java @@ -127,16 +127,6 @@ public Optional getHelpPage() { return Optional.of(HelpFile.FETCHER_GOOGLE_SCHOLAR); } - @Override - public List performSearch(String query) throws FetcherException { - return new ArrayList<>(performSearchPaged(query, 0).getContent()); - } - - @Override - public List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { - return new ArrayList<>(performComplexSearchPaged(complexSearchQuery, 0).getContent()); - } - private String constructComplexQueryString(ComplexSearchQuery complexSearchQuery) { List searchTerms = new ArrayList<>(); searchTerms.addAll(complexSearchQuery.getDefaultFieldPhrases()); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java index 92a10bbdb25..d89223908a0 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java @@ -191,11 +191,6 @@ public TrustLevel getTrustLevel() { return TrustLevel.PUBLISHER; } - @Override - public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException { - return getURLForQuery(query, 0); - } - @Override public Parser getParser() { return inputStream -> { @@ -226,11 +221,6 @@ public Optional getHelpPage() { return Optional.of(HelpFile.FETCHER_IEEEXPLORE); } - @Override - public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery) throws URISyntaxException, MalformedURLException { - return getComplexQueryURL(complexSearchQuery, 0); - } - @Override public URL getURLForQuery(String query, int pageNumber) throws URISyntaxException, MalformedURLException { URIBuilder uriBuilder = new URIBuilder("https://ieeexploreapi.ieee.org/api/v1/search/articles"); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java index 5c8ced78b2d..a547dbe2175 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java @@ -157,16 +157,6 @@ public Optional getHelpPage() { return Optional.of(HelpFile.FETCHER_SPRINGER); } - @Override - public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException { - return getURLForQuery(query, 0); - } - - @Override - public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery) throws URISyntaxException, MalformedURLException { - return getComplexQueryURL(complexSearchQuery, 0); - } - @Override public URL getURLForQuery(String query, int pageNumber) throws URISyntaxException, MalformedURLException { URIBuilder uriBuilder = new URIBuilder(API_URL); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java index a623e2e26f1..34d9e8a8a11 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java @@ -8,12 +8,12 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.PagedSearchBasedFetcher; import org.jabref.logic.importer.SearchBasedFetcher; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.identifier.ArXivIdentifier; import org.jabref.model.entry.types.StandardEntryType; -import org.jabref.model.paging.Page; import org.jabref.testutils.category.FetcherTest; import org.junit.jupiter.api.BeforeEach; @@ -21,14 +21,13 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @FetcherTest -class ArXivTest implements SearchBasedFetcherCapabilityTest { +class ArXivTest implements SearchBasedFetcherCapabilityTest, PagedSearchFetcherTest { private ArXiv fetcher; private BibEntry entry; private BibEntry sliceTheoremPaper; @@ -286,18 +285,9 @@ public void supportsPhraseSearchAndMatchesExact() throws Exception { assertEquals(Collections.singletonList(expected), resultWithPhraseSearch); } - /** - * Ensure that different page return different entries - */ - @Test - public void pageSearchReturnsUniqueResultsPerPage() throws Exception { - String query = "Software"; - Page firstPage = fetcher.performSearchPaged(query, 0); - Page secondPage = fetcher.performSearchPaged(query, 1); - - for (BibEntry entry : firstPage.getContent()) { - assertFalse(secondPage.getContent().contains(entry)); - } + @Override + public PagedSearchBasedFetcher getPagedFetcher() { + return fetcher; } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java index 56d033e3046..7f5c708047f 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java @@ -5,6 +5,7 @@ import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.PagedSearchBasedFetcher; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; @@ -16,13 +17,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @FetcherTest -public class AstrophysicsDataSystemTest { +public class AstrophysicsDataSystemTest implements PagedSearchFetcherTest { private AstrophysicsDataSystem fetcher; private BibEntry diezSliceTheoremEntry; @@ -215,11 +215,8 @@ public void performSearchByQueryPaged_invalidAuthorsReturnEmptyPages() throws Ex assertEquals(0, page5.getSize(), "fetcher doesnt return empty pages for invalid author"); } - @Test - public void performSearchByQueryPaged_twoPagesNotEqual() throws Exception { - Page page = fetcher.performSearchPaged("author:\"A\"", 0); - Page page2 = fetcher.performSearchPaged("author:\"A\"", 1); - // This tests if the fetcher actually performs paging - assertNotEquals(page.getContent(), page2.getContent(), "Two consecutive pages shouldn't be equal"); + @Override + public PagedSearchBasedFetcher getPagedFetcher() { + return fetcher; } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java index c26b8389dc4..87ff79ac608 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java @@ -9,11 +9,11 @@ import org.jabref.logic.bibtex.FieldContentFormatterPreferences; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.PagedSearchBasedFetcher; import org.jabref.logic.importer.SearchBasedFetcher; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; -import org.jabref.model.paging.Page; import org.jabref.support.DisabledOnCIServer; import org.jabref.testutils.category.FetcherTest; @@ -21,12 +21,11 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @FetcherTest -class GoogleScholarTest implements SearchBasedFetcherCapabilityTest { +class GoogleScholarTest implements SearchBasedFetcherCapabilityTest, PagedSearchFetcherTest { private GoogleScholar finder; private BibEntry entry; @@ -83,23 +82,13 @@ void findManyEntries() throws FetcherException { assertEquals(20, foundEntries.size()); } - /** - * Ensure that different page return different entries - */ - @Test - @DisabledOnCIServer("CI server is blocked by Google") - public void pageSearchReturnsUniqueResultsPerPage() throws Exception { - String query = "Software"; - Page firstPage = finder.performSearchPaged(query, 0); - Page secondPage = finder.performSearchPaged(query, 1); - - for (BibEntry entry : firstPage.getContent()) { - assertFalse(secondPage.getContent().contains(entry)); - } + @Override + public SearchBasedFetcher getFetcher() { + return finder; } @Override - public SearchBasedFetcher getFetcher() { + public PagedSearchBasedFetcher getPagedFetcher() { return finder; } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java b/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java index b8ba64e81d5..a063519bb8d 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java @@ -6,23 +6,22 @@ import java.util.Optional; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.PagedSearchBasedFetcher; import org.jabref.logic.importer.SearchBasedFetcher; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; -import org.jabref.model.paging.Page; import org.jabref.testutils.category.FetcherTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @FetcherTest -class IEEETest implements SearchBasedFetcherCapabilityTest { +class IEEETest implements SearchBasedFetcherCapabilityTest, PagedSearchFetcherTest { private IEEE fetcher; private BibEntry entry; @@ -127,20 +126,6 @@ void searchByQueryFindsEntry() throws Exception { assertEquals(Collections.singletonList(expected), fetchedEntries); } - /** - * Ensure that different page return different entries - */ - @Test - public void pageSearchReturnsUniqueResultsPerPage() throws Exception { - String query = "Software"; - Page firstPage = fetcher.performSearchPaged(query, 0); - Page secondPage = fetcher.performSearchPaged(query, 1); - - for (BibEntry entry: firstPage.getContent()) { - assertFalse(secondPage.getContent().contains(entry)); - } - } - @Override public SearchBasedFetcher getFetcher() { return fetcher; @@ -155,4 +140,9 @@ public List getTestAuthors() { public String getTestJournal() { return "IET Renewable Power Generation"; } + + @Override + public PagedSearchBasedFetcher getPagedFetcher() { + return fetcher; + } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java new file mode 100644 index 00000000000..43902fe9fa2 --- /dev/null +++ b/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java @@ -0,0 +1,31 @@ +package org.jabref.logic.importer.fetcher; + +import org.jabref.logic.importer.PagedSearchBasedFetcher; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.paging.Page; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +/** + * This interface provides general test methods for paged fetchers + */ +public interface PagedSearchFetcherTest { + + /** + * Ensure that different page return different entries + */ + @Test + default void pageSearchReturnsUniqueResultsPerPage() throws Exception { + String query = "Software"; + Page firstPage = getPagedFetcher().performSearchPaged(query, 0); + Page secondPage = getPagedFetcher().performSearchPaged(query, 1); + + for (BibEntry entry : firstPage.getContent()) { + assertFalse(secondPage.getContent().contains(entry)); + } + } + + PagedSearchBasedFetcher getPagedFetcher(); +} diff --git a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java index 0eb65994cf5..baedf464cfc 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java @@ -5,11 +5,11 @@ import java.util.Optional; import java.util.stream.Collectors; +import org.jabref.logic.importer.PagedSearchBasedFetcher; import org.jabref.logic.importer.SearchBasedFetcher; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; -import org.jabref.model.paging.Page; import org.jabref.testutils.category.FetcherTest; import kong.unirest.json.JSONObject; @@ -19,11 +19,10 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @FetcherTest -class SpringerFetcherTest implements SearchBasedFetcherCapabilityTest { +class SpringerFetcherTest implements SearchBasedFetcherCapabilityTest, PagedSearchFetcherTest { SpringerFetcher fetcher; @@ -134,20 +133,6 @@ public void supportsBooleanANDSearch() throws Exception { .map(Optional::get).forEach(authorField -> assertTrue(authorField.contains("Redmiles"))); } - /** - * Ensure that different page return different entries - */ - @Test - public void pageSearchReturnsUniqueResultsPerPage() throws Exception { - String query = "Software"; - Page firstPage = fetcher.performSearchPaged(query, 0); - Page secondPage = fetcher.performSearchPaged(query, 1); - - for (BibEntry entry : firstPage.getContent()) { - assertFalse(secondPage.getContent().contains(entry)); - } - } - @Override public SearchBasedFetcher getFetcher() { return fetcher; @@ -162,4 +147,9 @@ public List getTestAuthors() { public String getTestJournal() { return "\"Clinical Research in Cardiology\""; } + + @Override + public PagedSearchBasedFetcher getPagedFetcher() { + return fetcher; + } } From c76bf45bdb74062f6d3f3d38f43798f641e17559 Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Thu, 12 Nov 2020 14:09:47 +0100 Subject: [PATCH 6/8] Remove performSearch and adapt all tests accordingly Signed-off-by: Dominik Voigt --- .../org/jabref/cli/ArgumentProcessor.java | 2 +- .../BibtexExtractorViewModel.java | 2 +- .../fetcher/WebSearchPaneViewModel.java | 14 ++--------- .../importer/PagedSearchBasedFetcher.java | 5 ---- .../PagedSearchBasedParserFetcher.java | 5 ---- .../jabref/logic/importer/QueryParser.java | 2 -- .../logic/importer/SearchBasedFetcher.java | 23 ++++++++++++------- .../importer/SearchBasedParserFetcher.java | 23 ++----------------- .../jabref/logic/importer/fetcher/ArXiv.java | 2 +- .../importer/fetcher/ComplexSearchQuery.java | 3 ++- .../fetcher/CompositeSearchBasedFetcher.java | 4 ++-- .../fetcher/GrobidCitationFetcher.java | 4 +++- .../importer/fetcher/MedlineFetcher.java | 17 ++++++-------- .../fetcher/ACMPortalFetcherTest.java | 2 +- .../logic/importer/fetcher/ArXivTest.java | 12 +++++----- .../fetcher/AstrophysicsDataSystemTest.java | 2 +- .../logic/importer/fetcher/CiteSeerTest.java | 4 ++-- ...puterScienceBibliographiesFetcherTest.java | 4 ++-- .../CompositeSearchBasedFetcherTest.java | 14 +++++------ .../logic/importer/fetcher/CrossRefTest.java | 4 ++-- .../importer/fetcher/DBLPFetcherTest.java | 6 ++--- .../importer/fetcher/DOAJFetcherTest.java | 4 ++-- .../importer/fetcher/GoogleScholarTest.java | 4 ++-- .../fetcher/GrobidCitationFetcherTest.java | 10 ++++---- .../importer/fetcher/GvkFetcherTest.java | 8 +++---- .../logic/importer/fetcher/IEEETest.java | 4 ++-- .../importer/fetcher/INSPIREFetcherTest.java | 4 ++-- .../importer/fetcher/JstorFetcherTest.java | 9 +++++++- .../importer/fetcher/MathSciNetTest.java | 2 +- .../importer/fetcher/MedlineFetcherTest.java | 8 +++---- .../importer/fetcher/SpringerFetcherTest.java | 12 +++++----- .../logic/importer/fetcher/ZbMATHTest.java | 2 +- 32 files changed, 97 insertions(+), 124 deletions(-) diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index eeee79c1366..dc87122cb62 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -550,7 +550,7 @@ private Optional fetch(String fetchCommand) { System.out.println(Localization.lang("Running query '%0' with fetcher '%1'.", query, engine)); System.out.print(Localization.lang("Please wait...")); try { - List matches = selectedFetcher.get().performSearch(query); + List matches = selectedFetcher.get().performComplexSearch(query); if (matches.isEmpty()) { System.out.println("\r" + Localization.lang("No results found.")); return Optional.empty(); diff --git a/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java b/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java index f1d99d74331..83069aba600 100644 --- a/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java +++ b/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java @@ -62,7 +62,7 @@ public StringProperty inputTextProperty() { } public void startParsing() { - BackgroundTask.wrap(() -> currentCitationfetcher.performSearch(inputTextProperty.getValue())) + BackgroundTask.wrap(() -> currentCitationfetcher.performComplexSearch(inputTextProperty.getValue())) .onRunning(() -> dialogService.notify(Localization.lang("Your text is being parsed..."))) .onFailure((e) -> { if (e instanceof FetcherException) { diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java index beafb11c060..fb982f6b7c7 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java @@ -1,6 +1,5 @@ package org.jabref.gui.importer.fetcher; -import java.util.Optional; import java.util.SortedSet; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -23,10 +22,8 @@ import org.jabref.gui.util.BackgroundTask; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ParserResult; -import org.jabref.logic.importer.QueryParser; import org.jabref.logic.importer.SearchBasedFetcher; import org.jabref.logic.importer.WebFetchers; -import org.jabref.logic.importer.fetcher.ComplexSearchQuery; import org.jabref.logic.l10n.Localization; import org.jabref.model.strings.StringUtil; import org.jabref.preferences.JabRefPreferences; @@ -109,15 +106,8 @@ public void search() { SearchBasedFetcher activeFetcher = getSelectedFetcher(); BackgroundTask task; - QueryParser queryParser = new QueryParser(); - Optional generatedQuery = queryParser.parseQueryStringIntoComplexQuery(getQuery()); - if (generatedQuery.isPresent()) { - task = BackgroundTask.wrap(() -> new ParserResult(activeFetcher.performComplexSearch(generatedQuery.get()))) - .withInitialMessage(Localization.lang("Processing %0", getQuery())); - } else { - task = BackgroundTask.wrap(() -> new ParserResult(activeFetcher.performSearch(getQuery().trim()))) - .withInitialMessage(Localization.lang("Processing %0", getQuery())); - } + task = BackgroundTask.wrap(() -> new ParserResult(activeFetcher.performComplexSearch(getQuery().trim()))) + .withInitialMessage(Localization.lang("Processing %0", getQuery().trim())); task.onFailure(dialogService::showErrorDialogAndWait); ImportEntriesDialog dialog = new ImportEntriesDialog(frame.getCurrentLibraryTab().getBibDatabaseContext(), task); diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java index 5bcc8b5c916..f33c920a94b 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java @@ -32,11 +32,6 @@ default int getPageSize() { return 20; } - @Override - default List performSearch(String query) throws FetcherException { - return new ArrayList<>(performSearchPaged(query, 0).getContent()); - } - @Override default List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { return new ArrayList<>(performComplexSearchPaged(complexSearchQuery, 0).getContent()); diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java index f771696b768..bbd52d78877 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java @@ -73,11 +73,6 @@ default URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery, int pageNu return getURLForQuery(complexSearchQuery.toString(), pageNumber); } - @Override - default List performSearch(String query) throws FetcherException { - return SearchBasedParserFetcher.super.performSearch(query); - } - @Override default List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { return SearchBasedParserFetcher.super.performComplexSearch(complexSearchQuery); diff --git a/src/main/java/org/jabref/logic/importer/QueryParser.java b/src/main/java/org/jabref/logic/importer/QueryParser.java index 6fe611f442f..6bec3eae988 100644 --- a/src/main/java/org/jabref/logic/importer/QueryParser.java +++ b/src/main/java/org/jabref/logic/importer/QueryParser.java @@ -32,8 +32,6 @@ public class QueryParser { */ public Optional parseQueryStringIntoComplexQuery(String queryString) { try { - ComplexSearchQuery.ComplexSearchQueryBuilder builder = ComplexSearchQuery.builder(); - StandardQueryParser parser = new StandardQueryParser(); Query luceneQuery = parser.parse(queryString, "default"); Set terms = new HashSet<>(); diff --git a/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java index 8aa8dcf04f1..c60619e5b35 100644 --- a/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java @@ -1,6 +1,8 @@ package org.jabref.logic.importer; +import java.util.Collections; import java.util.List; +import java.util.Optional; import org.jabref.logic.importer.fetcher.ComplexSearchQuery; import org.jabref.model.entry.BibEntry; @@ -12,21 +14,26 @@ public interface SearchBasedFetcher extends WebFetcher { /** - * Looks for hits which are matched by the given free-text query. + * This method is used to send complex queries using fielded search. * - * @param query search string + * @param complexSearchQuery the search query defining all fielded search parameters * @return a list of {@link BibEntry}, which are matched by the query (may be empty) */ - List performSearch(String query) throws FetcherException; + List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException; /** - * This method is used to send complex queries using fielded search. + * Looks for hits which are matched by the given free-text query. * - * @param complexSearchQuery the search query defining all fielded search parameters + * @param query search string * @return a list of {@link BibEntry}, which are matched by the query (may be empty) */ - default List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { - // Default implementation behaves as perform search on all fields concatenated as query - return performSearch(complexSearchQuery.toString()); + default List performComplexSearch(String query) throws FetcherException { + if (query.isBlank()) { + return Collections.emptyList(); + } + QueryParser queryParser = new QueryParser(); + Optional generatedQuery = queryParser.parseQueryStringIntoComplexQuery(query); + // Otherwise just use query as a default term + return this.performComplexSearch(generatedQuery.orElse(ComplexSearchQuery.builder().defaultFieldPhrase(query).build())); } } diff --git a/src/main/java/org/jabref/logic/importer/SearchBasedParserFetcher.java b/src/main/java/org/jabref/logic/importer/SearchBasedParserFetcher.java index e8b40c963ad..ff83aa7c8e9 100644 --- a/src/main/java/org/jabref/logic/importer/SearchBasedParserFetcher.java +++ b/src/main/java/org/jabref/logic/importer/SearchBasedParserFetcher.java @@ -5,13 +5,11 @@ import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; -import java.util.Collections; import java.util.List; import org.jabref.logic.cleanup.Formatter; import org.jabref.logic.importer.fetcher.ComplexSearchQuery; import org.jabref.model.entry.BibEntry; -import org.jabref.model.strings.StringUtil; /** * Provides a convenient interface for search-based fetcher, which follow the usual three-step procedure: @@ -35,22 +33,6 @@ public interface SearchBasedParserFetcher extends SearchBasedFetcher { */ Parser getParser(); - @Override - default List performSearch(String query) throws FetcherException { - if (StringUtil.isBlank(query)) { - return Collections.emptyList(); - } - - // ADR-0014 - URL urlForQuery; - try { - urlForQuery = getURLForQuery(query); - } catch (URISyntaxException | MalformedURLException | FetcherException e) { - throw new FetcherException(String.format("Search URI crafted from query %s is malformed", query), e); - } - return getBibEntries(urlForQuery); - } - /** * This method is used to send queries with advanced URL parameters. * This method is necessary as the performSearch method does not support certain URL parameters that are used for @@ -83,9 +65,8 @@ private List getBibEntries(URL urlForQuery) throws FetcherException { } default URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery) throws URISyntaxException, MalformedURLException, FetcherException { - // Default implementation behaves as getURLForQuery using the default field phrases as query - List defaultPhrases = complexSearchQuery.getDefaultFieldPhrases(); - return this.getURLForQuery(String.join(" ", defaultPhrases)); + // Default implementation behaves as getURLForQuery treating complex query as plain string query + return this.getURLForQuery(complexSearchQuery.toString()); } /** diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java index a03ad526164..573111e1dec 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java @@ -268,7 +268,7 @@ public Page performComplexSearchPaged(ComplexSearchQuery complexSearch List searchTerms = new ArrayList<>(); complexSearchQuery.getAuthors().forEach(author -> searchTerms.add("au:" + author)); complexSearchQuery.getTitlePhrases().forEach(title -> searchTerms.add("ti:" + title)); - complexSearchQuery.getTitlePhrases().forEach(abstr -> searchTerms.add("abs:" + abstr)); + complexSearchQuery.getAbstractPhrases().forEach(abstr -> searchTerms.add("abs:" + abstr)); complexSearchQuery.getJournal().ifPresent(journal -> searchTerms.add("jr:" + journal)); // Since ArXiv API does not support year search, we ignore the year related terms complexSearchQuery.getToYear().ifPresent(year -> searchTerms.add(year.toString())); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java b/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java index 750a6d68e46..6fe86b92e09 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java @@ -46,7 +46,8 @@ public static ComplexSearchQuery fromTerms(Collection terms) { case "year" -> builder.singleYear(Integer.valueOf(termText)); case "year-range" -> builder.parseYearRange(termText); case "default" -> builder.defaultFieldPhrase(termText); - default -> builder.defaultFieldPhrase(term.field() + ":" + termText); + // add unknown field as default field + default -> builder.defaultFieldPhrase(termText); } }); return builder.build(); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcher.java index b0dbf1c5184..f5bb271757c 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcher.java @@ -36,13 +36,13 @@ public CompositeSearchBasedFetcher(Set searchBasedFetchers, } @Override - public List performSearch(String query) { + public List performComplexSearch(ComplexSearchQuery complexSearchQuery) { ImportCleanup cleanup = new ImportCleanup(BibDatabaseMode.BIBTEX); // All entries have to be converted into one format, this is necessary for the format conversion return fetchers.parallelStream() .flatMap(searchBasedFetcher -> { try { - return searchBasedFetcher.performSearch(query).stream(); + return searchBasedFetcher.performComplexSearch(complexSearchQuery).stream(); } catch (FetcherException e) { LOGGER.warn(String.format("%s API request failed", searchBasedFetcher.getName()), e); return Stream.empty(); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java index 7a57535efe9..4fddd4c1587 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java @@ -66,8 +66,10 @@ private Optional parseBibToBibEntry(String bibtexString) { } @Override - public List performSearch(String query) throws FetcherException { + public List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { List bibEntries = null; + // This just treats the complex query like a normal string query until it it implemented correctly + String query = complexSearchQuery.toString(); try { bibEntries = Arrays .stream(query.split("\\r\\r+|\\n\\n+|\\r\\n(\\r\\n)+")) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java index 0050bc1fbf7..e47937b610d 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java @@ -10,7 +10,6 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Optional; @@ -159,16 +158,15 @@ public void doPostCleanup(BibEntry entry) { } @Override - public List performSearch(String query) throws FetcherException { - List entryList = new LinkedList<>(); + public List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { + List entryList; + String query = complexSearchQuery.toString(); - if (query.isEmpty()) { + if (query.isBlank()) { return Collections.emptyList(); } else { - String searchTerm = replaceCommaWithAND(query); - // searching for pubmed ids matching the query - List idList = getPubMedIdsFromQuery(searchTerm); + List idList = getPubMedIdsFromQuery(query); if (idList.isEmpty()) { LOGGER.info("No results found."); @@ -186,13 +184,12 @@ public List performSearch(String query) throws FetcherException { } } - private URL createSearchUrl(String term) throws URISyntaxException, MalformedURLException { - term = replaceCommaWithAND(term); + private URL createSearchUrl(String query) throws URISyntaxException, MalformedURLException { URIBuilder uriBuilder = new URIBuilder(SEARCH_URL); uriBuilder.addParameter("db", "pubmed"); uriBuilder.addParameter("sort", "relevance"); uriBuilder.addParameter("retmax", String.valueOf(NUMBER_TO_FETCH)); - uriBuilder.addParameter("term", term); + uriBuilder.addParameter("term", replaceCommaWithAND(query)); return uriBuilder.build().toURL(); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java index 420047cd79e..1cc7b47466e 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java @@ -51,7 +51,7 @@ void searchByQueryFindsEntry() throws Exception { expected.setField(StandardField.URL, "http://doi.acm.org/10.1145/3129790.3129810"); expected.setField(StandardField.YEAR, "2017"); - List fetchedEntries = fetcher.performSearch("jabref architectural churn"); + List fetchedEntries = fetcher.performComplexSearch("jabref architectural churn"); assertEquals(Collections.singletonList(expected), fetchedEntries); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java index 34d9e8a8a11..4e720ebcf5f 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java @@ -136,13 +136,13 @@ void findFullTextTrustLevel() { @Test void searchEntryByPartOfTitle() throws Exception { assertEquals(Collections.singletonList(sliceTheoremPaper), - fetcher.performSearch("ti:\"slice theorem for Frechet\"")); + fetcher.performComplexSearch("title:\"slice theorem for Frechet\"")); } @Test void searchEntryByPartOfTitleWithAcuteAccent() throws Exception { assertEquals(Collections.singletonList(sliceTheoremPaper), - fetcher.performSearch("ti:\"slice theorem for Fréchet\"")); + fetcher.performComplexSearch("title:\"slice theorem for Fréchet\"")); } @Test @@ -256,8 +256,8 @@ public String getTestJournal() { */ @Test public void supportsPhraseSearch() throws Exception { - List resultWithPhraseSearch = fetcher.performSearch("ti:\"Taxonomy of Distributed\""); - List resultWithOutPhraseSearch = fetcher.performSearch("ti:Taxonomy AND ti:of AND ti:Distributed"); + List resultWithPhraseSearch = fetcher.performComplexSearch("title:\"Taxonomy of Distributed\""); + List resultWithOutPhraseSearch = fetcher.performComplexSearch("title:Taxonomy AND title:of AND title:Distributed"); // Phrase search result has to be subset of the default search result assertTrue(resultWithOutPhraseSearch.containsAll(resultWithPhraseSearch)); } @@ -279,7 +279,7 @@ public void supportsPhraseSearchAndMatchesExact() throws Exception { .withField(StandardField.EPRINTCLASS, "cs.DC") .withField(StandardField.KEYWORDS, "cs.DC, cs.LG"); - List resultWithPhraseSearch = fetcher.performSearch("ti:\"Taxonomy of Distributed\""); + List resultWithPhraseSearch = fetcher.performComplexSearch("title:\"Taxonomy of Distributed\""); // There is only a single paper found by searching that contains the exact sequence "Taxonomy of Distributed" in the title. assertEquals(Collections.singletonList(expected), resultWithPhraseSearch); @@ -305,7 +305,7 @@ public void supportsBooleanANDSearch() throws Exception { .withField(StandardField.EPRINTCLASS, "q-bio.TO") .withField(StandardField.KEYWORDS, "q-bio.TO"); - List result = fetcher.performSearch("au:\"Tobias Büscher\" AND ti:\"Instability and fingering of interfaces\""); + List result = fetcher.performComplexSearch("author:\"Tobias Büscher\" AND title:\"Instability and fingering of interfaces\""); // There is only one paper authored by Tobias Büscher with that phrase in the title assertEquals(Collections.singletonList(expected), result); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java index 7f5c708047f..6f8fd13f4b9 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java @@ -143,7 +143,7 @@ public void testGetName() { @Test public void searchByQueryFindsEntry() throws Exception { - List fetchedEntries = fetcher.performSearch("Diez slice theorem Lie"); + List fetchedEntries = fetcher.performComplexSearch("Diez slice theorem Lie"); assertTrue(fetchedEntries.contains(diezSliceTheoremEntry)); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CiteSeerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CiteSeerTest.java index e2f6f2951a1..eb2040a0633 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CiteSeerTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CiteSeerTest.java @@ -26,7 +26,7 @@ void searchByQueryFindsEntryRigorousDerivation() throws Exception { .withField(StandardField.TITLE, "Rigorous Derivation from Landau-de Gennes Theory to Eericksen-leslie Theory") .withField(StandardField.DOI, "10.1.1.744.5780"); - List fetchedEntries = fetcher.performSearch("title:Ericksen-Leslie AND venue:q AND ncites:[10 TO 15000]"); + List fetchedEntries = fetcher.performComplexSearch("title:Ericksen-Leslie AND venue:q AND ncites:[10 TO 15000]"); assertEquals(Collections.singletonList(expected), fetchedEntries); } @@ -39,7 +39,7 @@ void searchByQueryFindsEntryCopingTheoryAndResearch() throws Exception { .withField(StandardField.YEAR, "1993") .withField(StandardField.JOURNALTITLE, "PSYCHOSOMATIC MEDICINE"); - List fetchedEntries = fetcher.performSearch("doi:10.1.1.115.9665"); + List fetchedEntries = fetcher.performComplexSearch("doi:10.1.1.115.9665"); assertEquals(Collections.singletonList(expected), fetchedEntries); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java index 577f4624196..eae7c929a1e 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java @@ -49,7 +49,7 @@ public void getUrlForQueryReturnsCorrectUrl() throws MalformedURLException, URIS @Test public void performSearchReturnsMatchingMultipleEntries() throws FetcherException { - List searchResult = fetcher.performSearch("jabref"); + List searchResult = fetcher.performComplexSearch("jabref"); BibEntry firstBibEntry = new BibEntry(StandardEntryType.InProceedings) .withCitationKey("conf/ecsa/OlssonEW17") @@ -117,7 +117,7 @@ public void performSearchReturnsMatchingMultipleEntries() throws FetcherExceptio @Test public void performSearchReturnsEmptyListForEmptySearch() throws FetcherException { - List searchResult = fetcher.performSearch(""); + List searchResult = fetcher.performComplexSearch(""); assertEquals(Collections.emptyList(), searchResult); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java index fb4ca119f7d..b25b9a99d87 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java @@ -39,21 +39,21 @@ public void createCompositeFetcherWithNullSet() { } @Test - public void performSearchWithoutFetchers() { + public void performSearchWithoutFetchers() throws Exception { Set empty = new HashSet<>(); CompositeSearchBasedFetcher fetcher = new CompositeSearchBasedFetcher(empty, Integer.MAX_VALUE); - List result = fetcher.performSearch("quantum"); + List result = fetcher.performComplexSearch("quantum"); Assertions.assertEquals(result, Collections.EMPTY_LIST); } @ParameterizedTest(name = "Perform Search on empty query.") @MethodSource("performSearchParameters") - public void performSearchOnEmptyQuery(Set fetchers) { + public void performSearchOnEmptyQuery(Set fetchers) throws Exception { CompositeSearchBasedFetcher compositeFetcher = new CompositeSearchBasedFetcher(fetchers, Integer.MAX_VALUE); - List queryResult = compositeFetcher.performSearch(""); + List queryResult = compositeFetcher.performComplexSearch(""); Assertions.assertEquals(queryResult, Collections.EMPTY_LIST); } @@ -61,14 +61,14 @@ public void performSearchOnEmptyQuery(Set fetchers) { @ParameterizedTest(name = "Perform search on query \"quantum\". Using the CompositeFetcher of the following " + "Fetchers: {arguments}") @MethodSource("performSearchParameters") - public void performSearchOnNonEmptyQuery(Set fetchers) { + public void performSearchOnNonEmptyQuery(Set fetchers) throws Exception { CompositeSearchBasedFetcher compositeFetcher = new CompositeSearchBasedFetcher(fetchers, Integer.MAX_VALUE); ImportCleanup cleanup = new ImportCleanup(BibDatabaseMode.BIBTEX); - List compositeResult = compositeFetcher.performSearch("quantum"); + List compositeResult = compositeFetcher.performComplexSearch("quantum"); for (SearchBasedFetcher fetcher : fetchers) { try { - List fetcherResult = fetcher.performSearch("quantum"); + List fetcherResult = fetcher.performComplexSearch("quantum"); fetcherResult.forEach(cleanup::doPostCleanup); Assertions.assertTrue(compositeResult.containsAll(fetcherResult)); } catch (FetcherException e) { diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java index 7409b317838..6386aed81e2 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java @@ -105,7 +105,7 @@ public void findByDOI() throws Exception { @Test public void findByAuthors() throws Exception { - assertEquals(Optional.of(barrosEntry), fetcher.performSearch("Barros, Alistair and Dumas, Marlon and Arthur H.M. ter Hofstede").stream().findFirst()); + assertEquals(Optional.of(barrosEntry), fetcher.performComplexSearch("\"Barros, Alistair\" AND \"Dumas, Marlon\" AND \"Arthur H.M. ter Hofstede\"").stream().findFirst()); } @Test @@ -137,7 +137,7 @@ public void performSearchByEmptyId() throws Exception { @Test public void performSearchByEmptyQuery() throws Exception { - assertEquals(Collections.emptyList(), fetcher.performSearch("")); + assertEquals(Collections.emptyList(), fetcher.performComplexSearch("")); } /** diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java index 83414d8666d..63f205bfb4b 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java @@ -51,7 +51,7 @@ public void setUp() { @Test public void findSingleEntry() throws FetcherException { String query = "Process Engine Benchmarking with Betsy in the Context of {ISO/IEC} Quality Standards"; - List result = dblpFetcher.performSearch(query); + List result = dblpFetcher.performComplexSearch(query); assertEquals(Collections.singletonList(entry), result); } @@ -59,13 +59,13 @@ public void findSingleEntry() throws FetcherException { @Test public void findSingleEntryUsingComplexOperators() throws FetcherException { String query = "geiger harrer betsy$ softw.trends"; // -wirtz Negative operators do no longer work, see issue https://github.com/JabRef/jabref/issues/2890 - List result = dblpFetcher.performSearch(query); + List result = dblpFetcher.performComplexSearch(query); assertEquals(Collections.singletonList(entry), result); } @Test public void findNothing() throws Exception { - assertEquals(Collections.emptyList(), dblpFetcher.performSearch("")); + assertEquals(Collections.emptyList(), dblpFetcher.performComplexSearch("")); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java index 2cad38a3f17..fe5829110fe 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java @@ -45,7 +45,7 @@ void searchByQueryFindsEntry() throws Exception { expected.setField(StandardField.YEAR, "2018"); expected.setField(StandardField.ABSTRACT, "The paper presents an approach to combine multiple existing information retrieval (IR) techniques to support change impact analysis, which seeks to identify the possible outcomes of a change or determine the necessary modifications for affecting a desired change. The approach integrates a bag-of-words based IR technique, where each class or method is abstracted as a set of words, and a neural network based IR technique to derive conceptual couplings from the source code of a software system. We report rigorous empirical assessments of the changes of three open source systems: jEdit, muCommander, and JabRef. The impact sets obtained are evaluated at the method level of granularity, and the results show that our integrated approach provides statistically significant improvements in accuracy across several cut points relative to the accuracies provided by the individual methods employed independently. Improvements in F-score values of up to 7.3%, 10.9%, and 17.3% are obtained over a baseline technique for jEdit, muCommander, and JabRef, respectively."); - List fetchedEntries = fetcher.performSearch("JabRef impact"); + List fetchedEntries = fetcher.performComplexSearch("JabRef impact"); assertEquals(Collections.singletonList(expected), fetchedEntries); } @@ -65,7 +65,7 @@ void testBibJSONConverter() { @Test public void searchByEmptyQuery() throws Exception { - assertEquals(Collections.emptyList(), fetcher.performSearch("")); + assertEquals(Collections.emptyList(), fetcher.performComplexSearch("")); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java index 87ff79ac608..1929de37d6e 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java @@ -69,7 +69,7 @@ void findSingleEntry() throws FetcherException { entry.setField(StandardField.YEAR, "2013"); entry.setField(StandardField.PAGES, "41--44"); - List foundEntries = finder.performSearch("Detecting Interoperability and Correctness Issues in BPMN 2.0 Process Models"); + List foundEntries = finder.performComplexSearch("Detecting Interoperability and Correctness Issues in BPMN 2.0 Process Models"); assertEquals(Collections.singletonList(entry), foundEntries); } @@ -77,7 +77,7 @@ void findSingleEntry() throws FetcherException { @Test @DisabledOnCIServer("CI server is blocked by Google") void findManyEntries() throws FetcherException { - List foundEntries = finder.performSearch("random test string"); + List foundEntries = finder.performComplexSearch("random test string"); assertEquals(20, foundEntries.size()); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java index 329748dcd56..69f34980f86 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java @@ -84,26 +84,26 @@ public static Stream provideInvalidInput() { @ParameterizedTest(name = "{0}") @MethodSource("provideExamplesForCorrectResultTest") public void grobidPerformSearchCorrectResultTest(String testName, BibEntry expectedBibEntry, String searchQuery) throws FetcherException { - List entries = grobidCitationFetcher.performSearch(searchQuery); + List entries = grobidCitationFetcher.performComplexSearch(searchQuery); assertEquals(List.of(expectedBibEntry), entries); } @Test public void grobidPerformSearchCorrectlySplitsStringTest() throws FetcherException { - List entries = grobidCitationFetcher.performSearch(example1 + "\n\n" + example2 + "\r\n\r\n" + example3 + "\r\r" + example4); + List entries = grobidCitationFetcher.performComplexSearch(example1 + "\n\n" + example2 + "\r\n\r\n" + example3 + "\r\r" + example4); assertEquals(List.of(example1AsBibEntry, example2AsBibEntry, example3AsBibEntry, example4AsBibEntry), entries); } @Test public void grobidPerformSearchWithEmptyStringsTest() throws FetcherException { - List entries = grobidCitationFetcher.performSearch(" \n "); + List entries = grobidCitationFetcher.performComplexSearch(" \n "); assertEquals(Collections.emptyList(), entries); } @ParameterizedTest @MethodSource("provideInvalidInput") public void grobidPerformSearchWithInvalidDataTest(String invalidInput) throws FetcherException { - List entries = grobidCitationFetcher.performSearch(invalidInput); + List entries = grobidCitationFetcher.performComplexSearch(invalidInput); assertEquals(Collections.emptyList(), entries); } @@ -114,7 +114,7 @@ public void performSearchThrowsExceptionInCaseOfConnectionIssues() throws IOExce grobidCitationFetcher = new GrobidCitationFetcher(importFormatPreferences, grobidServiceMock); assertThrows(FetcherException.class, () -> { - grobidCitationFetcher.performSearch("any text"); + grobidCitationFetcher.performComplexSearch("any text"); }, "performSearch should throw an FetcherException, when there are underlying IOException."); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java index e95f87ab003..ef37d5746b6 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java @@ -93,26 +93,26 @@ public void complexSearchQueryURLCorrect() throws MalformedURLException, URISynt @Test public void testPerformSearchMatchingMultipleEntries() throws FetcherException { - List searchResult = fetcher.performSearch("tit effective java"); + List searchResult = fetcher.performComplexSearch("title:\"effective java\""); assertTrue(searchResult.contains(bibEntryPPN591166003)); assertTrue(searchResult.contains(bibEntryPPN66391437X)); } @Test public void testPerformSearch591166003() throws FetcherException { - List searchResult = fetcher.performSearch("ppn 591166003"); + List searchResult = fetcher.performComplexSearch("ppn:591166003"); assertEquals(Collections.singletonList(bibEntryPPN591166003), searchResult); } @Test public void testPerformSearch66391437X() throws FetcherException { - List searchResult = fetcher.performSearch("ppn 66391437X"); + List searchResult = fetcher.performComplexSearch("ppn:66391437X"); assertEquals(Collections.singletonList(bibEntryPPN66391437X), searchResult); } @Test public void testPerformSearchEmpty() throws FetcherException { - List searchResult = fetcher.performSearch(""); + List searchResult = fetcher.performComplexSearch(""); assertEquals(Collections.emptyList(), searchResult); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java b/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java index a063519bb8d..b718688f157 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java @@ -98,7 +98,7 @@ void searchResultHasNoKeywordTerms() throws Exception { .withField(StandardField.TITLE, "Optimal operation of PV-DG-battery based microgrid with power quality conditioner") .withField(StandardField.VOLUME, "13"); - List fetchedEntries = fetcher.performSearch("8636659"); // article number + List fetchedEntries = fetcher.performComplexSearch("8636659"); // article number fetchedEntries.forEach(entry -> entry.clearField(StandardField.ABSTRACT)); // Remove abstract due to copyright); assertEquals(Collections.singletonList(expected), fetchedEntries); } @@ -122,7 +122,7 @@ void searchByQueryFindsEntry() throws Exception { .withField(StandardField.TITLE, "Overcoming Open Source Project Entry Barriers with a Portal for Newcomers") .withField(StandardField.FILE, ":https\\://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=7886910:PDF") .withField(StandardField.ABSTRACT, "Community-based Open Source Software (OSS) projects are usually self-organized and dynamic, receiving contributions from distributed volunteers. Newcomer are important to the survival, long-term success, and continuity of these communities. However, newcomers face many barriers when making their first contribution to an OSS project, leading in many cases to dropouts. Therefore, a major challenge for OSS projects is to provide ways to support newcomers during their first contribution. In this paper, we propose and evaluate FLOSScoach, a portal created to support newcomers to OSS projects. FLOSScoach was designed based on a conceptual model of barriers created in our previous work. To evaluate the portal, we conducted a study with 65 students, relying on qualitative data from diaries, self-efficacy questionnaires, and the Technology Acceptance Model. The results indicate that FLOSScoach played an important role in guiding newcomers and in lowering barriers related to the orientation and contribution process, whereas it was not effective in lowering technical barriers. We also found that FLOSScoach is useful, easy to use, and increased newcomers' confidence to contribute. Our results can help project maintainers on deciding the points that need more attention in order to help OSS project newcomers overcome entry barriers."); - List fetchedEntries = fetcher.performSearch("Overcoming Open Source Project Entry Barriers with a Portal for Newcomers"); + List fetchedEntries = fetcher.performComplexSearch("Overcoming Open Source Project Entry Barriers with a Portal for Newcomers"); assertEquals(Collections.singletonList(expected), fetchedEntries); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java index c29a59217b0..90cf5af75f2 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java @@ -41,7 +41,7 @@ void searchByQueryFindsEntry() throws Exception { .withField(StandardField.EPRINT, "1405.2249") .withField(StandardField.ARCHIVEPREFIX, "arXiv") .withField(StandardField.PRIMARYCLASS, "math-ph"); - List fetchedEntries = fetcher.performSearch("Fr\\'echet group actions field"); + List fetchedEntries = fetcher.performComplexSearch("Fr\\´echet group actions field"); assertEquals(Collections.singletonList(master), fetchedEntries); } @@ -59,7 +59,7 @@ public void searchByIdentifierFindsEntry() throws Exception { .withField(StandardField.EPRINT, "hep-ph/9802379") .withField(StandardField.ARCHIVEPREFIX, "arXiv") .withField(new UnknownField("reportnumber"), "BUDKER-INP-1998-7, TTP-98-10"); - List fetchedEntries = fetcher.performSearch("hep-ph/9802379"); + List fetchedEntries = fetcher.performComplexSearch("hep-ph/9802379"); assertEquals(Collections.singletonList(article), fetchedEntries); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java index a55f38def16..2ffa03e20e3 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java @@ -42,7 +42,7 @@ public class JstorFetcherTest implements SearchBasedFetcherCapabilityTest { @Test void searchByTitle() throws Exception { - List entries = fetcher.performSearch("ti: \"Test Anxiety Analysis of Chinese College Students in Computer-based Spoken English Test\""); + List entries = fetcher.performComplexSearch("title: \"Test Anxiety Analysis of Chinese College Students in Computer-based Spoken English Test\""); assertEquals(Collections.singletonList(bibEntry), entries); } @@ -64,6 +64,7 @@ public List getTestAuthors() { @Override public String getTestJournal() { + // Does not provide articles and journals return "Test"; } @@ -73,6 +74,12 @@ public void supportsYearRangeSearch() throws Exception { } + @Disabled("jstor does not provide articles with journals") + @Override + public void supportsJournalSearch() throws Exception { + + } + @Disabled("jstor does not support search only based on year") @Override public void supportsYearSearch() throws Exception { diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java index 7c3cba64256..51230a3da53 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java @@ -73,7 +73,7 @@ void searchByIdInEntryFindsEntry() throws Exception { @Test @DisabledOnCIServer("CI server has no subscription to MathSciNet and thus gets 401 response") void searchByQueryFindsEntry() throws Exception { - List fetchedEntries = fetcher.performSearch("Existence and uniqueness theorems Two-Dimensional Ericksen Leslie System"); + List fetchedEntries = fetcher.performComplexSearch("Existence and uniqueness theorems Two-Dimensional Ericksen Leslie System"); assertFalse(fetchedEntries.isEmpty()); assertEquals(ratiuEntry, fetchedEntries.get(1)); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java index f80953b9d63..91bc837a23d 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java @@ -171,10 +171,10 @@ public void testSearchByIDSari() throws Exception { @Test public void testMultipleEntries() throws Exception { - List entryList = fetcher.performSearch("java"); + List entryList = fetcher.performComplexSearch("java"); entryList.forEach(entry -> entry.clearField(StandardField.ABSTRACT)); // Remove abstract due to copyright); + System.out.println(entryList); assertEquals(50, entryList.size()); - assertTrue(entryList.contains(bibEntryIchikawa)); } @Test @@ -184,12 +184,12 @@ public void testInvalidSearchTerm() throws Exception { @Test public void testEmptyEntryList() throws Exception { - List entryList = fetcher.performSearch("java is fantastic and awesome "); + List entryList = fetcher.performComplexSearch("java is fantastic and awesome "); assertEquals(Collections.emptyList(), entryList); } @Test public void testEmptyInput() throws Exception { - assertEquals(Collections.emptyList(), fetcher.performSearch("")); + assertEquals(Collections.emptyList(), fetcher.performComplexSearch("")); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java index baedf464cfc..de802388374 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java @@ -49,7 +49,7 @@ void searchByQueryFindsEntry() throws Exception { .withField(StandardField.FILE, ":http\\://link.springer.com/openurl/pdf?id=doi\\:10.1007/s10606-018-9335-z:PDF") .withField(StandardField.ABSTRACT, "An influx of newcomers is critical to the survival, long-term success, and continuity of many Open Source Software (OSS) community-based projects. However, newcomers face many barriers when making their first contribution, leading in many cases to dropouts. Due to the collaborative nature of community-based OSS projects, newcomers may be susceptible to social barriers, such as communication breakdowns and reception issues. In this article, we report a two-phase study aimed at better understanding social barriers faced by newcomers. In the first phase, we qualitatively analyzed the literature and data collected from practitioners to identify barriers that hinder newcomers’ first contribution. We designed a model composed of 58 barriers, including 13 social barriers. In the second phase, based on the barriers model, we developed FLOSScoach, a portal to support newcomers making their first contribution. We evaluated the portal in a diary-based study and found that the portal guided the newcomers and reduced the need for communication. Our results provide insights for communities that want to support newcomers and lay a foundation for building better onboarding tools. The contributions of this paper include identifying and gathering empirical evidence of social barriers faced by newcomers; understanding how social barriers can be reduced or avoided by using a portal that organizes proper information for newcomers (FLOSScoach); presenting guidelines for communities and newcomers on how to reduce or avoid social barriers; and identifying new streams of research."); - List fetchedEntries = fetcher.performSearch("JabRef Social Barriers Steinmacher"); + List fetchedEntries = fetcher.performComplexSearch("JabRef Social Barriers Steinmacher"); assertEquals(Collections.singletonList(expected), fetchedEntries); } @@ -78,7 +78,7 @@ void testSpringerJSONToBibtex() { @Test void searchByEmptyQueryFindsNothing() throws Exception { - assertEquals(Collections.emptyList(), fetcher.performSearch("")); + assertEquals(Collections.emptyList(), fetcher.performComplexSearch("")); } @Test @@ -109,8 +109,8 @@ public void supportsPhraseSearch() throws Exception { .withField(StandardField.FILE, ":http\\://link.springer.com/openurl/pdf?id=doi\\:10.1007/978-3-319-78105-1_75:PDF") .withField(StandardField.ABSTRACT, "The iSchool Inclusion Institute (i3) is a Research Experience for Undergraduates (REU) program in the US designed to address underrepresentation in the information sciences. i3 is a year-long, cohort-based program that prepares undergraduate students for graduate school in information science and is rooted in a research and leadership development curriculum. Using data from six years of i3 cohorts, we present in this paper a qualitative and quantitative evaluation of the program in terms of student learning, research production, and graduate school enrollment. We find that students who participate in i3 report significant learning gains in information-science- and graduate-school-related areas and that 52% of i3 participants enroll in graduate school, over 2 $$\\times $$ × the national average. Based on these and additional results, we distill recommendations for future implementations of similar programs to address underrepresentation in information science."); - List resultPhrase = fetcher.performSearch("name:\"Redmiles David\""); - List result = fetcher.performSearch("name:Redmiles David"); + List resultPhrase = fetcher.performComplexSearch("author:\"Redmiles David\""); + List result = fetcher.performComplexSearch("author:Redmiles David"); // Phrase search should be a subset of the normal search result. Assertions.assertTrue(result.containsAll(resultPhrase)); @@ -120,8 +120,8 @@ public void supportsPhraseSearch() throws Exception { @Test public void supportsBooleanANDSearch() throws Exception { - List resultJustByAuthor = fetcher.performSearch("name:\"Redmiles, David\""); - List result = fetcher.performSearch("name:\"Redmiles, David\" AND journal:Computer Supported Cooperative Work"); + List resultJustByAuthor = fetcher.performComplexSearch("author:\"Redmiles, David\""); + List result = fetcher.performComplexSearch("author:\"Redmiles, David\" AND journal:\"Computer Supported Cooperative Work\""); Assertions.assertTrue(resultJustByAuthor.containsAll(result)); List allEntriesFromCSCW = result.stream() diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java index ade6bffec3e..1caed5a0973 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java @@ -50,7 +50,7 @@ void setUp() throws Exception { @Test @DisabledOnCIServer("CI server has no subscription to zbMath and thus gets 401 response") void searchByQueryFindsEntry() throws Exception { - List fetchedEntries = fetcher.performSearch("an:0507.57010"); + List fetchedEntries = fetcher.performComplexSearch("an:0507.57010"); assertEquals(Collections.singletonList(donaldsonEntry), fetchedEntries); } } From 189632595c3e9a612d91a00f0d3ea0f99426f1e6 Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Thu, 12 Nov 2020 15:01:43 +0100 Subject: [PATCH 7/8] Remove normal paged search Signed-off-by: Dominik Voigt --- .../importer/PagedSearchBasedFetcher.java | 23 +++++++++--- .../PagedSearchBasedParserFetcher.java | 26 ++----------- .../jabref/logic/importer/fetcher/ArXiv.java | 14 +++---- .../fetcher/AstrophysicsDataSystem.java | 10 ++--- .../logic/importer/fetcher/GoogleScholar.java | 37 ------------------- .../fetcher/AstrophysicsDataSystemTest.java | 6 +-- .../fetcher/PagedSearchFetcherTest.java | 4 +- 7 files changed, 36 insertions(+), 84 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java index f33c920a94b..46a13c2a92c 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java @@ -1,7 +1,9 @@ package org.jabref.logic.importer; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Optional; import org.jabref.logic.importer.fetcher.ComplexSearchQuery; import org.jabref.model.entry.BibEntry; @@ -14,15 +16,21 @@ public interface PagedSearchBasedFetcher extends SearchBasedFetcher { * @param pageNumber requested site number indexed from 0 * @return Page with search results */ - Page performSearchPaged(String query, int pageNumber) throws FetcherException; + Page performComplexSearchPaged(ComplexSearchQuery query, int pageNumber) throws FetcherException; /** - * @param query search query send to endpoint - * @param pageNumber requested site number indexed from 0 + * @param complexSearchQuery search query send to endpoint + * @param pageNumber requested site number indexed from 0 * @return Page with search results */ - default Page performComplexSearchPaged(ComplexSearchQuery query, int pageNumber) throws FetcherException { - return performSearchPaged(query.toString(), pageNumber); + default Page performComplexSearchPaged(String complexSearchQuery, int pageNumber) throws FetcherException { + if (complexSearchQuery.isBlank()) { + return new Page<>(complexSearchQuery, pageNumber, Collections.emptyList()); + } + QueryParser queryParser = new QueryParser(); + Optional generatedQuery = queryParser.parseQueryStringIntoComplexQuery(complexSearchQuery); + // Otherwise just use query as a default term + return this.performComplexSearchPaged(generatedQuery.orElse(ComplexSearchQuery.builder().defaultFieldPhrase(complexSearchQuery).build()), pageNumber); } /** @@ -36,4 +44,9 @@ default int getPageSize() { default List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { return new ArrayList<>(performComplexSearchPaged(complexSearchQuery, 0).getContent()); } + + @Override + default List performComplexSearch(String complexSearchQuery) throws FetcherException { + return new ArrayList<>(performComplexSearchPaged(complexSearchQuery, 0).getContent()); + } } diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java index bbd52d78877..c9af0ef7fe8 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java @@ -5,30 +5,24 @@ import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; -import java.util.Collections; import java.util.List; import org.jabref.logic.importer.fetcher.ComplexSearchQuery; import org.jabref.model.entry.BibEntry; import org.jabref.model.paging.Page; -import org.jabref.model.strings.StringUtil; public interface PagedSearchBasedParserFetcher extends SearchBasedParserFetcher, PagedSearchBasedFetcher { @Override - default Page performSearchPaged(String query, int pageNumber) throws FetcherException { - if (StringUtil.isBlank(query)) { - return new Page(query, pageNumber, Collections.emptyList()); - } - + default Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { // ADR-0014 URL urlForQuery; try { - urlForQuery = getURLForQuery(query, pageNumber); + urlForQuery = getComplexQueryURL(complexSearchQuery, pageNumber); } catch (URISyntaxException | MalformedURLException e) { - throw new FetcherException(String.format("Search URI crafted from query %s is malformed", query), e); + throw new FetcherException("Search URI crafted from complex search query is malformed", e); } - return new Page<>(query, pageNumber, getBibEntries(urlForQuery)); + return new Page<>(complexSearchQuery.toString(), pageNumber, getBibEntries(urlForQuery)); } private List getBibEntries(URL urlForQuery) throws FetcherException { @@ -43,18 +37,6 @@ private List getBibEntries(URL urlForQuery) throws FetcherException { } } - @Override - default Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { - // ADR-0014 - URL urlForQuery; - try { - urlForQuery = getComplexQueryURL(complexSearchQuery, pageNumber); - } catch (URISyntaxException | MalformedURLException e) { - throw new FetcherException("Search URI crafted from complex search query is malformed", e); - } - return new Page<>(complexSearchQuery.toString(), pageNumber, getBibEntries(urlForQuery)); - } - /** * Constructs a URL based on the query, size and page number. * diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java index 573111e1dec..59da79cff6c 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java @@ -249,14 +249,6 @@ public Optional getHelpPage() { return Optional.of(HelpFile.FETCHER_OAI2_ARXIV); } - @Override - public Page performSearchPaged(String query, int pageNumber) throws FetcherException { - List searchResult = searchForEntries(query, pageNumber).stream() - .map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator())) - .collect(Collectors.toList()); - return new Page<>(query, pageNumber, searchResult); - } - /** * Constructs a complex query string using the field prefixes specified at https://arxiv.org/help/api/user-manual * @@ -274,7 +266,11 @@ public Page performComplexSearchPaged(ComplexSearchQuery complexSearch complexSearchQuery.getToYear().ifPresent(year -> searchTerms.add(year.toString())); searchTerms.addAll(complexSearchQuery.getDefaultFieldPhrases()); String complexQueryString = String.join(" AND ", searchTerms); - return performSearchPaged(complexQueryString, pageNumber); + + List searchResult = searchForEntries(complexQueryString, pageNumber).stream() + .map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator())) + .collect(Collectors.toList()); + return new Page<>(complexQueryString, pageNumber, searchResult); } @Override diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java index 05e07a03acb..02716718c35 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java @@ -274,14 +274,12 @@ private List performSearchByIds(Collection identifiers) throws } @Override - public Page performSearchPaged(String query, int pageNumber) throws FetcherException { - if (StringUtil.isBlank(query)) { - return new Page<>(query, pageNumber); - } + public Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { try { - List bibcodes = fetchBibcodes(getURLForQuery(query, pageNumber)); + // This is currently just interpreting the complex query as a default string query + List bibcodes = fetchBibcodes(getComplexQueryURL(complexSearchQuery, pageNumber)); Collection results = performSearchByIds(bibcodes); - return new Page<>(query, pageNumber, results); + return new Page<>(complexSearchQuery.toString(), pageNumber, results); } catch (URISyntaxException e) { throw new FetcherException("Search URI is malformed", e); } catch (IOException e) { diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java index fa804a7ad07..579e7b1d7fe 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java @@ -184,43 +184,6 @@ private void obtainAndModifyCookie() throws FetcherException { } } - @Override - public Page performSearchPaged(String query, int pageNumber) throws FetcherException { - LOGGER.debug("Using URL {}", query); - obtainAndModifyCookie(); - List foundEntries = new ArrayList<>(20); - - URIBuilder uriBuilder; - try { - uriBuilder = new URIBuilder(BASIC_SEARCH_URL); - } catch (URISyntaxException e) { - throw new FetcherException("Error while fetching from " + getName() + " at URL " + BASIC_SEARCH_URL, e); - } - - uriBuilder.addParameter("hl", "en"); - uriBuilder.addParameter("start", String.valueOf(pageNumber * getPageSize())); - uriBuilder.addParameter("q", query); - uriBuilder.addParameter("num", String.valueOf(getPageSize())); - uriBuilder.addParameter("btnG", "Search"); - String queryURL = uriBuilder.toString(); - - try { - addHitsFromQuery(foundEntries, queryURL); - } catch (IOException e) { - // if there are too much requests from the same IP address google is answering with a 503 and redirecting to a captcha challenge - // The caught IOException looks for example like this: - // java.io.IOException: Server returned HTTP response code: 503 for URL: https://ipv4.google.com/sorry/index?continue=https://scholar.google.com/scholar%3Fhl%3Den%26btnG%3DSearch%26q%3Dbpmn&hl=en&q=CGMSBI0NBDkYuqy9wAUiGQDxp4NLQCWbIEY1HjpH5zFJhv4ANPGdWj0 - if (e.getMessage().contains("Server returned HTTP response code: 503 for URL")) { - throw new FetcherException("Fetching from Google Scholar at URL " + queryURL + " failed.", - Localization.lang("This might be caused by reaching the traffic limitation of Google Scholar (see 'Help' for details)."), e); - } else { - throw new FetcherException("Error while fetching from " + getName() + " at URL " + queryURL, e); - } - } - - return new Page<>(query, pageNumber, foundEntries); - } - @Override public Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { try { diff --git a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java index 6f8fd13f4b9..66b13b87c6c 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java @@ -203,14 +203,14 @@ public void testPerformSearchByLuceyPaulEntry() throws Exception { @Test public void performSearchByQueryPaged_searchLimitsSize() throws Exception { - Page page = fetcher.performSearchPaged("author:\"A\"", 0); + Page page = fetcher.performComplexSearchPaged("author:\"A\"", 0); assertEquals(fetcher.getPageSize(), page.getSize(), "fetcher return wrong page size"); } @Test public void performSearchByQueryPaged_invalidAuthorsReturnEmptyPages() throws Exception { - Page page = fetcher.performSearchPaged("author:\"ThisAuthorWillNotBeFound\"", 0); - Page page5 = fetcher.performSearchPaged("author:\"ThisAuthorWillNotBeFound\"", 5); + Page page = fetcher.performComplexSearchPaged("author:\"ThisAuthorWillNotBeFound\"", 0); + Page page5 = fetcher.performComplexSearchPaged("author:\"ThisAuthorWillNotBeFound\"", 5); assertEquals(0, page.getSize(), "fetcher doesnt return empty pages for invalid author"); assertEquals(0, page5.getSize(), "fetcher doesnt return empty pages for invalid author"); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java index 43902fe9fa2..49633ad5d18 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java @@ -19,8 +19,8 @@ public interface PagedSearchFetcherTest { @Test default void pageSearchReturnsUniqueResultsPerPage() throws Exception { String query = "Software"; - Page firstPage = getPagedFetcher().performSearchPaged(query, 0); - Page secondPage = getPagedFetcher().performSearchPaged(query, 1); + Page firstPage = getPagedFetcher().performComplexSearchPaged(query, 0); + Page secondPage = getPagedFetcher().performComplexSearchPaged(query, 1); for (BibEntry entry : firstPage.getContent()) { assertFalse(secondPage.getContent().contains(entry)); From 4e4e4197fececedf1984fe016edf6248eda0abfb Mon Sep 17 00:00:00 2001 From: Dominik Voigt Date: Fri, 13 Nov 2020 16:00:02 +0100 Subject: [PATCH 8/8] Remove the complex part from perform search Adapt query parser and add new tests Signed-off-by: Dominik Voigt --- .../org/jabref/cli/ArgumentProcessor.java | 2 +- .../BibtexExtractorViewModel.java | 2 +- .../fetcher/WebSearchPaneViewModel.java | 2 +- .../importer/PagedSearchBasedFetcher.java | 20 ++++++------ .../PagedSearchBasedParserFetcher.java | 10 +++--- .../jabref/logic/importer/QueryParser.java | 15 ++++----- .../logic/importer/SearchBasedFetcher.java | 14 ++++---- .../importer/SearchBasedParserFetcher.java | 32 +++++++++---------- .../jabref/logic/importer/fetcher/ArXiv.java | 2 +- .../fetcher/AstrophysicsDataSystem.java | 2 +- .../importer/fetcher/ComplexSearchQuery.java | 4 +-- .../fetcher/CompositeSearchBasedFetcher.java | 4 +-- .../logic/importer/fetcher/GoogleScholar.java | 2 +- .../fetcher/GrobidCitationFetcher.java | 2 +- .../logic/importer/fetcher/JstorFetcher.java | 32 +++++++++---------- .../importer/fetcher/MedlineFetcher.java | 2 +- .../logic/importer/QueryParserTest.java | 30 ++++++++++++----- .../fetcher/ACMPortalFetcherTest.java | 2 +- .../logic/importer/fetcher/ArXivTest.java | 12 +++---- .../fetcher/AstrophysicsDataSystemTest.java | 8 ++--- .../logic/importer/fetcher/CiteSeerTest.java | 4 +-- ...puterScienceBibliographiesFetcherTest.java | 4 +-- .../CompositeSearchBasedFetcherTest.java | 8 ++--- .../logic/importer/fetcher/CrossRefTest.java | 4 +-- .../importer/fetcher/DBLPFetcherTest.java | 6 ++-- .../importer/fetcher/DOAJFetcherTest.java | 4 +-- .../importer/fetcher/GoogleScholarTest.java | 4 +-- .../fetcher/GrobidCitationFetcherTest.java | 10 +++--- .../importer/fetcher/GvkFetcherTest.java | 8 ++--- .../logic/importer/fetcher/IEEETest.java | 4 +-- .../importer/fetcher/INSPIREFetcherTest.java | 4 +-- .../importer/fetcher/JstorFetcherTest.java | 2 +- .../importer/fetcher/MathSciNetTest.java | 2 +- .../importer/fetcher/MedlineFetcherTest.java | 6 ++-- .../fetcher/PagedSearchFetcherTest.java | 4 +-- .../SearchBasedFetcherCapabilityTest.java | 8 ++--- .../importer/fetcher/SpringerFetcherTest.java | 12 +++---- .../logic/importer/fetcher/ZbMATHTest.java | 2 +- 38 files changed, 154 insertions(+), 141 deletions(-) diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index dc87122cb62..eeee79c1366 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -550,7 +550,7 @@ private Optional fetch(String fetchCommand) { System.out.println(Localization.lang("Running query '%0' with fetcher '%1'.", query, engine)); System.out.print(Localization.lang("Please wait...")); try { - List matches = selectedFetcher.get().performComplexSearch(query); + List matches = selectedFetcher.get().performSearch(query); if (matches.isEmpty()) { System.out.println("\r" + Localization.lang("No results found.")); return Optional.empty(); diff --git a/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java b/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java index 83069aba600..f1d99d74331 100644 --- a/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java +++ b/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java @@ -62,7 +62,7 @@ public StringProperty inputTextProperty() { } public void startParsing() { - BackgroundTask.wrap(() -> currentCitationfetcher.performComplexSearch(inputTextProperty.getValue())) + BackgroundTask.wrap(() -> currentCitationfetcher.performSearch(inputTextProperty.getValue())) .onRunning(() -> dialogService.notify(Localization.lang("Your text is being parsed..."))) .onFailure((e) -> { if (e instanceof FetcherException) { diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java index fb982f6b7c7..774fcc538f7 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java @@ -106,7 +106,7 @@ public void search() { SearchBasedFetcher activeFetcher = getSelectedFetcher(); BackgroundTask task; - task = BackgroundTask.wrap(() -> new ParserResult(activeFetcher.performComplexSearch(getQuery().trim()))) + task = BackgroundTask.wrap(() -> new ParserResult(activeFetcher.performSearch(getQuery().trim()))) .withInitialMessage(Localization.lang("Processing %0", getQuery().trim())); task.onFailure(dialogService::showErrorDialogAndWait); diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java index 46a13c2a92c..ea547522049 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java @@ -12,25 +12,25 @@ public interface PagedSearchBasedFetcher extends SearchBasedFetcher { /** - * @param query search query send to endpoint - * @param pageNumber requested site number indexed from 0 + * @param complexSearchQuery the complex query defining all fielded search parameters + * @param pageNumber requested site number indexed from 0 * @return Page with search results */ - Page performComplexSearchPaged(ComplexSearchQuery query, int pageNumber) throws FetcherException; + Page performSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException; /** - * @param complexSearchQuery search query send to endpoint + * @param complexSearchQuery query string that can be parsed into a complex search query * @param pageNumber requested site number indexed from 0 * @return Page with search results */ - default Page performComplexSearchPaged(String complexSearchQuery, int pageNumber) throws FetcherException { + default Page performSearchPaged(String complexSearchQuery, int pageNumber) throws FetcherException { if (complexSearchQuery.isBlank()) { return new Page<>(complexSearchQuery, pageNumber, Collections.emptyList()); } QueryParser queryParser = new QueryParser(); Optional generatedQuery = queryParser.parseQueryStringIntoComplexQuery(complexSearchQuery); // Otherwise just use query as a default term - return this.performComplexSearchPaged(generatedQuery.orElse(ComplexSearchQuery.builder().defaultFieldPhrase(complexSearchQuery).build()), pageNumber); + return this.performSearchPaged(generatedQuery.orElse(ComplexSearchQuery.builder().defaultFieldPhrase(complexSearchQuery).build()), pageNumber); } /** @@ -41,12 +41,12 @@ default int getPageSize() { } @Override - default List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { - return new ArrayList<>(performComplexSearchPaged(complexSearchQuery, 0).getContent()); + default List performSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { + return new ArrayList<>(performSearchPaged(complexSearchQuery, 0).getContent()); } @Override - default List performComplexSearch(String complexSearchQuery) throws FetcherException { - return new ArrayList<>(performComplexSearchPaged(complexSearchQuery, 0).getContent()); + default List performSearch(String complexSearchQuery) throws FetcherException { + return new ArrayList<>(performSearchPaged(complexSearchQuery, 0).getContent()); } } diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java index c9af0ef7fe8..7f7b3380f0b 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedParserFetcher.java @@ -14,7 +14,7 @@ public interface PagedSearchBasedParserFetcher extends SearchBasedParserFetcher, PagedSearchBasedFetcher { @Override - default Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { + default Page performSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { // ADR-0014 URL urlForQuery; try { @@ -56,8 +56,8 @@ default URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery, int pageNu } @Override - default List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { - return SearchBasedParserFetcher.super.performComplexSearch(complexSearchQuery); + default List performSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { + return SearchBasedParserFetcher.super.performSearch(complexSearchQuery); } @Override @@ -66,7 +66,7 @@ default URL getURLForQuery(String query) throws URISyntaxException, MalformedURL } @Override - default URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery) throws URISyntaxException, MalformedURLException, FetcherException { - return getComplexQueryURL(complexSearchQuery, 0); + default URL getURLForQuery(ComplexSearchQuery query) throws URISyntaxException, MalformedURLException, FetcherException { + return getComplexQueryURL(query, 0); } } diff --git a/src/main/java/org/jabref/logic/importer/QueryParser.java b/src/main/java/org/jabref/logic/importer/QueryParser.java index 6bec3eae988..65359122ff2 100644 --- a/src/main/java/org/jabref/logic/importer/QueryParser.java +++ b/src/main/java/org/jabref/logic/importer/QueryParser.java @@ -16,24 +16,23 @@ import org.apache.lucene.search.QueryVisitor; /** - * This class converts a query string written in lucene syntax into a complex search query. + * This class converts a query string written in lucene syntax into a complex query. * - * For simplicity this is limited to fielded data and the boolean AND operator. + * For simplicity this is currently limited to fielded data and the boolean AND operator. */ public class QueryParser { /** * Parses the given query string into a complex query using lucene. - * Note: For unique fields, the alphabetically first instance in the query string is used in the complex query. + * Note: For unique fields, the alphabetically and numerically first instance in the query string is used in the complex query. * - * @param queryString The given query string + * @param query The given query string * @return A complex query containing all fields of the query string - * @throws QueryNodeException Error during parsing */ - public Optional parseQueryStringIntoComplexQuery(String queryString) { + public Optional parseQueryStringIntoComplexQuery(String query) { try { StandardQueryParser parser = new StandardQueryParser(); - Query luceneQuery = parser.parse(queryString, "default"); + Query luceneQuery = parser.parse(query, "default"); Set terms = new HashSet<>(); // This implementation collects all terms from the leaves of the query tree independent of the internal boolean structure // If further capabilities are required in the future the visitor and ComplexSearchQuery has to be adapted accordingly. @@ -42,7 +41,7 @@ public Optional parseQueryStringIntoComplexQuery(String quer List sortedTerms = new ArrayList<>(terms); sortedTerms.sort(Comparator.comparing(Term::text).reversed()); - return Optional.of(ComplexSearchQuery.fromTerms(terms)); + return Optional.of(ComplexSearchQuery.fromTerms(sortedTerms)); } catch (QueryNodeException | IllegalStateException | IllegalArgumentException ex) { return Optional.empty(); } diff --git a/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java index c60619e5b35..faeb4ffa6f6 100644 --- a/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/SearchBasedFetcher.java @@ -16,24 +16,24 @@ public interface SearchBasedFetcher extends WebFetcher { /** * This method is used to send complex queries using fielded search. * - * @param complexSearchQuery the search query defining all fielded search parameters + * @param complexSearchQuery the complex search query defining all fielded search parameters * @return a list of {@link BibEntry}, which are matched by the query (may be empty) */ - List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException; + List performSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException; /** * Looks for hits which are matched by the given free-text query. * - * @param query search string + * @param complexSearchQuery query string that can be parsed into a complex search query * @return a list of {@link BibEntry}, which are matched by the query (may be empty) */ - default List performComplexSearch(String query) throws FetcherException { - if (query.isBlank()) { + default List performSearch(String complexSearchQuery) throws FetcherException { + if (complexSearchQuery.isBlank()) { return Collections.emptyList(); } QueryParser queryParser = new QueryParser(); - Optional generatedQuery = queryParser.parseQueryStringIntoComplexQuery(query); + Optional generatedQuery = queryParser.parseQueryStringIntoComplexQuery(complexSearchQuery); // Otherwise just use query as a default term - return this.performComplexSearch(generatedQuery.orElse(ComplexSearchQuery.builder().defaultFieldPhrase(query).build())); + return this.performSearch(generatedQuery.orElse(ComplexSearchQuery.builder().defaultFieldPhrase(complexSearchQuery).build())); } } diff --git a/src/main/java/org/jabref/logic/importer/SearchBasedParserFetcher.java b/src/main/java/org/jabref/logic/importer/SearchBasedParserFetcher.java index ff83aa7c8e9..d0817ade6a0 100644 --- a/src/main/java/org/jabref/logic/importer/SearchBasedParserFetcher.java +++ b/src/main/java/org/jabref/logic/importer/SearchBasedParserFetcher.java @@ -21,18 +21,6 @@ */ public interface SearchBasedParserFetcher extends SearchBasedFetcher { - /** - * Constructs a URL based on the query. - * - * @param query the search query - */ - URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException, FetcherException; - - /** - * Returns the parser used to convert the response to a list of {@link BibEntry}. - */ - Parser getParser(); - /** * This method is used to send queries with advanced URL parameters. * This method is necessary as the performSearch method does not support certain URL parameters that are used for @@ -41,11 +29,11 @@ public interface SearchBasedParserFetcher extends SearchBasedFetcher { * @param complexSearchQuery the search query defining all fielded search parameters */ @Override - default List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { + default List performSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { // ADR-0014 URL urlForQuery; try { - urlForQuery = getComplexQueryURL(complexSearchQuery); + urlForQuery = getURLForQuery(complexSearchQuery); } catch (URISyntaxException | MalformedURLException | FetcherException e) { throw new FetcherException("Search URI crafted from complex search query is malformed", e); } @@ -64,11 +52,23 @@ private List getBibEntries(URL urlForQuery) throws FetcherException { } } - default URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery) throws URISyntaxException, MalformedURLException, FetcherException { + default URL getURLForQuery(ComplexSearchQuery query) throws URISyntaxException, MalformedURLException, FetcherException { // Default implementation behaves as getURLForQuery treating complex query as plain string query - return this.getURLForQuery(complexSearchQuery.toString()); + return this.getURLForQuery(query.toString()); } + /** + * Returns the parser used to convert the response to a list of {@link BibEntry}. + */ + Parser getParser(); + + /** + * Constructs a URL based on the query. + * + * @param query the search query + */ + URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException, FetcherException; + /** * Performs a cleanup of the fetched entry. *

diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java index 59da79cff6c..9b640cdd7f0 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java @@ -256,7 +256,7 @@ public Optional getHelpPage() { * @return A list of entries matching the complex query */ @Override - public Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { + public Page performSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { List searchTerms = new ArrayList<>(); complexSearchQuery.getAuthors().forEach(author -> searchTerms.add("au:" + author)); complexSearchQuery.getTitlePhrases().forEach(title -> searchTerms.add("ti:" + title)); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java index 02716718c35..a266418b351 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java @@ -274,7 +274,7 @@ private List performSearchByIds(Collection identifiers) throws } @Override - public Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { + public Page performSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { try { // This is currently just interpreting the complex query as a default string query List bibcodes = fetchBibcodes(getComplexQueryURL(complexSearchQuery, pageNumber)); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java b/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java index 6fe86b92e09..ade12d2d8b9 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ComplexSearchQuery.java @@ -34,7 +34,7 @@ private ComplexSearchQuery(List defaultField, List authors, List this.singleYear = singleYear; } - public static ComplexSearchQuery fromTerms(Collection terms) { + public static ComplexSearchQuery fromTerms(List terms) { ComplexSearchQueryBuilder builder = ComplexSearchQuery.builder(); terms.forEach(term -> { String termText = term.text(); @@ -249,7 +249,7 @@ public ComplexSearchQueryBuilder terms(Collection terms) { * Instantiates the AdvancesSearchConfig from the provided Builder parameters * If all text fields are empty an empty optional is returned * - * @return AdvancedSearchConfig instance with the fields set to the values defined in the building instance. + * @return ComplexSearchQuery instance with the fields set to the values defined in the building instance. * @throws IllegalStateException An IllegalStateException is thrown in case all text search fields are empty. * See: https://softwareengineering.stackexchange.com/questions/241309/builder-pattern-when-to-fail/241320#241320 */ diff --git a/src/main/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcher.java index f5bb271757c..3ce32ebeee6 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcher.java @@ -36,13 +36,13 @@ public CompositeSearchBasedFetcher(Set searchBasedFetchers, } @Override - public List performComplexSearch(ComplexSearchQuery complexSearchQuery) { + public List performSearch(ComplexSearchQuery complexSearchQuery) { ImportCleanup cleanup = new ImportCleanup(BibDatabaseMode.BIBTEX); // All entries have to be converted into one format, this is necessary for the format conversion return fetchers.parallelStream() .flatMap(searchBasedFetcher -> { try { - return searchBasedFetcher.performComplexSearch(complexSearchQuery).stream(); + return searchBasedFetcher.performSearch(complexSearchQuery).stream(); } catch (FetcherException e) { LOGGER.warn(String.format("%s API request failed", searchBasedFetcher.getName()), e); return Stream.empty(); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java index 579e7b1d7fe..58d6c8546b7 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GoogleScholar.java @@ -185,7 +185,7 @@ private void obtainAndModifyCookie() throws FetcherException { } @Override - public Page performComplexSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { + public Page performSearchPaged(ComplexSearchQuery complexSearchQuery, int pageNumber) throws FetcherException { try { obtainAndModifyCookie(); List foundEntries = new ArrayList<>(10); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java index 4fddd4c1587..61218575668 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java @@ -66,7 +66,7 @@ private Optional parseBibToBibEntry(String bibtexString) { } @Override - public List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { + public List performSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { List bibEntries = null; // This just treats the complex query like a normal string query until it it implemented correctly String query = complexSearchQuery.toString(); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/JstorFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/JstorFetcher.java index 9f8cb7de04a..eb50f3fef1d 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/JstorFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/JstorFetcher.java @@ -48,34 +48,34 @@ public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLE } @Override - public URL getComplexQueryURL(ComplexSearchQuery complexSearchQuery) throws URISyntaxException, MalformedURLException, FetcherException { + public URL getURLForQuery(ComplexSearchQuery query) throws URISyntaxException, MalformedURLException, FetcherException { URIBuilder uriBuilder = new URIBuilder(SEARCH_HOST); StringBuilder stringBuilder = new StringBuilder(); - if (!complexSearchQuery.getDefaultFieldPhrases().isEmpty()) { - stringBuilder.append(complexSearchQuery.getDefaultFieldPhrases()); + if (!query.getDefaultFieldPhrases().isEmpty()) { + stringBuilder.append(query.getDefaultFieldPhrases()); } - if (!complexSearchQuery.getAuthors().isEmpty()) { - for (String author : complexSearchQuery.getAuthors()) { + if (!query.getAuthors().isEmpty()) { + for (String author : query.getAuthors()) { stringBuilder.append("au:").append(author); } } - if (!complexSearchQuery.getTitlePhrases().isEmpty()) { - for (String title : complexSearchQuery.getTitlePhrases()) { + if (!query.getTitlePhrases().isEmpty()) { + for (String title : query.getTitlePhrases()) { stringBuilder.append("ti:").append(title); } } - if (complexSearchQuery.getJournal().isPresent()) { - stringBuilder.append("pt:").append(complexSearchQuery.getJournal().get()); + if (query.getJournal().isPresent()) { + stringBuilder.append("pt:").append(query.getJournal().get()); } - if (complexSearchQuery.getSingleYear().isPresent()) { - uriBuilder.addParameter("sd", String.valueOf(complexSearchQuery.getSingleYear().get())); - uriBuilder.addParameter("ed", String.valueOf(complexSearchQuery.getSingleYear().get())); + if (query.getSingleYear().isPresent()) { + uriBuilder.addParameter("sd", String.valueOf(query.getSingleYear().get())); + uriBuilder.addParameter("ed", String.valueOf(query.getSingleYear().get())); } - if (complexSearchQuery.getFromYear().isPresent()) { - uriBuilder.addParameter("sd", String.valueOf(complexSearchQuery.getFromYear().get())); + if (query.getFromYear().isPresent()) { + uriBuilder.addParameter("sd", String.valueOf(query.getFromYear().get())); } - if (complexSearchQuery.getToYear().isPresent()) { - uriBuilder.addParameter("ed", String.valueOf(complexSearchQuery.getToYear().get())); + if (query.getToYear().isPresent()) { + uriBuilder.addParameter("ed", String.valueOf(query.getToYear().get())); } uriBuilder.addParameter("Query", stringBuilder.toString()); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java index e47937b610d..a4553bc876b 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/MedlineFetcher.java @@ -158,7 +158,7 @@ public void doPostCleanup(BibEntry entry) { } @Override - public List performComplexSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { + public List performSearch(ComplexSearchQuery complexSearchQuery) throws FetcherException { List entryList; String query = complexSearchQuery.toString(); diff --git a/src/test/java/org/jabref/logic/importer/QueryParserTest.java b/src/test/java/org/jabref/logic/importer/QueryParserTest.java index 624117d5289..970788e86c3 100644 --- a/src/test/java/org/jabref/logic/importer/QueryParserTest.java +++ b/src/test/java/org/jabref/logic/importer/QueryParserTest.java @@ -10,49 +10,63 @@ class QueryParserTest { QueryParser parser = new QueryParser(); @Test - public void convertAuthorField() throws Exception { + public void convertAuthorField() { ComplexSearchQuery searchQuery = parser.parseQueryStringIntoComplexQuery("author:\"Igor Steinmacher\"").get(); ComplexSearchQuery expectedQuery = ComplexSearchQuery.builder().author("\"Igor Steinmacher\"").build(); assertEquals(expectedQuery, searchQuery); } @Test - public void convertDefaultField() throws Exception { + public void convertDefaultField() { ComplexSearchQuery searchQuery = parser.parseQueryStringIntoComplexQuery("\"default value\"").get(); ComplexSearchQuery expectedQuery = ComplexSearchQuery.builder().defaultFieldPhrase("\"default value\"").build(); assertEquals(expectedQuery, searchQuery); } @Test - public void convertExplicitDefaultField() throws Exception { + public void convertExplicitDefaultField() { ComplexSearchQuery searchQuery = parser.parseQueryStringIntoComplexQuery("default:\"default value\"").get(); ComplexSearchQuery expectedQuery = ComplexSearchQuery.builder().defaultFieldPhrase("\"default value\"").build(); assertEquals(expectedQuery, searchQuery); } @Test - public void convertJournalField() throws Exception { - ComplexSearchQuery searchQuery = parser.parseQueryStringIntoComplexQuery("journal:\"Nature\"").get(); + public void convertJournalField() { + ComplexSearchQuery searchQuery = parser.parseQueryStringIntoComplexQuery("journal:Nature").get(); ComplexSearchQuery expectedQuery = ComplexSearchQuery.builder().journal("\"Nature\"").build(); assertEquals(expectedQuery, searchQuery); } @Test - public void convertYearField() throws Exception { + public void convertAlphabeticallyFirstJournalField() { + ComplexSearchQuery searchQuery = parser.parseQueryStringIntoComplexQuery("journal:Nature journal:\"Complex Networks\"").get(); + ComplexSearchQuery expectedQuery = ComplexSearchQuery.builder().journal("\"Complex Networks\"").build(); + assertEquals(expectedQuery, searchQuery); + } + + @Test + public void convertYearField() { ComplexSearchQuery searchQuery = parser.parseQueryStringIntoComplexQuery("year:2015").get(); ComplexSearchQuery expectedQuery = ComplexSearchQuery.builder().singleYear(2015).build(); assertEquals(expectedQuery, searchQuery); } @Test - public void convertYearRangeField() throws Exception { + public void convertNumericallyFirstYearField() { + ComplexSearchQuery searchQuery = parser.parseQueryStringIntoComplexQuery("year:2015 year:2014").get(); + ComplexSearchQuery expectedQuery = ComplexSearchQuery.builder().singleYear(2014).build(); + assertEquals(expectedQuery, searchQuery); + } + + @Test + public void convertYearRangeField() { ComplexSearchQuery searchQuery = parser.parseQueryStringIntoComplexQuery("year-range:2012-2015").get(); ComplexSearchQuery expectedQuery = ComplexSearchQuery.builder().fromYearAndToYear(2012, 2015).build(); assertEquals(expectedQuery, searchQuery); } @Test - public void convertMultipleValuesWithTheSameField() throws Exception { + public void convertMultipleValuesWithTheSameField() { ComplexSearchQuery searchQuery = parser.parseQueryStringIntoComplexQuery("author:\"Igor Steinmacher\" author:\"Christoph Treude\"").get(); ComplexSearchQuery expectedQuery = ComplexSearchQuery.builder().author("\"Igor Steinmacher\"").author("\"Christoph Treude\"").build(); assertEquals(expectedQuery, searchQuery); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java index 1cc7b47466e..420047cd79e 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java @@ -51,7 +51,7 @@ void searchByQueryFindsEntry() throws Exception { expected.setField(StandardField.URL, "http://doi.acm.org/10.1145/3129790.3129810"); expected.setField(StandardField.YEAR, "2017"); - List fetchedEntries = fetcher.performComplexSearch("jabref architectural churn"); + List fetchedEntries = fetcher.performSearch("jabref architectural churn"); assertEquals(Collections.singletonList(expected), fetchedEntries); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java index 4e720ebcf5f..9fdf8b15ee8 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java @@ -136,13 +136,13 @@ void findFullTextTrustLevel() { @Test void searchEntryByPartOfTitle() throws Exception { assertEquals(Collections.singletonList(sliceTheoremPaper), - fetcher.performComplexSearch("title:\"slice theorem for Frechet\"")); + fetcher.performSearch("title:\"slice theorem for Frechet\"")); } @Test void searchEntryByPartOfTitleWithAcuteAccent() throws Exception { assertEquals(Collections.singletonList(sliceTheoremPaper), - fetcher.performComplexSearch("title:\"slice theorem for Fréchet\"")); + fetcher.performSearch("title:\"slice theorem for Fréchet\"")); } @Test @@ -256,8 +256,8 @@ public String getTestJournal() { */ @Test public void supportsPhraseSearch() throws Exception { - List resultWithPhraseSearch = fetcher.performComplexSearch("title:\"Taxonomy of Distributed\""); - List resultWithOutPhraseSearch = fetcher.performComplexSearch("title:Taxonomy AND title:of AND title:Distributed"); + List resultWithPhraseSearch = fetcher.performSearch("title:\"Taxonomy of Distributed\""); + List resultWithOutPhraseSearch = fetcher.performSearch("title:Taxonomy AND title:of AND title:Distributed"); // Phrase search result has to be subset of the default search result assertTrue(resultWithOutPhraseSearch.containsAll(resultWithPhraseSearch)); } @@ -279,7 +279,7 @@ public void supportsPhraseSearchAndMatchesExact() throws Exception { .withField(StandardField.EPRINTCLASS, "cs.DC") .withField(StandardField.KEYWORDS, "cs.DC, cs.LG"); - List resultWithPhraseSearch = fetcher.performComplexSearch("title:\"Taxonomy of Distributed\""); + List resultWithPhraseSearch = fetcher.performSearch("title:\"Taxonomy of Distributed\""); // There is only a single paper found by searching that contains the exact sequence "Taxonomy of Distributed" in the title. assertEquals(Collections.singletonList(expected), resultWithPhraseSearch); @@ -305,7 +305,7 @@ public void supportsBooleanANDSearch() throws Exception { .withField(StandardField.EPRINTCLASS, "q-bio.TO") .withField(StandardField.KEYWORDS, "q-bio.TO"); - List result = fetcher.performComplexSearch("author:\"Tobias Büscher\" AND title:\"Instability and fingering of interfaces\""); + List result = fetcher.performSearch("author:\"Tobias Büscher\" AND title:\"Instability and fingering of interfaces\""); // There is only one paper authored by Tobias Büscher with that phrase in the title assertEquals(Collections.singletonList(expected), result); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java index 66b13b87c6c..7f5c708047f 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystemTest.java @@ -143,7 +143,7 @@ public void testGetName() { @Test public void searchByQueryFindsEntry() throws Exception { - List fetchedEntries = fetcher.performComplexSearch("Diez slice theorem Lie"); + List fetchedEntries = fetcher.performSearch("Diez slice theorem Lie"); assertTrue(fetchedEntries.contains(diezSliceTheoremEntry)); } @@ -203,14 +203,14 @@ public void testPerformSearchByLuceyPaulEntry() throws Exception { @Test public void performSearchByQueryPaged_searchLimitsSize() throws Exception { - Page page = fetcher.performComplexSearchPaged("author:\"A\"", 0); + Page page = fetcher.performSearchPaged("author:\"A\"", 0); assertEquals(fetcher.getPageSize(), page.getSize(), "fetcher return wrong page size"); } @Test public void performSearchByQueryPaged_invalidAuthorsReturnEmptyPages() throws Exception { - Page page = fetcher.performComplexSearchPaged("author:\"ThisAuthorWillNotBeFound\"", 0); - Page page5 = fetcher.performComplexSearchPaged("author:\"ThisAuthorWillNotBeFound\"", 5); + Page page = fetcher.performSearchPaged("author:\"ThisAuthorWillNotBeFound\"", 0); + Page page5 = fetcher.performSearchPaged("author:\"ThisAuthorWillNotBeFound\"", 5); assertEquals(0, page.getSize(), "fetcher doesnt return empty pages for invalid author"); assertEquals(0, page5.getSize(), "fetcher doesnt return empty pages for invalid author"); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CiteSeerTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CiteSeerTest.java index eb2040a0633..e2f6f2951a1 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CiteSeerTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CiteSeerTest.java @@ -26,7 +26,7 @@ void searchByQueryFindsEntryRigorousDerivation() throws Exception { .withField(StandardField.TITLE, "Rigorous Derivation from Landau-de Gennes Theory to Eericksen-leslie Theory") .withField(StandardField.DOI, "10.1.1.744.5780"); - List fetchedEntries = fetcher.performComplexSearch("title:Ericksen-Leslie AND venue:q AND ncites:[10 TO 15000]"); + List fetchedEntries = fetcher.performSearch("title:Ericksen-Leslie AND venue:q AND ncites:[10 TO 15000]"); assertEquals(Collections.singletonList(expected), fetchedEntries); } @@ -39,7 +39,7 @@ void searchByQueryFindsEntryCopingTheoryAndResearch() throws Exception { .withField(StandardField.YEAR, "1993") .withField(StandardField.JOURNALTITLE, "PSYCHOSOMATIC MEDICINE"); - List fetchedEntries = fetcher.performComplexSearch("doi:10.1.1.115.9665"); + List fetchedEntries = fetcher.performSearch("doi:10.1.1.115.9665"); assertEquals(Collections.singletonList(expected), fetchedEntries); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java index eae7c929a1e..577f4624196 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CollectionOfComputerScienceBibliographiesFetcherTest.java @@ -49,7 +49,7 @@ public void getUrlForQueryReturnsCorrectUrl() throws MalformedURLException, URIS @Test public void performSearchReturnsMatchingMultipleEntries() throws FetcherException { - List searchResult = fetcher.performComplexSearch("jabref"); + List searchResult = fetcher.performSearch("jabref"); BibEntry firstBibEntry = new BibEntry(StandardEntryType.InProceedings) .withCitationKey("conf/ecsa/OlssonEW17") @@ -117,7 +117,7 @@ public void performSearchReturnsMatchingMultipleEntries() throws FetcherExceptio @Test public void performSearchReturnsEmptyListForEmptySearch() throws FetcherException { - List searchResult = fetcher.performComplexSearch(""); + List searchResult = fetcher.performSearch(""); assertEquals(Collections.emptyList(), searchResult); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java index b25b9a99d87..b0b326c50d5 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java @@ -43,7 +43,7 @@ public void performSearchWithoutFetchers() throws Exception { Set empty = new HashSet<>(); CompositeSearchBasedFetcher fetcher = new CompositeSearchBasedFetcher(empty, Integer.MAX_VALUE); - List result = fetcher.performComplexSearch("quantum"); + List result = fetcher.performSearch("quantum"); Assertions.assertEquals(result, Collections.EMPTY_LIST); } @@ -53,7 +53,7 @@ public void performSearchWithoutFetchers() throws Exception { public void performSearchOnEmptyQuery(Set fetchers) throws Exception { CompositeSearchBasedFetcher compositeFetcher = new CompositeSearchBasedFetcher(fetchers, Integer.MAX_VALUE); - List queryResult = compositeFetcher.performComplexSearch(""); + List queryResult = compositeFetcher.performSearch(""); Assertions.assertEquals(queryResult, Collections.EMPTY_LIST); } @@ -65,10 +65,10 @@ public void performSearchOnNonEmptyQuery(Set fetchers) throw CompositeSearchBasedFetcher compositeFetcher = new CompositeSearchBasedFetcher(fetchers, Integer.MAX_VALUE); ImportCleanup cleanup = new ImportCleanup(BibDatabaseMode.BIBTEX); - List compositeResult = compositeFetcher.performComplexSearch("quantum"); + List compositeResult = compositeFetcher.performSearch("quantum"); for (SearchBasedFetcher fetcher : fetchers) { try { - List fetcherResult = fetcher.performComplexSearch("quantum"); + List fetcherResult = fetcher.performSearch("quantum"); fetcherResult.forEach(cleanup::doPostCleanup); Assertions.assertTrue(compositeResult.containsAll(fetcherResult)); } catch (FetcherException e) { diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java index 6386aed81e2..130206433ec 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java @@ -105,7 +105,7 @@ public void findByDOI() throws Exception { @Test public void findByAuthors() throws Exception { - assertEquals(Optional.of(barrosEntry), fetcher.performComplexSearch("\"Barros, Alistair\" AND \"Dumas, Marlon\" AND \"Arthur H.M. ter Hofstede\"").stream().findFirst()); + assertEquals(Optional.of(barrosEntry), fetcher.performSearch("\"Barros, Alistair\" AND \"Dumas, Marlon\" AND \"Arthur H.M. ter Hofstede\"").stream().findFirst()); } @Test @@ -137,7 +137,7 @@ public void performSearchByEmptyId() throws Exception { @Test public void performSearchByEmptyQuery() throws Exception { - assertEquals(Collections.emptyList(), fetcher.performComplexSearch("")); + assertEquals(Collections.emptyList(), fetcher.performSearch("")); } /** diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java index 63f205bfb4b..83414d8666d 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DBLPFetcherTest.java @@ -51,7 +51,7 @@ public void setUp() { @Test public void findSingleEntry() throws FetcherException { String query = "Process Engine Benchmarking with Betsy in the Context of {ISO/IEC} Quality Standards"; - List result = dblpFetcher.performComplexSearch(query); + List result = dblpFetcher.performSearch(query); assertEquals(Collections.singletonList(entry), result); } @@ -59,13 +59,13 @@ public void findSingleEntry() throws FetcherException { @Test public void findSingleEntryUsingComplexOperators() throws FetcherException { String query = "geiger harrer betsy$ softw.trends"; // -wirtz Negative operators do no longer work, see issue https://github.com/JabRef/jabref/issues/2890 - List result = dblpFetcher.performComplexSearch(query); + List result = dblpFetcher.performSearch(query); assertEquals(Collections.singletonList(entry), result); } @Test public void findNothing() throws Exception { - assertEquals(Collections.emptyList(), dblpFetcher.performComplexSearch("")); + assertEquals(Collections.emptyList(), dblpFetcher.performSearch("")); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java index fe5829110fe..2cad38a3f17 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java @@ -45,7 +45,7 @@ void searchByQueryFindsEntry() throws Exception { expected.setField(StandardField.YEAR, "2018"); expected.setField(StandardField.ABSTRACT, "The paper presents an approach to combine multiple existing information retrieval (IR) techniques to support change impact analysis, which seeks to identify the possible outcomes of a change or determine the necessary modifications for affecting a desired change. The approach integrates a bag-of-words based IR technique, where each class or method is abstracted as a set of words, and a neural network based IR technique to derive conceptual couplings from the source code of a software system. We report rigorous empirical assessments of the changes of three open source systems: jEdit, muCommander, and JabRef. The impact sets obtained are evaluated at the method level of granularity, and the results show that our integrated approach provides statistically significant improvements in accuracy across several cut points relative to the accuracies provided by the individual methods employed independently. Improvements in F-score values of up to 7.3%, 10.9%, and 17.3% are obtained over a baseline technique for jEdit, muCommander, and JabRef, respectively."); - List fetchedEntries = fetcher.performComplexSearch("JabRef impact"); + List fetchedEntries = fetcher.performSearch("JabRef impact"); assertEquals(Collections.singletonList(expected), fetchedEntries); } @@ -65,7 +65,7 @@ void testBibJSONConverter() { @Test public void searchByEmptyQuery() throws Exception { - assertEquals(Collections.emptyList(), fetcher.performComplexSearch("")); + assertEquals(Collections.emptyList(), fetcher.performSearch("")); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java index 1929de37d6e..87ff79ac608 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GoogleScholarTest.java @@ -69,7 +69,7 @@ void findSingleEntry() throws FetcherException { entry.setField(StandardField.YEAR, "2013"); entry.setField(StandardField.PAGES, "41--44"); - List foundEntries = finder.performComplexSearch("Detecting Interoperability and Correctness Issues in BPMN 2.0 Process Models"); + List foundEntries = finder.performSearch("Detecting Interoperability and Correctness Issues in BPMN 2.0 Process Models"); assertEquals(Collections.singletonList(entry), foundEntries); } @@ -77,7 +77,7 @@ void findSingleEntry() throws FetcherException { @Test @DisabledOnCIServer("CI server is blocked by Google") void findManyEntries() throws FetcherException { - List foundEntries = finder.performComplexSearch("random test string"); + List foundEntries = finder.performSearch("random test string"); assertEquals(20, foundEntries.size()); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java index 69f34980f86..329748dcd56 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java @@ -84,26 +84,26 @@ public static Stream provideInvalidInput() { @ParameterizedTest(name = "{0}") @MethodSource("provideExamplesForCorrectResultTest") public void grobidPerformSearchCorrectResultTest(String testName, BibEntry expectedBibEntry, String searchQuery) throws FetcherException { - List entries = grobidCitationFetcher.performComplexSearch(searchQuery); + List entries = grobidCitationFetcher.performSearch(searchQuery); assertEquals(List.of(expectedBibEntry), entries); } @Test public void grobidPerformSearchCorrectlySplitsStringTest() throws FetcherException { - List entries = grobidCitationFetcher.performComplexSearch(example1 + "\n\n" + example2 + "\r\n\r\n" + example3 + "\r\r" + example4); + List entries = grobidCitationFetcher.performSearch(example1 + "\n\n" + example2 + "\r\n\r\n" + example3 + "\r\r" + example4); assertEquals(List.of(example1AsBibEntry, example2AsBibEntry, example3AsBibEntry, example4AsBibEntry), entries); } @Test public void grobidPerformSearchWithEmptyStringsTest() throws FetcherException { - List entries = grobidCitationFetcher.performComplexSearch(" \n "); + List entries = grobidCitationFetcher.performSearch(" \n "); assertEquals(Collections.emptyList(), entries); } @ParameterizedTest @MethodSource("provideInvalidInput") public void grobidPerformSearchWithInvalidDataTest(String invalidInput) throws FetcherException { - List entries = grobidCitationFetcher.performComplexSearch(invalidInput); + List entries = grobidCitationFetcher.performSearch(invalidInput); assertEquals(Collections.emptyList(), entries); } @@ -114,7 +114,7 @@ public void performSearchThrowsExceptionInCaseOfConnectionIssues() throws IOExce grobidCitationFetcher = new GrobidCitationFetcher(importFormatPreferences, grobidServiceMock); assertThrows(FetcherException.class, () -> { - grobidCitationFetcher.performComplexSearch("any text"); + grobidCitationFetcher.performSearch("any text"); }, "performSearch should throw an FetcherException, when there are underlying IOException."); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java index ef37d5746b6..d1af17c5be0 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GvkFetcherTest.java @@ -93,26 +93,26 @@ public void complexSearchQueryURLCorrect() throws MalformedURLException, URISynt @Test public void testPerformSearchMatchingMultipleEntries() throws FetcherException { - List searchResult = fetcher.performComplexSearch("title:\"effective java\""); + List searchResult = fetcher.performSearch("title:\"effective java\""); assertTrue(searchResult.contains(bibEntryPPN591166003)); assertTrue(searchResult.contains(bibEntryPPN66391437X)); } @Test public void testPerformSearch591166003() throws FetcherException { - List searchResult = fetcher.performComplexSearch("ppn:591166003"); + List searchResult = fetcher.performSearch("ppn:591166003"); assertEquals(Collections.singletonList(bibEntryPPN591166003), searchResult); } @Test public void testPerformSearch66391437X() throws FetcherException { - List searchResult = fetcher.performComplexSearch("ppn:66391437X"); + List searchResult = fetcher.performSearch("ppn:66391437X"); assertEquals(Collections.singletonList(bibEntryPPN66391437X), searchResult); } @Test public void testPerformSearchEmpty() throws FetcherException { - List searchResult = fetcher.performComplexSearch(""); + List searchResult = fetcher.performSearch(""); assertEquals(Collections.emptyList(), searchResult); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java b/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java index b718688f157..a063519bb8d 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java @@ -98,7 +98,7 @@ void searchResultHasNoKeywordTerms() throws Exception { .withField(StandardField.TITLE, "Optimal operation of PV-DG-battery based microgrid with power quality conditioner") .withField(StandardField.VOLUME, "13"); - List fetchedEntries = fetcher.performComplexSearch("8636659"); // article number + List fetchedEntries = fetcher.performSearch("8636659"); // article number fetchedEntries.forEach(entry -> entry.clearField(StandardField.ABSTRACT)); // Remove abstract due to copyright); assertEquals(Collections.singletonList(expected), fetchedEntries); } @@ -122,7 +122,7 @@ void searchByQueryFindsEntry() throws Exception { .withField(StandardField.TITLE, "Overcoming Open Source Project Entry Barriers with a Portal for Newcomers") .withField(StandardField.FILE, ":https\\://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=7886910:PDF") .withField(StandardField.ABSTRACT, "Community-based Open Source Software (OSS) projects are usually self-organized and dynamic, receiving contributions from distributed volunteers. Newcomer are important to the survival, long-term success, and continuity of these communities. However, newcomers face many barriers when making their first contribution to an OSS project, leading in many cases to dropouts. Therefore, a major challenge for OSS projects is to provide ways to support newcomers during their first contribution. In this paper, we propose and evaluate FLOSScoach, a portal created to support newcomers to OSS projects. FLOSScoach was designed based on a conceptual model of barriers created in our previous work. To evaluate the portal, we conducted a study with 65 students, relying on qualitative data from diaries, self-efficacy questionnaires, and the Technology Acceptance Model. The results indicate that FLOSScoach played an important role in guiding newcomers and in lowering barriers related to the orientation and contribution process, whereas it was not effective in lowering technical barriers. We also found that FLOSScoach is useful, easy to use, and increased newcomers' confidence to contribute. Our results can help project maintainers on deciding the points that need more attention in order to help OSS project newcomers overcome entry barriers."); - List fetchedEntries = fetcher.performComplexSearch("Overcoming Open Source Project Entry Barriers with a Portal for Newcomers"); + List fetchedEntries = fetcher.performSearch("Overcoming Open Source Project Entry Barriers with a Portal for Newcomers"); assertEquals(Collections.singletonList(expected), fetchedEntries); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java index 90cf5af75f2..ff8c597705b 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/INSPIREFetcherTest.java @@ -41,7 +41,7 @@ void searchByQueryFindsEntry() throws Exception { .withField(StandardField.EPRINT, "1405.2249") .withField(StandardField.ARCHIVEPREFIX, "arXiv") .withField(StandardField.PRIMARYCLASS, "math-ph"); - List fetchedEntries = fetcher.performComplexSearch("Fr\\´echet group actions field"); + List fetchedEntries = fetcher.performSearch("Fr\\´echet group actions field"); assertEquals(Collections.singletonList(master), fetchedEntries); } @@ -59,7 +59,7 @@ public void searchByIdentifierFindsEntry() throws Exception { .withField(StandardField.EPRINT, "hep-ph/9802379") .withField(StandardField.ARCHIVEPREFIX, "arXiv") .withField(new UnknownField("reportnumber"), "BUDKER-INP-1998-7, TTP-98-10"); - List fetchedEntries = fetcher.performComplexSearch("hep-ph/9802379"); + List fetchedEntries = fetcher.performSearch("hep-ph/9802379"); assertEquals(Collections.singletonList(article), fetchedEntries); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java index 2ffa03e20e3..c8d51bd1fee 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java @@ -42,7 +42,7 @@ public class JstorFetcherTest implements SearchBasedFetcherCapabilityTest { @Test void searchByTitle() throws Exception { - List entries = fetcher.performComplexSearch("title: \"Test Anxiety Analysis of Chinese College Students in Computer-based Spoken English Test\""); + List entries = fetcher.performSearch("title: \"Test Anxiety Analysis of Chinese College Students in Computer-based Spoken English Test\""); assertEquals(Collections.singletonList(bibEntry), entries); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java index 51230a3da53..7c3cba64256 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MathSciNetTest.java @@ -73,7 +73,7 @@ void searchByIdInEntryFindsEntry() throws Exception { @Test @DisabledOnCIServer("CI server has no subscription to MathSciNet and thus gets 401 response") void searchByQueryFindsEntry() throws Exception { - List fetchedEntries = fetcher.performComplexSearch("Existence and uniqueness theorems Two-Dimensional Ericksen Leslie System"); + List fetchedEntries = fetcher.performSearch("Existence and uniqueness theorems Two-Dimensional Ericksen Leslie System"); assertFalse(fetchedEntries.isEmpty()); assertEquals(ratiuEntry, fetchedEntries.get(1)); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java index 91bc837a23d..843f1838917 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java @@ -171,7 +171,7 @@ public void testSearchByIDSari() throws Exception { @Test public void testMultipleEntries() throws Exception { - List entryList = fetcher.performComplexSearch("java"); + List entryList = fetcher.performSearch("java"); entryList.forEach(entry -> entry.clearField(StandardField.ABSTRACT)); // Remove abstract due to copyright); System.out.println(entryList); assertEquals(50, entryList.size()); @@ -184,12 +184,12 @@ public void testInvalidSearchTerm() throws Exception { @Test public void testEmptyEntryList() throws Exception { - List entryList = fetcher.performComplexSearch("java is fantastic and awesome "); + List entryList = fetcher.performSearch("java is fantastic and awesome "); assertEquals(Collections.emptyList(), entryList); } @Test public void testEmptyInput() throws Exception { - assertEquals(Collections.emptyList(), fetcher.performComplexSearch("")); + assertEquals(Collections.emptyList(), fetcher.performSearch("")); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java index 49633ad5d18..43902fe9fa2 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/PagedSearchFetcherTest.java @@ -19,8 +19,8 @@ public interface PagedSearchFetcherTest { @Test default void pageSearchReturnsUniqueResultsPerPage() throws Exception { String query = "Software"; - Page firstPage = getPagedFetcher().performComplexSearchPaged(query, 0); - Page secondPage = getPagedFetcher().performComplexSearchPaged(query, 1); + Page firstPage = getPagedFetcher().performSearchPaged(query, 0); + Page secondPage = getPagedFetcher().performSearchPaged(query, 1); for (BibEntry entry : firstPage.getContent()) { assertFalse(secondPage.getContent().contains(entry)); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/SearchBasedFetcherCapabilityTest.java b/src/test/java/org/jabref/logic/importer/fetcher/SearchBasedFetcherCapabilityTest.java index 02760e1b91e..73afa6d63c9 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/SearchBasedFetcherCapabilityTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/SearchBasedFetcherCapabilityTest.java @@ -34,7 +34,7 @@ default void supportsAuthorSearch() throws Exception { ComplexSearchQuery.ComplexSearchQueryBuilder builder = ComplexSearchQuery.builder(); getTestAuthors().forEach(builder::author); - List result = getFetcher().performComplexSearch(builder.build()); + List result = getFetcher().performSearch(builder.build()); new ImportCleanup(BibDatabaseMode.BIBTEX).doPostCleanup(result); assertFalse(result.isEmpty()); @@ -56,7 +56,7 @@ default void supportsYearSearch() throws Exception { .singleYear(getTestYear()) .build(); - List result = getFetcher().performComplexSearch(complexSearchQuery); + List result = getFetcher().performSearch(complexSearchQuery); new ImportCleanup(BibDatabaseMode.BIBTEX).doPostCleanup(result); List differentYearsInResult = result.stream() .map(bibEntry -> bibEntry.getField(StandardField.YEAR)) @@ -77,7 +77,7 @@ default void supportsYearRangeSearch() throws Exception { List yearsInYearRange = List.of("2018", "2019", "2020"); builder.fromYearAndToYear(2018, 2020); - List result = getFetcher().performComplexSearch(builder.build()); + List result = getFetcher().performSearch(builder.build()); new ImportCleanup(BibDatabaseMode.BIBTEX).doPostCleanup(result); List differentYearsInResult = result.stream() .map(bibEntry -> bibEntry.getField(StandardField.YEAR)) @@ -96,7 +96,7 @@ default void supportsYearRangeSearch() throws Exception { default void supportsJournalSearch() throws Exception { ComplexSearchQuery.ComplexSearchQueryBuilder builder = ComplexSearchQuery.builder(); builder.journal(getTestJournal()); - List result = getFetcher().performComplexSearch(builder.build()); + List result = getFetcher().performSearch(builder.build()); new ImportCleanup(BibDatabaseMode.BIBTEX).doPostCleanup(result); assertFalse(result.isEmpty()); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java index de802388374..74e595c777a 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java @@ -49,7 +49,7 @@ void searchByQueryFindsEntry() throws Exception { .withField(StandardField.FILE, ":http\\://link.springer.com/openurl/pdf?id=doi\\:10.1007/s10606-018-9335-z:PDF") .withField(StandardField.ABSTRACT, "An influx of newcomers is critical to the survival, long-term success, and continuity of many Open Source Software (OSS) community-based projects. However, newcomers face many barriers when making their first contribution, leading in many cases to dropouts. Due to the collaborative nature of community-based OSS projects, newcomers may be susceptible to social barriers, such as communication breakdowns and reception issues. In this article, we report a two-phase study aimed at better understanding social barriers faced by newcomers. In the first phase, we qualitatively analyzed the literature and data collected from practitioners to identify barriers that hinder newcomers’ first contribution. We designed a model composed of 58 barriers, including 13 social barriers. In the second phase, based on the barriers model, we developed FLOSScoach, a portal to support newcomers making their first contribution. We evaluated the portal in a diary-based study and found that the portal guided the newcomers and reduced the need for communication. Our results provide insights for communities that want to support newcomers and lay a foundation for building better onboarding tools. The contributions of this paper include identifying and gathering empirical evidence of social barriers faced by newcomers; understanding how social barriers can be reduced or avoided by using a portal that organizes proper information for newcomers (FLOSScoach); presenting guidelines for communities and newcomers on how to reduce or avoid social barriers; and identifying new streams of research."); - List fetchedEntries = fetcher.performComplexSearch("JabRef Social Barriers Steinmacher"); + List fetchedEntries = fetcher.performSearch("JabRef Social Barriers Steinmacher"); assertEquals(Collections.singletonList(expected), fetchedEntries); } @@ -78,7 +78,7 @@ void testSpringerJSONToBibtex() { @Test void searchByEmptyQueryFindsNothing() throws Exception { - assertEquals(Collections.emptyList(), fetcher.performComplexSearch("")); + assertEquals(Collections.emptyList(), fetcher.performSearch("")); } @Test @@ -109,8 +109,8 @@ public void supportsPhraseSearch() throws Exception { .withField(StandardField.FILE, ":http\\://link.springer.com/openurl/pdf?id=doi\\:10.1007/978-3-319-78105-1_75:PDF") .withField(StandardField.ABSTRACT, "The iSchool Inclusion Institute (i3) is a Research Experience for Undergraduates (REU) program in the US designed to address underrepresentation in the information sciences. i3 is a year-long, cohort-based program that prepares undergraduate students for graduate school in information science and is rooted in a research and leadership development curriculum. Using data from six years of i3 cohorts, we present in this paper a qualitative and quantitative evaluation of the program in terms of student learning, research production, and graduate school enrollment. We find that students who participate in i3 report significant learning gains in information-science- and graduate-school-related areas and that 52% of i3 participants enroll in graduate school, over 2 $$\\times $$ × the national average. Based on these and additional results, we distill recommendations for future implementations of similar programs to address underrepresentation in information science."); - List resultPhrase = fetcher.performComplexSearch("author:\"Redmiles David\""); - List result = fetcher.performComplexSearch("author:Redmiles David"); + List resultPhrase = fetcher.performSearch("author:\"Redmiles David\""); + List result = fetcher.performSearch("author:Redmiles David"); // Phrase search should be a subset of the normal search result. Assertions.assertTrue(result.containsAll(resultPhrase)); @@ -120,8 +120,8 @@ public void supportsPhraseSearch() throws Exception { @Test public void supportsBooleanANDSearch() throws Exception { - List resultJustByAuthor = fetcher.performComplexSearch("author:\"Redmiles, David\""); - List result = fetcher.performComplexSearch("author:\"Redmiles, David\" AND journal:\"Computer Supported Cooperative Work\""); + List resultJustByAuthor = fetcher.performSearch("author:\"Redmiles, David\""); + List result = fetcher.performSearch("author:\"Redmiles, David\" AND journal:\"Computer Supported Cooperative Work\""); Assertions.assertTrue(resultJustByAuthor.containsAll(result)); List allEntriesFromCSCW = result.stream() diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java index 1caed5a0973..ade6bffec3e 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ZbMATHTest.java @@ -50,7 +50,7 @@ void setUp() throws Exception { @Test @DisabledOnCIServer("CI server has no subscription to zbMath and thus gets 401 response") void searchByQueryFindsEntry() throws Exception { - List fetchedEntries = fetcher.performComplexSearch("an:0507.57010"); + List fetchedEntries = fetcher.performSearch("an:0507.57010"); assertEquals(Collections.singletonList(donaldsonEntry), fetchedEntries); } }