int main() { //Integers const std::vector<int> a { 0,1,2, 3, 4, 5 }; //Squares const std::vector<int> b { 0,1,4,16,25,36 }; //Zero, one and four are common in both arrays const std::vector<int> expected { 0,1,4 }; //array_intersect will return the following form const std::vector<int> result { array_intersect(a,b) }; assert(expected == result); }
string search_search2 (void * webserver_request) { Webserver_Request * request = (Webserver_Request *) webserver_request; Database_Volatile database_volatile = Database_Volatile (); string siteUrl = config_logic_site_url (); string bible = request->database_config_user()->getBible (); if (request->query.count ("bible")) bible = request->query ["bible"]; bool hit_is_set = request->query.count ("h"); bool query_is_set = request->query.count ("q"); int identifier = convert_to_int (request->query ["i"]); string query = request->query ["q"]; string hit = request->query ["h"]; // Get one search hit. if (hit_is_set) { // Retrieve the search parameters from the volatile database. string query = database_volatile.getValue (identifier, "query"); //bool casesensitive = convert_to_bool (database_volatile.getValue (identifier, "casesensitive")); bool plaintext = convert_to_bool (database_volatile.getValue (identifier, "plaintext")); // Get the Bible and passage for this identifier. Passage details = Passage::from_text (hit); string bible = details.bible; int book = details.book; int chapter = details.chapter; string verse = details.verse; // Get the plain text or USFM. string text; if (plaintext) { text = search_logic_get_bible_verse_text (bible, book, chapter, convert_to_int (verse)); } else { text = search_logic_get_bible_verse_usfm (bible, book, chapter, convert_to_int (verse)); } // Format it. string link = filter_passage_link_for_opening_editor_at (book, chapter, verse); text = filter_string_markup_words ({query}, text); string output = "<div>" + link + " " + text + "</div>"; // Output to browser. return output; } // Perform the initial search. if (query_is_set) { // Get extra search parameters and store them all in the volatile database. bool casesensitive = (request->query ["c"] == "true"); bool plaintext = (request->query ["p"] == "true"); bool currentbook = (request->query ["b"] == "true"); string sharing = request->query ["s"]; database_volatile.setValue (identifier, "query", query); database_volatile.setValue (identifier, "casesensitive", convert_to_string (casesensitive)); database_volatile.setValue (identifier, "plaintext", convert_to_string (plaintext)); // Deal with case sensitivity. // Deal with whether to search the plain text, or the raw USFM. // Fetch the initial set of hits. vector <Passage> passages; if (plaintext) { if (casesensitive) { passages = search_logic_search_bible_text_case_sensitive (bible, query); } else { passages = search_logic_search_bible_text (bible, query); } } else { if (casesensitive) { passages = search_logic_search_bible_usfm_case_sensitive (bible, query); } else { passages = search_logic_search_bible_usfm (bible, query); } } // Deal with possible searching in the current book only. if (currentbook) { int book = Ipc_Focus::getBook (request); vector <Passage> bookpassages; for (auto & passage : passages) { if (book == passage.book) { bookpassages.push_back (passage); } } passages = bookpassages; } // Deal with how to share the results. vector <string> hits; for (auto & passage : passages) { hits.push_back (passage.to_text ()); } if (sharing != "load") { vector <string> loaded_hits = filter_string_explode (database_volatile.getValue (identifier, "hits"), '\n'); if (sharing == "add") { hits.insert (hits.end(), loaded_hits.begin(), loaded_hits.end()); } if (sharing == "remove") { hits = filter_string_array_diff (loaded_hits, hits); } if (sharing == "intersect") { hits = array_intersect (loaded_hits, hits); } hits = array_unique (hits); } // Generate one string from the hits. string output = filter_string_implode (hits, "\n"); // Store search hits in the volatile database. database_volatile.setValue (identifier, "hits", output); // Output results. return output; } // Build the advanced search page. string page; Assets_Header header = Assets_Header (translate("Search"), request); header.setNavigator (); header.addBreadCrumb (menu_logic_search_menu (), menu_logic_search_text ()); page = header.run (); Assets_View view; view.set_variable ("bible", bible); string script = "var searchBible = \"" + bible + "\";"; view.set_variable ("script", script); page += view.render ("search", "search2"); page += Assets_Page::footer (); return page; }