1 #include <Poco/SharedPtr.h>
2 #include <Poco/ScopedLock.h>
3 #include <Poco/ThreadPool.h>
28 : inherited(
"search_"+indexName_),
indexName(indexName_), queries(queries_),
29 fObj(
"node_"+indexName_, sphinx_search_const::
defaultDataDir, indexName_, start, stop), fps(0)
43 const float progressStep = 100/queries.size();
45 for (
size_t i=0;i<queries.size();++i)
48 progress += progressStep;
49 setProgress(progress);
53 localTime /= queries.size();
61 std::cout << pNf->task()->name() <<
" progress: " << pNf->progress() <<
std::endl;
67 std::cout << pNf->task()->name() <<
" finished." <<
std::endl;
69 Poco::Mutex::ScopedLock lock(mutex);
77 Poco::Mutex::ScopedLock lock(mutex);
82 void SphinxMultiIndexTest::printSuccess(
const std::string& msg, std::ostream& os)
84 os << std::setw(40) << msg <<
" - OK\n";
87 void SphinxMultiIndexTest::printWarning(
const std::string& msg, std::ostream& os)
89 os << std::setw(40) << msg <<
" - WARNING\n";
99 branches.push_back(
"branch_"+indexName);
101 if (!dataContent.empty())
103 for (
size_t i=0;i<branches.size();++i)
109 for (
size_t i=0;i<branches.size();++i)
134 handler.
setType(SphinxInputJsonMessage::MessageType::mtSearch);
135 handler.setData(json);
137 std::stringstream str;
151 assert(!outputMessage.isError());
155 return outputMessage.getTime();
161 for (
size_t i=1;i<=count;++i)
168 names.push_back(indexName.str());
175 std::ifstream ifs(dataFileName.c_str(), std::fstream::binary);
178 std::streambuf* pbuf = ifs.rdbuf();
179 std::streamsize size = pbuf->pubseekoff(0,ifs.end);
180 pbuf->pubseekoff(0,ifs.beg);
181 dataContent.resize(size);
182 pbuf->sgetn (const_cast<char*>(dataContent.c_str()), size);
184 printSuccess(
"Load data file for test '"+dataFileName+
"'");
196 for (
size_t i=0;i<names.size();++i)
204 assert(names.size());
205 Poco::ThreadPool threadPool(1, names.size());
206 Poco::TaskManager tm(threadPool);
211 for (
size_t i=0;i<names.size();++i)
220 void SphinxMultiIndexTest::setIndexProperty(
const std::string&
homeDir,
const std::string&
indexName,
const IndexProperty& property)
throw (Poco::Exception)
225 std::vector<std::string> keys;
228 for (
size_t i=0;i<keys.size();++i)
233 pConf->setString(name, property.path);
238 pConf->save(propFile);
239 pConf->setPropertyFileConfiguration(propFile);
242 std::ofstream ofs(sphinxConfig.c_str(), std::fstream::trunc);
247 void SphinxMultiIndexTest::getIndexProperty(
const std::string&
homeDir,
const std::string&
indexName, IndexProperty& property)
throw (Poco::Exception)
250 Poco::AutoPtr<SphinxConfigCreator> pConf =
new SphinxConfigCreator(propFile);
252 std::vector<std::string> keys;
255 for (
size_t i=0;i<keys.size();++i)
260 property.path = pConf->getString(name);
269 assert(names.size());
271 Poco::ThreadPool threadPool(1, names.size());
272 Poco::TaskManager tm(threadPool);
279 IndexProperty property;
280 SphinxMultiIndexTest::getIndexProperty(homeDir, indexName, property);
283 std::map<std::string, IndexProperty> Map;
284 for (
size_t i=0;i<names.size();++i)
286 if (indexName==names[i])
288 IndexProperty localProperty;
289 SphinxMultiIndexTest::getIndexProperty(homeDir, names[i], localProperty);
290 Map[names[i]] = localProperty;
291 SphinxMultiIndexTest::setIndexProperty(homeDir, names[i], property);
295 tm.start(
new SearchTask(indexName, queries,
true,
false));
296 for (
size_t i=0;i<names.size();++i)
298 if (indexName==names[i])
300 tm.start(
new SearchTask(names[i], queries,
false,
false));
307 for (std::map<std::string, IndexProperty>::iterator iter=Map.begin();iter!=Map.end();++iter)
310 SphinxMultiIndexTest::setIndexProperty(homeDir, (*iter).first, (*iter).second);
313 catch(Poco::Exception& e)
315 std::cout <<
"Error ("<< e.code() <<
"): " << e.message() <<
std::endl;
323 for (
size_t i=0;i<names.size();++i)