Ejemplo n.º 1
0
LogicalPlanNode * LogicalPlan::createTermLogicalPlanNode(const std::string &queryKeyword,
		TermType type,const float boost, const float fuzzyMatchPenalty,
		const uint8_t threshold , const vector<unsigned>& fieldFilter,ATTRIBUTES_OP attrOp){
	Term * term = new Term(queryKeyword, type, boost, fuzzyMatchPenalty, threshold);
	term->addAttributesToFilter(fieldFilter, attrOp);
	LogicalPlanNode * node = new LogicalPlanNode(term , NULL);
	return node;
}
void fireSearch(QueryEvaluator * queryEvaluator, vector<unsigned> filter, ATTRIBUTES_OP attrOp, unsigned k, const vector<string> &searchKeywords,
                unsigned numOfResults, const vector<string> &resultIds, const vector<vector<vector<unsigned> > > &resultAttributeBitmap)
{
    
    Query *query = new Query(srch2::instantsearch::SearchTypeTopKQuery);
    QueryResultFactory * resultFactory = new QueryResultFactory();
    QueryResults * queryResults = new QueryResults(resultFactory,queryEvaluator, query);

    for (unsigned i = 0; i < searchKeywords.size(); ++i)
    {
        TermType termType = TERM_TYPE_PREFIX;
        Term *term = ExactTerm::create(searchKeywords[i], termType, 1, 0.5);
        term->addAttributesToFilter(filter, attrOp);
        query->setPrefixMatchPenalty(0.95);
        query->add(term);
    }


    LogicalPlan * logicalPlan = prepareLogicalPlanForUnitTests(query , NULL, 0, 10, false, srch2::instantsearch::SearchTypeTopKQuery);
    queryEvaluator->search(logicalPlan , queryResults);
//    QueryEvaluatorRuntimeParametersContainer runTimeParameters;
//    QueryEvaluator * queryEvaluator = new QueryEvaluator(indexer,&runTimeParameters );
    cout << "record found :" << queryResults->getNumberOfResults() << endl;
    ASSERT(queryResults->getNumberOfResults() == numOfResults);

    vector<vector<unsigned> > matchedAttributeBitmap;
    for (unsigned i = 0; i< numOfResults; ++i)
    {
        ASSERT(queryResults->getRecordId(i) == resultIds[i]);
        queryResults->getMatchedAttributes(i, matchedAttributeBitmap);
        for(int j = 0; j< matchedAttributeBitmap.size(); j++)
        	for(int k = 0; k< matchedAttributeBitmap[j].size(); k++)
        		ASSERT(matchedAttributeBitmap[j][k] == resultAttributeBitmap[i][j][k]);
    }

    delete queryResults;
    delete query;
    delete resultFactory;

}