-
-
-
-
-)HTML";
-
- std::string html = removeEOLWhitespaceMarkers(SEARCHRESULTS_HTML_TEMPLATE);
- html = replace(html, "%PATTERN%", pattern);
+ std::string html = removeEOLWhitespaceMarkers(SEARCHRESULTS_XML_TEMPLATE);
html = replace(html, "%HEADER%", header);
html = replace(html, "%RESULTS%", results);
- html = replace(html, "%FOOTER%", footer);
return html;
}
#define SEARCH_RESULT(LINK, TITLE, SNIPPET, BOOK_TITLE, WORDCOUNT) \
-"\n \n"\
-" " TITLE "\n"\
-" \n"\
-" " SNIPPET "\n"\
-"
from " BOOK_TITLE "
\n"\
-"
" WORDCOUNT " words
\n"
+" " TITLE "\n"\
+" " LINK "\n"\
+" " SNIPPET "\n"\
+" \n"\
+" " BOOK_TITLE "\n"\
+" \n"\
+" " WORDCOUNT ""
+
const std::vector LARGE_SEARCH_RESULTS = {
SEARCH_RESULT(
@@ -187,7 +77,7 @@ const std::vector LARGE_SEARCH_RESULTS = {
),
SEARCH_RESULT(
- /*link*/ "/ROOT/zimfile/A/Catchin'_Some_Rays:_The_Music_of_Ray_Charles",
+ /*link*/ "/ROOT/zimfile/A/Catchin'_Some_Rays:_The_Music_of_Ray_Charles",
/*title*/ "Catchin' Some Rays: The Music of Ray Charles",
/*snippet*/ R"SNIPPET(...jazz singer Roseanna Vitro, released in August 1997 on the Telarc Jazz label. Catchin' Some Rays: The Music of Ray Charles Studio album by Roseanna Vitro Released August 1997 Recorded March 26, 1997 at Sound on Sound, NYC April 4,1997 at Quad Recording Studios, NYC Genre Vocal jazz Length 61:00 Label Telarc Jazz CD-83419 Producer Paul Wickliffe Roseanna Vitro chronology Passion Dance (1996) Catchin' Some Rays: The Music of Ray Charles (1997) The Time of My Life: Roseanna Vitro Sings the Songs of......)SNIPPET",
/*bookTitle*/ "Ray Charles",
@@ -195,7 +85,7 @@ const std::vector LARGE_SEARCH_RESULTS = {
),
SEARCH_RESULT(
- /*link*/ "/ROOT/zimfile/A/That's_What_I_Say:_John_Scofield_Plays_the_Music_of_Ray_Charles",
+ /*link*/ "/ROOT/zimfile/A/That's_What_I_Say:_John_Scofield_Plays_the_Music_of_Ray_Charles",
/*title*/ "That's What I Say: John Scofield Plays the Music of Ray Charles",
/*snippet*/ R"SNIPPET(That's What I Say: John Scofield Plays the Music of Ray Charles Studio album by John Scofield Released June 7, 2005 (2005-06-07) Recorded December 2004 Studio Avatar Studios, New York City Genre Jazz Length 65:21 Label Verve Producer Steve Jordan John Scofield chronology EnRoute: John Scofield Trio LIVE (2004) That's What I Say: John Scofield Plays the Music of Ray Charles (2005) Out Louder (2006) Professional ratings Review scores Source Rating Allmusic All About Jazz All About Jazz...)SNIPPET",
/*bookTitle*/ "Ray Charles",
@@ -435,7 +325,7 @@ const std::vector LARGE_SEARCH_RESULTS = {
),
SEARCH_RESULT(
- /*link*/ "/ROOT/zimfile/A/Don't_Let_the_Sun_Catch_You_Cryin'",
+ /*link*/ "/ROOT/zimfile/A/Don't_Let_the_Sun_Catch_You_Cryin'",
/*title*/ "Don't Let the Sun Catch You Cryin'",
/*snippet*/ R"SNIPPET(...R&B Sides" and No. 95 on the Billboard Hot 100. It was also recorded by Jackie DeShannon on her 1965 album This is Jackie De Shannon, Paul McCartney on his 1990 live album Tripping the Live Fantastic, Jex Saarelaht and Kate Ceberano on their album Open the Door - Live at Mietta's (1992) and jazz singer Roseanna Vitro on her 1997 album Catchin’ Some Rays: The Music of Ray Charles. Karin Krog and Steve Kuhn include it on their 2005 album, Together Again. Steve Alaimo released a version in 1963...)SNIPPET",
/*bookTitle*/ "Ray Charles",
@@ -443,7 +333,7 @@ const std::vector LARGE_SEARCH_RESULTS = {
),
SEARCH_RESULT(
- /*link*/ "/ROOT/zimfile/A/I_Don't_Need_No_Doctor",
+ /*link*/ "/ROOT/zimfile/A/I_Don't_Need_No_Doctor",
/*title*/ "I Don't Need No Doctor",
/*snippet*/ R"SNIPPET(...jazz guitar player John Scofield recorded a version for his album That's What I Say: John Scofield Plays the Music of Ray Charles in 2005, featuring the blues guitarist John Mayer on additional guitar and vocals. Mayer covered the song again with his band during his tour in summer 2007. A recorded live version from a Los Angeles show during that tour is available on Mayer's CD/DVD release Where the Light Is. A Ray Charles tribute album also provided the impetus for jazz singer Roseanna Vitro's......)SNIPPET",
/*bookTitle*/ "Ray Charles",
@@ -531,7 +421,7 @@ const std::vector LARGE_SEARCH_RESULTS = {
std::string maskSnippetsInSearchResults(std::string s)
{
- return replace(s, ".+", "SNIPPET TEXT WAS MASKED");
+ return replace(s, "(?!Search result for).+", "SNIPPET TEXT WAS MASKED");
}
bool isValidSnippet(const std::string& s)
@@ -587,26 +477,18 @@ TEST_F(TaskbarlessServerTest, searchResults)
{
struct TestData
{
- struct PaginationEntry
- {
- std::string label;
- size_t start;
- bool selected;
- };
-
std::string query;
int start;
size_t resultsPerPage;
size_t totalResultCount;
size_t firstResultIndex;
std::vector results;
- std::vector pagination;
static std::string makeUrl(const std::string& query, int start, size_t resultsPerPage)
{
- std::string url = "/ROOT/search?" + query;
+ std::string url = "/ROOT/search?" + query + "&format=xml";
- if ( start >= 0 ) {
+ if (start >= 0) {
url += "&start=" + to_string(start);
}
@@ -632,23 +514,23 @@ TEST_F(TaskbarlessServerTest, searchResults)
std::string expectedHeader() const
{
- if ( totalResultCount == 0 ) {
- return "\n No results were found for \"" + getPattern() + "\"";
- }
+ std::string header = R"(Search: PATTERN
+ URL
+ Search result for PATTERN
+ RESULTCOUNT
+ FIRSTRESULT
+ ITEMCOUNT
+
+ )";
- std::string header = R"( Results
-
- FIRSTRESULT-LASTRESULT
- of
- RESULTCOUNT
- for
- "PATTERN"
-
- )";
-
- const size_t lastResultIndex = std::min(totalResultCount, firstResultIndex + results.size() - 1);
+ auto realResultsPerPage = resultsPerPage?resultsPerPage:25;
+ header = replace(header, "URL", replace(makeUrl(query, firstResultIndex, realResultsPerPage), "&", "&"));
header = replace(header, "FIRSTRESULT", to_string(firstResultIndex));
- header = replace(header, "LASTRESULT", to_string(lastResultIndex));
+ header = replace(header, "ITEMCOUNT", to_string(realResultsPerPage));
header = replace(header, "RESULTCOUNT", to_string(totalResultCount));
header = replace(header, "PATTERN", getPattern());
return header;
@@ -657,49 +539,23 @@ TEST_F(TaskbarlessServerTest, searchResults)
std::string expectedResultsString() const
{
if ( results.empty() ) {
- return "\n ";
+ return "\n ";
}
std::string s;
for ( const auto& r : results ) {
- s += "\n
";
+ s += "\n \n";
s += maskSnippetsInSearchResults(r);
- s += "