wxString MANFrame::CreateLinksPage(const std::vector<wxString> &files) { wxString ret= _("<html>\n" "<head>\n" "<meta content=\"text/html; charset=ISO-8859-1\"\n" "http-equiv=\"content-type\">\n" "<title></title>\n" "</head>\n" "<body>\n" "<h2>Multiple entries found</h2>\n" "<br>\n"); typedef std::multimap<wxString, wxString> ResultsMap; ResultsMap sortedResults; wxRegEx reMatchLocale(wxT("^(.+)/(man.+)$")); for (std::vector<wxString>::const_iterator i = files.begin(); i != files.end(); ++i) { wxString filename = *i; wxString linkname, ext, path; wxFileName::SplitPath(filename, &path, &linkname, &ext); if (ext != _T("bz2") && ext != _T("gz")) { linkname += _T(".") + ext; } // Strip the common directory from the path, so we can detect the language of the man page. for (std::vector<wxString>::const_iterator dir = m_dirsVect.begin(); dir != m_dirsVect.end(); ++dir) { if (path.StartsWith(*dir)) { path.Remove(0, dir->length()); if (!path.empty() && path[0] == wxFileName::GetPathSeparator()) path.Remove(0, 1); break; } } // Detect the language of the man page. if (reMatchLocale.Matches(path)) { const wxString &locale = reMatchLocale.GetMatch(path, 1); if (!locale.empty()) linkname += wxT(" (") + locale + wxT(")"); } const wxString &aTag = _T("<a href=\"fman:") + filename + _T("\">") + linkname + _T("</a><br>"); sortedResults.insert(ResultsMap::value_type(linkname, aTag)); } for (ResultsMap::const_iterator it = sortedResults.begin(); it != sortedResults.end(); ++it) ret += it->second; ret += _T("</body>\n" "</html>"); return ret; }
bool TextSearchIndex::Search(const std::string& query, bool searchPOIs, bool searchLocations, bool searchRegions, bool searchOther, ResultsMap& results) const { results.clear(); if(query.empty()) { return true; } std::vector<bool> searchGroups; searchGroups.push_back(searchPOIs); searchGroups.push_back(searchLocations); searchGroups.push_back(searchRegions); searchGroups.push_back(searchOther); for(size_t i=0; i < tries.size(); i++) { if(searchGroups[i] && tries[i].isAvail) { marisa::Agent agent; try { agent.set_query(query.c_str(), query.length()); while(tries[i].trie->predictive_search(agent)) { std::string result(agent.key().ptr(), agent.key().length()); std::string text; ObjectFileRef ref; splitSearchResult(result,text,ref); ResultsMap::iterator it=results.find(text); if(it==results.end()) { // If the text has not been added to the // search results yet, insert a new entry std::pair<std::string,std::vector<ObjectFileRef> > entry; entry.first = text; entry.second.push_back(ref); results.insert(entry); } else { // Else add the offset to the existing entry it->second.push_back(ref); } } } catch(const marisa::Exception &ex) { std::cerr << "Error searching for text: "; std::cerr << ex.what() << std::endl; return false; } } } return true; }