7 #include <Poco/JSON/Object.h>
8 #include <Poco/JSON/Array.h>
9 #include <Poco/JSON/JSON.h>
10 #include <Poco/JSON/Stringifier.h>
11 #include <Poco/JSON/Parser.h>
12 #include <Poco/JSON/JSONException.h>
13 #include <Poco/Dynamic/Var.h>
15 #include <Poco/String.h>
36 :
inherited(), fObj(fObj_), resultData(
""), message(fObj.getCustomMessage())
43 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
46 if (stat(path.c_str(), &st) != 0)
48 if (mkdir(path.c_str(), mode) != 0)
53 else if (!S_ISDIR(st.st_mode))
69 struct dirent* ent =
nullptr;
70 DIR* dir = opendir (path.c_str());
75 while ((ent = readdir (dir)) !=
nullptr)
77 fileName = ent->d_name;
78 if (fileName !=
"." && fileName !=
"..")
80 fileName = path+
"/"+ent->d_name;
82 if (
remove(fileName.c_str())==-1)
86 if (closedir(dir)==-1)
104 dir = opendir (path.c_str());
107 if (closedir(dir)==-1)
123 return (access(file.c_str(), F_OK)==0);
139 std::string
cmd(
"cp");
140 std::vector<std::string>
args = {srcFile, dstFile};
142 std::stringstream outMsg;
144 if (!procExec.
exec(outMsg, outMsg))
145 throw Poco::Exception(
"Copy '"+srcFile+
"' to '"+dstFile+
"' fail",
ERROR_COPY_FILE);
152 catch(Poco::Exception& e)
168 std::string
cmd(
"mv");
169 std::vector<std::string>
args = {srcFile, dstFile};
171 std::stringstream outMsg;
173 if (!procExec.
exec(outMsg, outMsg))
174 throw Poco::Exception(
"Move '"+srcFile+
"' to '"+dstFile+
"' fail",
ERROR_MOVE_FILE);
181 catch(Poco::Exception& e)
192 if (
remove(file.c_str())==0)
208 DIR* dir = opendir(srcPath.c_str());
212 std::string oldName, newName;
213 while((d = readdir(dir)))
216 if (oldName.find(indexFileName) != std::string::npos)
218 oldName = srcPath +
"/" + d->d_name;
219 newName = dstPath +
"/" + d->d_name;
227 if (closedir(dir)==-1)
229 errorMsg.append(
" ").append(strerror(errno));
242 DIR* dir = opendir(srcPath.c_str());
246 std::string oldName, newName;
247 while((d = readdir(dir)))
250 if (oldName.find(indexFileName) != std::string::npos)
252 oldName = srcPath +
"/" + d->d_name;
253 newName = dstPath +
"/" + d->d_name;
261 if (closedir(dir)==-1)
263 errorMsg.append(
" ").append(strerror(errno));
276 DIR* dir = opendir(path.c_str());
281 std::vector<std::string> files;
282 while((d = readdir(dir)))
284 fileName = d->d_name;
285 if (fileName.compare(0, indexFileName.length(),
indexFileName)==0)
287 if (!(d->d_name == std::string(
".") || d->d_name == std::string(
"..")))
289 fileName = path +
"/" + d->d_name;
290 files.push_back(fileName);
295 if (closedir(dir)==-1)
297 errorMsg.append(
" ").append(strerror(errno));
301 for (
size_t i=0;i<files.size();++i)
304 if (
remove(files[i].c_str())!=0)
325 std::string findExtension =
"."+ext;
326 dir = opendir (path.c_str());
329 struct dirent* ent =
nullptr;
330 while ((ent = readdir (dir)) !=
nullptr)
332 std::string sourceFileName(ent->d_name);
333 size_t found = sourceFileName.find(findExtension);
334 if (found !=std::string::npos)
336 sourceFileName = sourceFileName.substr(0, found);
337 vFiles.push_back(sourceFileName);
340 if (closedir(dir)==-1)
362 struct dirent* ent =
nullptr;
364 dir = opendir (path.c_str());
367 std::set<std::string> sIndexes;
369 while ((ent = readdir (dir)) !=
nullptr)
371 if (!(ent->d_name == std::string(
".") || ent->d_name == std::string(
"..")))
373 fileName = ent->d_name;
374 size_t found = fileName.find_last_of(
'.');
375 if (found!=std::string::npos)
377 sIndexes.insert(fileName.substr(0, found));
381 if (closedir(dir)==-1)
385 vIndexes.assign(sIndexes.begin(), sIndexes.end());
410 std::set<unsigned int> ports;
412 struct dirent* ent =
nullptr;
418 Poco::AutoPtr<SphinxConfigCreator> pConf =
nullptr;
419 while ((ent = readdir (dir)) !=
nullptr)
421 std::string
name = ent->d_name;
422 if (!(name==
"."||name==
".."))
437 catch(std::exception& exc)
447 if (closedir(dir)==-1)
452 std::set<unsigned int>::iterator iter = ports.find(i);
453 if (iter==ports.end())
462 catch(Poco::Exception& e)
486 std::vector<std::string> keys;
489 for (
size_t i=0;i<keys.size();++i)
495 pConf->setString(name, value);
499 std::string value = path+
"/"+trunkName;
500 pConf->setString(name, value);
513 pConf->save(propFile);
514 pConf->setPropertyFileConfiguration(propFile);
516 std::ofstream ofs(sphinxConfigFile.c_str(), std::fstream::trunc);
522 pConf->save(propFile);
526 catch(Poco::Exception& e)
563 Poco::SharedPtr<SphinxAdminCommand> pCmd;
565 if (commandString ==
"INDEX_CREATE")
567 else if (commandString ==
"INDEX_CHECK")
569 else if (commandString ==
"INDEX_STORE_DATA_FILE")
571 else if (commandString ==
"INDEX_STORE_SCHEMA_FILE")
573 else if (commandString ==
"INDEX_REBUILD")
577 else if (commandString ==
"INDEX_START")
579 else if (commandString ==
"INDEX_STOP")
581 else if (commandString ==
"INDEX_MERGE")
583 else if (commandString ==
"INDEX_MERGE_TRUNK")
585 else if (commandString ==
"INDEX_DELETE_DATA_FILE")
587 else if (commandString ==
"INDEX_DELETE_SCHEMA_FILE")
589 else if (commandString ==
"INDEX_APPEND_DATA_FILE")
591 else if (commandString ==
"INDEX_DELETE_DOC")
593 else if (commandString ==
"INDEX_DELETE_DOC_NUMBER")
595 else if (commandString ==
"INDEX_PACK_DOC_DATA")
597 else if (commandString ==
"INDEX_REMOVE")
599 else if (commandString ==
"INDEX_COPY")
601 else if (commandString ==
"INDEX_RENAME")
603 else if (commandString ==
"INDEX_SET_CONFIG_VAR")
605 else if (commandString ==
"INDEX_GET_CONFIG_VAR")
607 else if (commandString ==
"INDEX_CHECK_SCHEMA")
609 else if (commandString ==
"INDEX_STATUS_SEARCHD")
611 else if (commandString ==
"INDEX_STATUS")
613 else if (commandString ==
"INDEX_MAX_DOC_ID")
615 else if (commandString ==
"INDEX_DATA_LIST")
617 else if (commandString ==
"INDEX_BRANCHES_LIST")
619 else if (commandString ==
"INDEX_BRANCHES_INFO")
621 else if (commandString ==
"INDEX_BRANCHES_STATUS")
623 else if (commandString ==
"INDEX_CONNECT")
625 else if (commandString ==
"INDEX_DISCONNECT")
643 Poco::JSON::Object::Ptr obj =
new Poco::JSON::Object();
646 std::stringstream ostr;
647 Poco::JSON::Stringifier::stringify(obj, ostr);
652 catch(std::exception& e)
667 Poco::JSON::Parser parser;
668 Poco::Dynamic::Var res = parser.parse(json);
669 Poco::JSON::Object::Ptr obj = res.extract<Poco::JSON::Object::Ptr>();
677 catch(Poco::JSON::JSONException& e)
730 std::vector<std::string> keys;
733 for (
size_t i=0;i<keys.size();++i)
738 std::string value = pConf->getString(name);
739 size_t pos = value.find_last_of(
' ');
740 if (pos!=std::string::npos)
741 value = value.substr(pos+1);
743 std::stringstream str;
744 str <<
"cat " << dataDir <<
'/' << value;
745 pConf->setString(name, str.str());
751 std::string value = pConf->getString(name);
753 std::stringstream str;
754 str << indexDir <<
'/' << value;
755 pConf->setString(name, str.str());
788 pConf->save(dstFile);
789 pConf->setPropertyFileConfiguration(dstFile);
792 std::ofstream ofs(sphinxConfig.c_str(), std::fstream::trunc);
798 pConf->save(dstFile);
799 pConf->setPropertyFileConfiguration(dstFile);
804 catch(Poco::Exception& e)
853 catch(Poco::Exception& e)
876 Poco::JSON::Object::Ptr obj =
new Poco::JSON::Object();
881 std::stringstream ostr;
882 Poco::JSON::Stringifier::stringify(obj, ostr);
887 catch(std::exception& e)
904 Poco::JSON::Parser parser;
905 Poco::Dynamic::Var res = parser.parse(json);
906 Poco::JSON::Object::Ptr obj = res.extract<Poco::JSON::Object::Ptr>();
922 catch(Poco::JSON::JSONException& e)
946 if (str.str().empty())
963 std::set<std::string> delList;
964 std::string outString = xmlCleaner.
process(str.str(), delList);
968 path.append(
"/").append(
branchName).append(
".dat");
970 std::ofstream ofs(path.c_str(), std::fstream::trunc);
978 catch(Poco::Exception& e)
983 catch(std::exception& e)
1004 Poco::JSON::Object::Ptr obj =
new Poco::JSON::Object();
1008 std::stringstream ostr;
1009 Poco::JSON::Stringifier::stringify(obj, ostr);
1014 catch(std::exception& e)
1030 Poco::JSON::Parser parser;
1031 Poco::Dynamic::Var res = parser.parse(json);
1032 Poco::JSON::Object::Ptr obj = res.extract<Poco::JSON::Object::Ptr>();
1044 catch(Poco::JSON::JSONException& e)
1064 if (str.str().empty())
1070 std::vector<std::pair<std::string, int> > schemaVec;
1076 std::ofstream ofs(path.c_str(), std::fstream::trunc);
1084 catch(Poco::Exception& e)
1104 Poco::JSON::Object::Ptr obj =
new Poco::JSON::Object();
1107 Poco::JSON::Array::Ptr vecBranches =
new Poco::JSON::Array();
1110 for (
size_t i=0;i<
branches.size();++i)
1113 std::stringstream ostr;
1114 Poco::JSON::Stringifier::stringify(obj, ostr);
1119 catch(std::exception& e)
1135 Poco::JSON::Parser parser;
1136 Poco::Dynamic::Var res = parser.parse(json);
1137 Poco::JSON::Object::Ptr obj = res.extract<Poco::JSON::Object::Ptr>();
1144 if (!vecBranches.isNull())
1146 for (
size_t k = 0;k<vecBranches->size();++k)
1148 Poco::Dynamic::Var tmp = vecBranches->get(k);
1151 std::string
branchName = tmp.convert<std::string>();
1168 catch(Poco::JSON::JSONException& e)
1178 bool result =
false;
1181 std::ifstream ifsSchema(schemaFile.c_str());
1182 if (!ifsSchema.is_open())
1186 std::ifstream ifsDoc(dataFileName.c_str());
1187 if (!ifsDoc.is_open())
1196 std::fstream outputSource(outputFileName.c_str(), std::fstream::out | std::fstream::trunc);
1199 outputSource << dataSource <<
flush;
1202 catch(Poco::Exception& e)
1207 outputSource.close();
1211 catch(Poco::Exception& e)
1225 bool result =
false;
1237 std::vector<std::string> keys;
1241 for (
size_t i=0;i<keys.size();++i)
1246 std::stringstream str;
1247 str <<
"cat " << sourceFile;
1248 pConf->setString(name, str.str());
1253 std::stringstream str;
1255 pConf->setString(name, str.str());
1256 sectionName = keys[i];
1260 pConf->save(propertyFile);
1261 pConf->setPropertyFileConfiguration(propertyFile);
1262 pConf->renameSphinxConfigSection(sectionName,
"index "+branchName);
1264 std::ofstream ofs(configFile.c_str(), std::fstream::trunc);
1269 pConf->setPropertyFileConfiguration(propertyFile);
1270 pConf->cloneSphinxConfigSection(sectionName,
"index "+branchName);
1271 pConf->remove(sectionName);
1274 pConf->save(propertyFile);
1276 std::stringstream outMsg, errMsg;
1277 const std::string
cmd(
"indexer --config " +configFile+
" --all");
1281 if (!procExec.
exec(outMsg, errMsg))
1285 throw Poco::Exception(outMsg.str());
1287 fObj.
log(LoggerStream::Priority::PRIO_INFORMATION) << outMsg.str() <<
flush;
1290 catch(Poco::Exception& e)
1317 if (!
isExistDir(path+
"/"+sphinx_admin_command_const::indexDir))
1320 if (!
isExistDir(path+
"/"+sphinx_admin_command_const::dataDir))
1324 std::vector<std::string> vFiles;
1327 unsigned int madeFailCount = 0;
1328 if (vFiles.size()==0)
1337 for (
size_t i=0;i<vFiles.size();++i)
1339 if (!
makeSource(schemaFileName, vFiles[i], dataDir, path))
1350 for (
size_t k=0;k<
branches.size();++k)
1351 for (
size_t i=0;i<vFiles.size();++i)
1354 if (!
makeSource(schemaFileName, vFiles[i], dataDir, path))
1364 if (madeFailCount==0)
1370 catch(Poco::Exception& e)
1462 catch(Poco::Exception& e)
1500 catch(Poco::Exception& e)
1516 bool result =
false;
1528 std::vector<std::string> keys;
1533 std::string trunkSectionName, branchSource;
1534 for (
size_t i=0;i<keys.size();++i)
1537 if (found!=std::string::npos)
1539 branchSource = keys[i];
1542 std::stringstream str;
1543 str <<
"cat " << sourceFile;
1544 pConf->setString(name, str.str());
1548 trunkSectionName = keys[i];
1551 if (trunkSectionName.empty())
1555 pConf->cloneSphinxConfigSection(trunkSectionName, branchSectionName);
1557 std::string branchSourceName = branchSource;
1559 pConf->cloneSphinxConfigSection(branchSourceName, trunkSourceName);
1562 std::string value = trunkSourceName;
1563 pConf->setString(name, value);
1566 value =
"echo \"\"";
1567 pConf->setString(name, value);
1571 pConf->setString(name, value);
1575 pConf->setString(name, value);
1588 pConf->save(propertyFile);
1589 pConf->setPropertyFileConfiguration(propertyFile);
1591 std::ofstream ofs(configFile.c_str(), std::fstream::trunc);
1595 std::stringstream outMsg;
1596 const std::string
cmd(
"indexer");
1597 std::vector<std::string>
args = {
"--merge", trunkName,
branchName,
"--config", configFile};
1599 bool ret = procExec.
exec(outMsg, outMsg);
1608 throw Poco::Exception(outMsg.str());
1612 catch(Poco::Exception& e)
1618 catch(std::exception& e)
1629 std::vector<std::string>& vIndexes,
unsigned long long& maxDocId)
throw (Poco::Exception)
1631 if (vIndexes.empty())
1635 for (
size_t i=0;i<vIndexes.size();++i)
1637 if (vIndexes[i]==trunkName)
1652 Poco::AutoPtr<SphinxConfigCreator> pConfBranch =
new SphinxConfigCreator(getPropertyFileName(configPath, vIndexes.front()));
1658 std::vector<std::string> keys;
1661 for (
size_t i=0;i<keys.size();++i)
1666 std::stringstream str;
1669 pConf->setString(name, str.str());
1674 std::stringstream str;
1676 pConf->setString(name, str.str());
1682 value = fObj.getRunDir()+
"/"+
1690 pConf->save(propertyFile);
1691 pConf->setPropertyFileConfiguration(propertyFile);
1693 std::ofstream ofs(configFile.c_str(), std::fstream::trunc);
1697 std::stringstream outMsg;
1698 const std::string
cmd(
"indexer");
1699 std::vector<std::string>
args = {
"--quiet", trunkName,
"--config", configFile};
1701 bool ret = procExec.
exec(outMsg, outMsg);
1703 if (!(removeFile(configFile) && removeFile(propertyFile)))
1709 if (isExistError(outMsg.str()))
1710 throw Poco::Exception(outMsg.str());
1712 vIndexes.erase(vIndexes.begin());
1714 catch(Poco::Exception& e)
1746 if (!fObject.isLoadedConfig())
1755 std::vector<std::string> vIndexes;
1758 if (vIndexes.empty())
1762 unsigned long long maxDocId = 0;
1763 unsigned long long branchMaxDocId = 0;
1765 const std::string trunkFileName = *(vIndexes.begin());
1771 unsigned int madeFailCount = 0;
1774 for (
size_t i=0;i<vIndexes.size();++i)
1776 if (!
makeMerge(vIndexes[i], path, fObject.getIndexFileName(), branchMaxDocId))
1786 if (maxDocId < branchMaxDocId)
1787 maxDocId = branchMaxDocId;
1793 for (
size_t k=0;k<
branches.size();++k)
1794 for (
size_t i=0;i<vIndexes.size();++i)
1797 if (!
makeMerge(vIndexes[i], path, fObject.getIndexFileName(), branchMaxDocId))
1807 if (maxDocId < branchMaxDocId)
1808 maxDocId = branchMaxDocId;
1814 bool isActive = fObject.isActiveSearchd();
1815 fObject.stopSearchd();
1830 if (!fObject.startSearchd())
1833 if (madeFailCount==0)
1839 catch(Poco::Exception& e)
1845 catch(std::exception& e)
1883 if (!fObject.isLoadedConfig())
1888 std::vector<std::string> vIndexes;
1892 if (vIndexes.empty())
1895 const std::string trunkFileName = *(vIndexes.begin());
1901 unsigned long long maxDocId = 0;
1902 unsigned long long branchMaxDocId = 0;
1904 unsigned int madeFailCount = 0;
1905 for (
size_t k=0;k<
branches.size();++k)
1906 for (
size_t i=0;i<vIndexes.size();++i)
1909 if (!
makeMerge(vIndexes[i], path, fObject.getIndexFileName(), branchMaxDocId))
1919 if (maxDocId < branchMaxDocId)
1920 maxDocId = branchMaxDocId;
1925 bool isActive = fObject.isActiveSearchd();
1926 fObject.stopSearchd();
1938 if (!fObject.startSearchd())
1941 if (madeFailCount==0)
1944 catch(Poco::Exception& e)
1950 catch(std::exception& e)
1965 bool IndexDeleteDataFile::removeFilesList(
const std::string& path, std::vector<std::string>&
branches, std::vector<std::string>& files,
const std::string& ext)
throw (Poco::Exception)
1967 bool result =
false;
1968 unsigned int madeFailCount = 0;
1971 for (
size_t i=0;i<files.size();++i)
1973 std::string
fileName = path+
"/"+files[i]+
"."+ext;
1974 if (!removeFile(fileName))
1976 if (!resultData.empty())
1977 resultData.append(
",");
1978 resultData.append(fileName);
1985 for (
size_t k=0;k<
branches.size();++k)
1986 for (
size_t i=0;i<files.size();++i)
1989 std::string fileName = path+
"/"+files[i]+
"."+ext;
1990 if (!removeFile(fileName))
1992 if (!resultData.empty())
1993 resultData.append(
",");
1994 resultData.append(fileName);
1999 if (madeFailCount==0)
2005 bool IndexDeleteDataFile::removeIndexFiles(
const std::string& path, std::vector<std::string>&
branches, std::vector<std::string>& files)
throw (Poco::Exception)
2007 bool result =
false;
2008 unsigned int madeFailCount = 0;
2012 for (
size_t i=0;i<files.size();++i)
2016 if (!resultData.empty())
2017 resultData.append(
",");
2018 resultData.append(files[i]);
2025 for (
size_t k=0;k<
branches.size();++k)
2026 for (
size_t i=0;i<files.size();++i)
2031 if (!resultData.empty())
2032 resultData.append(
",");
2033 resultData.append(files[i]);
2038 if (madeFailCount==0)
2066 std::vector<std::string> dataFiles, sourceFiles, configFiles, propertyFiles, indexes;
2073 if (dataFiles.size()==0 && sourceFiles.size()==0 && indexes.size()==0 && configFiles.size()==0 && propertyFiles.size()==0)
2083 removeIndexFiles(indexDir,
branches, indexes));
2089 catch(Poco::Exception& e)
2120 catch(Poco::Exception& e)
2150 std::stringstream oldContent;
2152 std::ifstream ifs(dataFileName.c_str(), std::fstream::binary);
2155 oldContent << ifs.rdbuf();
2163 if (!dataFile.
append(strAppendContent))
2166 std::fstream fst(dataFileName.c_str(), std::fstream::out|std::fstream::trunc|std::fstream::binary);
2173 catch(Poco::Exception& e)
2198 Poco::JSON::Object::Ptr obj =
new Poco::JSON::Object();
2201 Poco::JSON::Array::Ptr array =
new Poco::JSON::Array();
2202 for (
size_t i=0;i<ids.size();++i)
2203 array->add(std::to_string(ids[i]));
2206 std::stringstream ostr;
2207 Poco::JSON::Stringifier::stringify(obj, ostr);
2212 catch(std::exception& e)
2228 Poco::JSON::Parser parser;
2229 Poco::Dynamic::Var res = parser.parse(json);
2230 Poco::JSON::Object::Ptr obj = res.extract<Poco::JSON::Object::Ptr>();
2237 if (!vecDocs.isNull())
2239 for (
size_t k = 0;k<vecDocs->size();++k)
2241 Poco::Dynamic::Var tmp = vecDocs->get(k);
2246 unsigned long long id = std::stoull(tmp.convert<std::string>());
2249 catch(std::exception& e)
2251 fObj.
log(LoggerStream::Priority::PRIO_INFORMATION) <<
"Get bad doc ID: " << e.what() <<
flush;
2254 if (tmp.isNumeric())
2256 unsigned long long id = tmp.convert<Poco::Int64>();
2263 catch(Poco::JSON::JSONException& e)
2288 std::fstream fst(fileName.c_str(), std::fstream::out|std::fstream::app);
2292 for (
size_t i=0;i<ids.size();++i)
2293 fst << (
unsigned long long)(ids[i]) <<
flush;
2298 std::ofstream ofs(fileName.c_str(), std::fstream::trunc);
2299 for (
size_t i=0;i<ids.size();++i)
2300 ofs << ids[i] <<
flush;
2305 catch(Poco::Exception& e)
2334 std::ifstream ifs(fileName.c_str());
2339 while(getline(ifs, line))
2348 catch(Poco::Exception& e)
2353 catch(std::exception& e)
2367 bool IndexPackDocData::packData(
const std::string& file, std::set<std::string>& delList)
2369 bool result =
false;
2373 std::string xmlString;
2374 std::string outString;
2377 std::ifstream in(file.c_str());
2381 in.seekg(0, std::ios::end);
2382 xmlString.resize(in.tellg());
2383 in.seekg(0, std::ios::beg);
2384 in.read(&xmlString[0], xmlString.size());
2387 outString = xmlCleaner.process(xmlString, delList);
2389 std::ofstream ofs(file.c_str(), std::fstream::trunc);
2395 catch(Poco::Exception& e)
2399 catch(std::exception& e)
2406 bool IndexPackDocData::getDocumentCount(
const std::string& file,
size_t& documentCount)
2408 bool result =
false;
2411 std::ifstream ifs(file.c_str());
2415 SphinxDataFile dataFile;
2416 size_t count = dataFile.documentCount(ifs);
2419 if (dataFile.isError())
2420 throw Poco::Exception(dataFile.getErrorMsg());
2423 documentCount += count;
2425 catch(Poco::Exception& e)
2429 catch(std::exception& e)
2459 std::set<std::string> delList;
2463 std::ifstream ifs(fileName.c_str());
2468 while(getline(ifs, line))
2473 delList.insert(line);
2475 catch(std::exception& e)
2482 if (!
moveFile(fileName, backupFile))
2486 std::vector<std::string> vFiles;
2490 size_t documentCount = 0;
2492 if (vFiles.size()==0)
2498 for (
size_t i=0;i<vFiles.size();++i)
2509 for (
size_t k=0;k<
branches.size();++k)
2510 for (
size_t i=0;i<vFiles.size();++i)
2527 catch(Poco::Exception& e)
2532 catch(std::exception& e)
2561 if (!indexStop.execute())
2564 std::string
cmd(
"rm");
2565 std::vector<std::string>
args = {
"-R", path};
2567 std::stringstream outMsg;
2569 if (!procExec.
exec(outMsg, outMsg))
2579 args.push_back(
"-R");
2580 args.push_back(path);
2586 catch(Poco::Exception& e)
2606 Poco::JSON::Object::Ptr obj =
new Poco::JSON::Object();
2610 std::stringstream ostr;
2611 Poco::JSON::Stringifier::stringify(obj, ostr);
2616 catch(std::exception& e)
2632 Poco::JSON::Parser parser;
2633 Poco::Dynamic::Var res = parser.parse(json);
2634 Poco::JSON::Object::Ptr obj = res.extract<Poco::JSON::Object::Ptr>();
2646 catch(Poco::JSON::JSONException& e)
2672 const std::string
cmd(
"cp");
2673 std::vector<std::string>
args = {
"-R", srcIndex, dstIndex};
2675 if (!procExec.
exec())
2682 std::vector<std::string> keys;
2685 for (
size_t i=0;i<keys.size();++i)
2690 std::string value = pConf->getString(name);
2693 if (pos!=std::string::npos)
2696 pConf->setString(name, value);
2702 std::string value = pConf->getString(name);
2705 if (pos!=std::string::npos)
2708 pConf->setString(name, value);
2722 unsigned int port = 0;
2729 pConf->save(propFile);
2730 pConf->setPropertyFileConfiguration(propFile);
2733 std::ofstream ofs(sphinxConfigFile.c_str(), std::fstream::trunc);
2739 catch(Poco::Exception& e)
2744 catch(std::exception& e)
2780 catch(Poco::Exception& e)
2800 Poco::JSON::Object::Ptr obj =
new Poco::JSON::Object();
2807 std::stringstream ostr;
2808 Poco::JSON::Stringifier::stringify(obj, ostr);
2813 catch(std::exception& e)
2831 Poco::JSON::Parser parser;
2832 Poco::Dynamic::Var res = parser.parse(json);
2833 Poco::JSON::Object::Ptr obj = res.extract<Poco::JSON::Object::Ptr>();
2857 catch(Poco::JSON::JSONException& e)
2883 pConf->save(propFile);
2884 pConf->setPropertyFileConfiguration(propFile);
2887 std::ofstream ofs(configFile.c_str(), std::fstream::trunc);
2893 catch(Poco::Exception& e)
2913 Poco::JSON::Object::Ptr obj =
new Poco::JSON::Object();
2918 std::stringstream ostr;
2919 Poco::JSON::Stringifier::stringify(obj, ostr);
2924 catch(std::exception& e)
2941 Poco::JSON::Parser parser;
2942 Poco::Dynamic::Var res = parser.parse(json);
2943 Poco::JSON::Object::Ptr obj = res.extract<Poco::JSON::Object::Ptr>();
2959 catch(Poco::JSON::JSONException& e)
2987 catch(Poco::Exception& e)
3013 std::ifstream ifs(path.c_str(), std::fstream::binary);
3018 std::vector<std::pair<std::string, int> > oldSchemaVec;
3024 std::stringstream str;
3027 std::vector<std::pair<std::string, int> > checkSchemaVec;
3029 if (!checkSchemaFile.
getFields(checkSchemaVec))
3032 for (
size_t i=0;i<checkSchemaVec.size();++i)
3034 bool isFound =
false;
3035 for (
size_t k=0;k<oldSchemaVec.size();++k)
3037 if (checkSchemaVec[i].first==oldSchemaVec[k].first)
3049 catch(Poco::Exception& e)
3079 std::stringstream outMsg, errMsg;
3080 const std::string
cmd(
"searchd");
3081 std::vector<std::string>
args = {
"--status",
"--config", configFile};
3083 if (!procExec.
exec(outMsg, errMsg))
3093 catch(Poco::Exception& e)
3103 bool result =
false;
3112 catch(Poco::Exception& e)
3142 std::stringstream outMsg;
3143 const std::string
cmd(
"indextool");
3147 if (procExec.isError())
3157 catch(Poco::Exception& e)
3179 unsigned long long maxDocId = 0;
3191 std::vector<std::string> vFiles;
3197 for (
size_t i=0;i<vFiles.size();++i)
3200 ifs.open(fileName.c_str());
3203 if (dataSourceParameters.
load(ifs))
3205 if (maxDocId < dataSourceParameters.
getMaxDocId())
3219 catch(Poco::Exception& e)
3224 catch(std::exception& e)
3255 if (!
isExistDir(path+
"/"+sphinx_admin_command_const::dataDir))
3258 std::vector<std::string> vFiles;
3261 for (
size_t i=0;i<vFiles.size();++i)
3270 catch(Poco::Exception& e)
3301 if (!
isExistDir(path+
"/"+sphinx_admin_command_const::indexDir))
3304 std::vector<std::string> vIndexes;
3307 for (
size_t i=0;i<vIndexes.size();++i)
3316 catch(Poco::Exception& e)
3332 bool result =
false;
3333 branchFieldsList.clear();
3340 ifs.open(branchFileName.c_str());
3344 bool loaded = dataSourceParameters.
load(ifs);
3349 std::string fieldsList;
3351 for (SphinxDataSourceParameters::PARAM_ATTR__MAP::iterator iter=paramAttr.begin();iter!=paramAttr.end();++iter)
3353 if (!fieldsList.empty())
3354 fieldsList.append(
",");
3355 fieldsList.append((*iter).first).append(
"=").append(std::to_string((*iter).second));
3357 Poco::URI::encode(fieldsList,
"", branchFieldsList);
3360 catch(Poco::Exception& e)
3391 std::vector<std::string> vFiles;
3394 unsigned int madeFailCount = 0;
3397 for (
size_t i=0;i<vFiles.size();++i)
3399 std::string branchFieldsList;
3404 resultData.append(vFiles[i]).append(
"=").append(branchFieldsList);
3412 for (
size_t k=0;k<
branches.size();++k)
3413 for (
size_t i=0;i<vFiles.size();++i)
3416 std::string branchFieldsList;
3421 resultData.append(vFiles[i]).append(
"=").append(branchFieldsList);
3428 if (madeFailCount==0)
3435 catch(Poco::Exception& e)
3451 bool result =
false;
3458 std::vector<std::string> keys;
3461 std::string trunkSectionName;
3462 for (
size_t i=0;i<keys.size();++i)
3468 pConf->setString(name, value);
3471 trunkSectionName = keys[i];
3475 pConf->setString(name, value);
3478 pConf->cloneSphinxConfigSection(trunkSectionName, branchSectionName);
3482 pConf->setString(name, value);
3495 pConf->save(propFile);
3496 pConf->setPropertyFileConfiguration(propFile);
3499 std::ofstream ofs(configFile.c_str(), std::fstream::trunc);
3504 catch(Poco::Exception& e)
3516 bool result =
false;
3517 information.clear();
3521 std::string branchConfigFileName;
3528 std::stringstream outMsg, errMsg;
3529 const std::string
cmd(
"indextool");
3530 std::vector<std::string>
args = {
"--dumpheader",
indexFileName,
"--config", branchConfigFileName};
3532 if (!procExec.
exec(outMsg, errMsg))
3538 Poco::URI::encode(outMsg.str(),
"", information);
3542 catch(Poco::Exception& e)
3574 std::vector<std::string> vIndexes;
3577 unsigned int madeFailCount = 0;
3580 for (
size_t i=0;i<vIndexes.size();++i)
3582 std::string information;
3587 resultData.append(vIndexes[i]).append(
"=").append(information);
3595 for (
size_t k=0;k<
branches.size();++k)
3596 for (
size_t i=0;i<vIndexes.size();++i)
3599 std::string information;
3604 resultData.append(vIndexes[i]).append(
"=").append(information);
3611 if (madeFailCount==0)
3618 catch(Poco::Exception& e)
3666 catch(Poco::Exception& e)
3686 Poco::JSON::Object::Ptr obj =
new Poco::JSON::Object();
3688 std::stringstream ostr;
3689 Poco::JSON::Stringifier::stringify(obj, ostr);
3694 catch(std::exception& e)
3708 Poco::JSON::Parser parser;
3709 Poco::Dynamic::Var res = parser.parse(json);
3710 Poco::JSON::Object::Ptr obj = res.extract<Poco::JSON::Object::Ptr>();
3714 catch(Poco::JSON::JSONException& e)
3736 catch(Poco::Exception& e)