Created
May 15, 2012 18:17
-
-
Save dvogel/2703907 to your computer and use it in GitHub Desktop.
Superfastmatch Search::execute and PostingSlot::searchIndex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Search::execute(){ | |
size_t num_results=registry_->getNumResults(); | |
size_t count=0; | |
registry_->getPostings()->searchIndex(*this); | |
for(inverted_search_t::iterator it2=pruned_results.begin(),ite2=pruned_results.end();(it2!=ite2) && (count<num_results);++it2){ | |
DocumentPtr other=registry_->getDocumentManager()->getDocument(it2->second.doc_type,it2->second.doc_id,DocumentManager::META); | |
AssociationPtr association(new Association(registry_,doc,other)); | |
performance->add(association->getInstrument()); | |
if (association->getResultCount()>0){ | |
associations.push_back(association); | |
if (doc->isPermanent()){ | |
association->save(); | |
} | |
count++; | |
} | |
} | |
} | |
bool PostingSlot::searchIndex(const uint32_t doctype,const uint32_t docid,const uint32_t hash, const uint32_t position,PostLine& line,search_t& results){ | |
const uint32_t slot_hash = hash-offset_; | |
const uint8_t current=position&0xFF; | |
if(index_.test(slot_hash)){ | |
const unsigned char* start=index_.unsafe_get(slot_hash); | |
vector<PostLineHeader>* doctypes=line.load(start); | |
for (vector<PostLineHeader>::const_iterator it=doctypes->begin(),ite=doctypes->end();it!=ite;++it){ | |
vector<uint32_t>* docids=line.getDocIds(it->doc_type); | |
for (vector<uint32_t>::const_iterator it2=docids->begin(),ite2=docids->end();it2!=ite2;++it2){ | |
DocPair pair(it->doc_type,*it2); | |
DocTally* tally=&results[pair]; | |
const bool notSearchDoc=(doctype-it->doc_type)|(docid-*it2); | |
uint64_t barrel=tally->previous; | |
const uint8_t previous=(barrel)&0xFF; | |
const uint8_t difference=current-previous; | |
barrel=((barrel&0xFFFFFFFFFFFFFF00)<<8)|(uint64_t(difference)<<8)|current; | |
tally->previous=barrel; | |
const bool notConsecutive=(barrel&0xFFFFFFFFFFFFFF00)-0x0101010101010100; | |
const bool isMatch=notSearchDoc&(!notConsecutive); | |
tally->count+=isMatch; | |
} | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment