1 #include <gtest/gtest.h>
2 #include <Poco/SharedPtr.h>
56 branches.push_back(
"branch_0005");
57 branches.push_back(
"branch_0006");
58 branches.push_back(
"branch_0007");
59 for (
size_t i=0;i<branches.size();++i)
71 for (
size_t i=0;i<branches.size();++i)
75 branches.push_back(
"branch_0008");
76 branches.push_back(
"branch_0009");
80 branches.push_back(
"*");
89 branches.push_back(
"branch_0005");
93 branches.push_back(
"branch_0005");
94 branches.push_back(
"branch_0006");
95 branches.push_back(
"branch_0007");
101 branches.push_back(
"branch_0005");
103 branches.push_back(
"branch_0006");
105 branches.push_back(
"branch_0007");
107 branches.push_back(
"branch_0008");
108 branches.push_back(
"branch_0009");
115 for (
size_t i=0;i<branches.size();++i)
118 branches.push_back(
"*");
123 branches.push_back(
"branch_0005");
124 branches.push_back(
"branch_0006");
125 for (
size_t i=0;i<branches.size();++i)
128 for (
size_t i=0;i<branches.size();++i)
131 std::vector<unsigned long long> ids = { 123456789012, 123456789023, 123456789034, 123456789045, 123456789056, 123456789067, 123456789078, 123456789089, 123456789090, 1234567890101};
136 branches.push_back(
"branch_0005");
137 branches.push_back(
"branch_0006");
138 branches.push_back(
"branch_0007");
139 for (
size_t i=0;i<branches.size();++i)
148 branches.push_back(
"*");
159 branches.push_back(
"branch_0005");
160 branches.push_back(
"branch_0006");
161 branches.push_back(
"branch_0007");
162 for (
size_t i=0;i<branches.size();++i)
197 std::string paramValue;
213 for (
size_t i=0;i<branches.size();++i)
246 std::vector<std::string>
branches = {
"branch_0005"};
247 for (
size_t i=0;i<branches.size();++i)
256 const std::string newIndexName =
"i004";
267 const std::string
nodeName =
"test_node";
269 const unsigned int SZ = 3;
270 const std::string
indexName[SZ] = {
"i003",
"i004" ,
"i005"};
271 Poco::SharedPtr<SphinxFunctionalObject>
pObj[SZ];
273 for (
unsigned int i=0;i<SZ;++i)
279 std::vector<std::string>
branches = {
"branch_0005"};
280 for (
size_t k=0;k<branches.size();++k)
290 for (
unsigned int i=0;i<SZ;++i)
293 for (
unsigned int i=0;i<SZ;++i)
294 ASSERT_FALSE(pObj[i]->isError());
311 std::vector<std::string>
branches = {
"branch_0005"};
312 for (
size_t i=0;i<branches.size();++i)
336 "{\"type\":\"0\",\"data\":\"{\\\"q\\\":\\\"post\\\",\\\"filters\\\":\\\"[{\\\\\\\"type\\\\\\\":0,\\\\\\\"attribute\\\\\\\":\\\\\\\"afflags7ex\\\\\\\",\\\\\\\"values\\\\\\\":[\\\\\\\"141665\\\\\\\"],\\\\\\\"exclude\\\\\\\":\\\\\\\"0\\\\\\\"}]\\\",\\\"max_results\\\":10,\\\"sort_mode\\\":1,\\\"parameters\\\":[{\\\"queryId\\\":\\\"2829799777\\\"},{\\\"JsonType\\\":7},{\\\"sort_by\\\":\\\"weight\\\"}]}\"}";
339 json =
"{\"type\":\"0\",\"data\":\"{\\\"q\\\":\\\"post\\\",\\\"filters\\\":\\\"[]\\\",\\\"max_results\\\":10,\\\"sort_mode\\\":1,\\\"parameters\\\":[{\\\"queryId\\\":\\\"2829799777\\\"},{\\\"JsonType\\\":7},{\\\"sort_by\\\":\\\"weight\\\"}]}\"}";
342 json =
"{\"type\":\"0\",\"data\":\"{\\\"q\\\":\\\"post\\\",\\\"filters\\\":\\\"[]\\\",\\\"max_results\\\":10,\\\"sort_mode\\\":1,\\\"parameters\\\":[]}\"}";
345 json =
"{\"type\":\"0\",\"data\":\"{\\\"query\\\":\\\"post\\\",\\\"filters\\\":\\\"[]\\\",\\\"sort_mode\\\":1,\\\"parameters\\\":[]}\"}";
348 json =
"{\"type\":\"0\",\"data\":\"{\\\"filters\\\":\\\"[]\\\",\\\"parameters\\\":[]}\"}";
356 Poco::SharedPtr<SphinxFilter> pFilter =
new SphinxFilter;
358 if (filterType==SphinxFilter::FilterType::ftRangeFloat)
361 pFilter->setAttributeName(
"uid");
362 pFilter->setExcludeValue(SphinxFilter::ExcludeType::etFalse);
363 pFilter->addAttributeValue(
"1.9");
364 pFilter->addAttributeValue(
"2.1");
365 filters.push_back(pFilter);
369 pFilter->setFilterType(filterType);
370 pFilter->setAttributeName(
"afflags4");
371 pFilter->setExcludeValue(SphinxFilter::ExcludeType::etFalse);
372 pFilter->addAttributeValue(
"4");
373 pFilter->addAttributeValue(
"8");
374 filters.push_back(pFilter);
378 pFilter->setAttributeName(
"afflags4ex");
379 pFilter->setExcludeValue(SphinxFilter::ExcludeType::etFalse);
380 pFilter->addAttributeValue(
"16");
381 pFilter->addAttributeValue(
"64");
382 filters.push_back(pFilter);
386 void SphinxFunctionalObjectTest::makeSearchFilter(SphinxFunctionalObject& fObj,
SphinxFilter::FilterType filterType,
size_t repeatCount)
388 const std::string
query =
"@bodys ceo";
389 std::vector<Poco::SharedPtr<SphinxFilter> > filters;
390 Poco::SharedPtr<SphinxResultData> resultData[repeatCount];
391 Poco::SharedPtr<SphinxResultDataSerializator> resultSerializator[repeatCount];
393 for (
size_t i=0;i<repeatCount;++i)
395 resultData[i] =
new SphinxResultData();
396 resultSerializator[i] =
new SphinxResultDataSerializator(*(resultData[i]));
399 initFilters(filterType, filters);
401 for (
size_t i=0;i<repeatCount;++i)
405 for (
size_t i=1;i<repeatCount;++i)
407 const size_t matchInfoCountPrev = resultData[i-1]->getMatchInfoCount();
408 const size_t matchInfoCountNext = resultData[i]->getMatchInfoCount();
410 ASSERT_EQ(matchInfoCountPrev, matchInfoCountNext);
411 for (
size_t k=0;k<matchInfoCountPrev;++k)
413 const SphinxMatchInfo& matchInfoPrev = resultData[i-1]->getMatchInfoItem(k);
414 const SphinxMatchInfo& matchInfoNext = resultData[i]->getMatchInfoItem(k);
416 ASSERT_EQ(matchInfoPrev.getDocId(), matchInfoNext.getDocId());
417 ASSERT_EQ(matchInfoPrev.getWeight(), matchInfoNext.getWeight());
419 const size_t attributesCountPrev = matchInfoPrev.getAttributesCount();
420 const size_t attributesCountNext = matchInfoNext.getAttributesCount();
422 ASSERT_EQ(attributesCountPrev, attributesCountNext);
423 for (
size_t j=0;j<attributesCountPrev;++j)
425 const AttrInfo& attrInfoPrev = matchInfoPrev.getAttrItem(j);
426 const AttrInfo& attrInfoNext = matchInfoNext.getAttrItem(j);
428 ASSERT_EQ(attrInfoPrev.name, attrInfoNext.name);
429 ASSERT_EQ(attrInfoPrev.value, attrInfoNext.value);
438 dataContent <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n<sphinx:document id=\"9223372490088244475\">"
439 <<
"<title><![CDATA[Mars One opens applications for one-way ticket to Mars]]></title>\n"
440 <<
"<h><![CDATA[<a href='http://cdni.wired.co.uk/620x413/k_n/Mars_7.jpg' target=_blank><img src='http://cdni.wired.co.uk/620x413/k_n/Mars_7.jpg' title='size: 0 width: 0 height: 0'></a>one-way ticket\nMars\n∧one∧way∧ticket\n∧Mars http://wired.co.uk/news/archive/2013-04/25/mars-one-applications ]]></h>\n"
441 <<
"<alt><![CDATA[2,8,32,128]]></alt>\n"
442 <<
"<bodys><![CDATA[It's time, if you're so inclined, to plunk down a reservation\nfor a one-way ticket to Mars. The privately funded Mars One\n"
443 <<
"foundation recently opened up applications for astronauts to take a\njourney to the Red Planet in 2022/23. Return trips, the organisers\n"
444 <<
"said, just aren't feasible with the technology we have.\nFrom a wide field of applicants, organisers said two women and\ntwo men will be selected to make the journey. The technology that\n"
445 <<
"takes them there has been tested before, and the potential for a\nworldwide audience will be there given four billion people will\nhave the internet by then, said Mars One CEO Bas Lansdorp.\n"
446 <<
"By: Elizabeth Howell, SEN.com, Edited by: Kadhim ShubberContinue reading...]]></bodys>\n"
447 <<
"<bodyn><![CDATA[10101010]]></bodyn>\n<meta><![CDATA[1191]]></meta>\n<ref><![CDATA[93]]></ref>\n"
448 <<
"<url><![CDATA[http://api.snatz.com/index.php?app=hceapi&event=feeds&time=new&feed_id=11250311753507343583&item_id=14946343666313105260-13-04]]></url>\n"
449 <<
"<cdate>1373619775</cdate>\n<mmedia>0</mmedia>\n<bseo>0</bseo>\n<uid>2</uid>\n<sid>1</sid>\n<lang>255</lang>\n"
450 <<
"<afflags0>2,8,32,128</afflags0>\n<afflags1>24</afflags1>\n<afflags2>1</afflags2>\n<afflags3>2,8,32,128</afflags3>\n"
451 <<
"<afflags4>2,8,32,128</afflags4>\n<afflags5>2,8,32,128</afflags5>\n<afflags6>2,8,32,128</afflags6>\n<afflags7>2,8,32,128</afflags7>\n\n"
452 <<
"<afflags0ex>1,4,16,64</afflags0ex>\n<afflags1ex>1,4,16,64</afflags1ex>\n<afflags2ex>1,4,16,64</afflags2ex>\n<afflags3ex>1,4,16,64</afflags3ex>\n"
453 <<
"<afflags4ex>1,4,16,64</afflags4ex>\n<afflags5ex>1,4,16,64</afflags5ex>\n<afflags6ex>1,4,16,64</afflags6ex>\n<afflags7ex>1,4,16,64</afflags7ex>\n"
454 <<
"</sphinx:document>\n</sphinx:docset>\n";
461 std::vector<std::string>
branches = {
"branch_0005"};
462 for (
size_t i=0;i<branches.size();++i)
470 const size_t testRepeat = 3;
472 SphinxFunctionalObjectTest::makeSearchFilter(fObj, SphinxFilter::FilterType::ftSimple, testRepeat);
474 printSuccess(
"Search Filter ftSimple");
476 SphinxFunctionalObjectTest::makeSearchFilter(fObj, SphinxFilter::FilterType::ftRangeFloat, testRepeat);
478 printSuccess(
"Search Filter ftRangeFloat");
480 SphinxFunctionalObjectTest::makeSearchFilter(fObj, SphinxFilter::FilterType::ftRangeInteger, testRepeat);
482 printSuccess(
"Search Filter ftRangeInteger");
484 SphinxFunctionalObjectTest::makeSearchFilter(fObj, SphinxFilter::FilterType::ftSimpleMulti, testRepeat);
486 printSuccess(
"Search Filter ftSimpleMulti");
490 printSuccess(
"Test search with different filters");
497 const unsigned long long docId = 9223372490088244475ULL;
500 dataContent <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">\n<sphinx:document id=\""<<docId<<
"\">"
501 <<
"<title><![CDATA[Mars One opens applications for one-way ticket to Mars]]></title>\n"
502 <<
"<h><![CDATA[<a href='http://cdni.wired.co.uk/620x413/k_n/Mars_7.jpg' target=_blank><img src='http://cdni.wired.co.uk/620x413/k_n/Mars_7.jpg' title='size: 0 width: 0 height: 0'></a>one-way ticket\nMars\n∧one∧way∧ticket\n∧Mars http://wired.co.uk/news/archive/2013-04/25/mars-one-applications ]]></h>\n"
503 <<
"<alt><![CDATA[2,8,32,128]]></alt>\n"
504 <<
"<bodys><![CDATA[It's time, if you're so inclined, to plunk down a reservation\nfor a one-way ticket to Mars. The privately funded Mars One\n"
505 <<
"foundation recently opened up applications for astronauts to take a\njourney to the Red Planet in 2022/23. Return trips, the organisers\n"
506 <<
"said, just aren't feasible with the technology we have.\nFrom a wide field of applicants, organisers said two women and\ntwo men will be selected to make the journey. The technology that\n"
507 <<
"takes them there has been tested before, and the potential for a\nworldwide audience will be there given four billion people will\nhave the internet by then, said Mars One CEO Bas Lansdorp.\n"
508 <<
"By: Elizabeth Howell, SEN.com, Edited by: Kadhim ShubberContinue reading...]]></bodys>\n"
509 <<
"<bodyn><![CDATA[10101010]]></bodyn>\n<meta><![CDATA[1191]]></meta>\n<ref><![CDATA[93]]></ref>\n"
510 <<
"<url><![CDATA[http://api.snatz.com/index.php?app=hceapi&event=feeds&time=new&feed_id=11250311753507343583&item_id=14946343666313105260-13-04]]></url>\n"
511 <<
"<cdate>1373619775</cdate>\n<mmedia>0</mmedia>\n<bseo>0</bseo>\n<uid>2</uid>\n<sid>1</sid>\n<lang>255</lang>\n"
512 <<
"<afflags0>2,8,32,128</afflags0>\n<afflags1>24</afflags1>\n<afflags2>1</afflags2>\n<afflags3>2,8,32,128</afflags3>\n"
513 <<
"<afflags4>2,8,32,128</afflags4>\n<afflags5>2,8,32,128</afflags5>\n<afflags6>2,8,32,128</afflags6>\n<afflags7>2,8,32,128</afflags7>\n\n"
514 <<
"<afflags0ex>1,4,16,64</afflags0ex>\n<afflags1ex>1,4,16,64</afflags1ex>\n<afflags2ex>1,4,16,64</afflags2ex>\n<afflags3ex>1,4,16,64</afflags3ex>\n"
515 <<
"<afflags4ex>1,4,16,64</afflags4ex>\n<afflags5ex>1,4,16,64</afflags5ex>\n<afflags6ex>1,4,16,64</afflags6ex>\n<afflags7ex>1,4,16,64</afflags7ex>\n"
516 <<
"</sphinx:document>\n</sphinx:docset>\n";
518 const std::string query =
"Mars";
525 std::vector<std::string>
branches = {
"branch_"+indexName};
526 for (
size_t i=0;i<branches.size();++i)
543 printSuccess(
"SphinxInputJsonMessageSearch serialize");
546 inputJsonMessage.
setType(SphinxInputJsonMessage::MessageType::mtSearch);
547 inputJsonMessage.
setData(json);
567 printSuccess(
"SphinxResultData unserialize");
569 assert(resultData.getMatchInfoCount()==1);
570 unsigned long long retDocId = resultData.getMatchInfoItem(0).getDocId();
572 result = (retDocId==
docId);
573 std::cout <<
"retDocId = " << retDocId <<
std::endl;
574 std::cout <<
"docId = " << docId <<
std::endl;
579 printSuccess(
"Test Use 32 or 64 Bit");
587 std::vector<std::string> indexNames;
599 std::string
indexName = indexNames.front();
609 std::vector<std::string> queries=
610 {
"seo",
"ISO",
"with",
"LibreOffice",
"is",
"free",
"and",
"open",
"source",
"office",
"suite",
"for",
"Linux",
"Mac",
"Windows",
"computers",
"Forest",
"Key",
"Seattle",
"MGM"};
615 std::stringstream outMsg;
616 outMsg <<
"Single index search perfomance: " << singleIndexFps <<
" fps." <<
std::endl;
617 const size_t length = outMsg.str().length();
618 std::cout << std::string(length,
'=') <<
"\n";
619 std::cout <<
"Multi index search perfomance: " << multiIndexFps <<
" fps." <<
std::endl;
620 std::cout << outMsg.str() << std::string(length,
'=') <<
std::endl;
624 void SphinxFunctionalObjectTest::createBigIndex(
const std::string&
homeDir,
const std::string& sourceTestDir,
const std::string&
indexName)
628 std::vector<std::string> dataFiles;
631 std::cout <<
"Error: " << errorMsg <<
std::endl;
634 for (
const auto&
name: dataFiles)
642 std::cout <<
"Error: " << errorMsg <<
std::endl;
645 std::vector<std::string>
branches = {
"*"};
651 const std::string& indexName,
bool needMakeIndex,
bool needRemoveIndex)
656 std::string paramValue;
660 const std::string query =
"и";
664 size_t maxReturnedDocs = 0;
665 const size_t maxCount = 10000;
666 for (
size_t i=1000;i<maxCount;i+=1000)
668 printMessage(
"Try get "+std::to_string(i)+
" documents");
672 maxReturnedDocs = i-1000;
674 for (
size_t j=maxReturnedDocs+100;j<maxCount;j+=100)
676 printMessage(
"Try get "+std::to_string(j)+
" documents");
696 printMessage(
"MAX RETURNED DOCS: "+std::to_string(maxReturnedDocs));
697 printSuccess(
"Stress test get max result");
701 const std::string& indexName,
bool needMakeIndex,
bool needRemoveIndex)
706 std::string paramValue;
710 const std::string query =
"";
711 const unsigned int maxResults = 1000;
712 const unsigned int offset = 999;
721 printSuccess(
"Stress test get result use offset");