#include "concordia/index_searcher.hpp" #include "concordia/common/utils.hpp" #include "concordia/tokenized_sentence.hpp" #include IndexSearcher::IndexSearcher() { _concordiaSearcher = boost::shared_ptr( new ConcordiaSearcher()); } IndexSearcher::~IndexSearcher() { } std::vector IndexSearcher::simpleSearch( boost::shared_ptr hashGenerator, boost::shared_ptr > T, boost::shared_ptr > markers, boost::shared_ptr > SA, const std::string & pattern) throw(ConcordiaException) { std::vector result; int left; std::vector hash = hashGenerator->generateHash(pattern)->getCodes(); saidx_t patternLength = hash.size()*sizeof(INDEX_CHARACTER_TYPE); sauchar_t * patternArray = Utils::indexVectorToSaucharArray(hash); int size = sa_search(T->data(), (saidx_t) T->size(), (const sauchar_t *) patternArray, patternLength, SA->data(), (saidx_t) SA->size(), &left); for (int i = 0; i < size; ++i) { saidx_t resultPos = SA->at(left + i); if (resultPos % sizeof(INDEX_CHARACTER_TYPE) == 0) { // As we are looking for a pattern in an array of higher // resolution than the hashed index file, we might // obtain accidental results exceeding the boundaries // of characters in hashed index. The above check // removes these accidental results. saidx_t actualResultPos = resultPos / sizeof(INDEX_CHARACTER_TYPE); SUFFIX_MARKER_TYPE marker = markers->at(actualResultPos); result.push_back(MatchedPatternFragment( Utils::getIdFromMarker(marker), Utils::getOffsetFromMarker(marker), 0, hash.size())); } } delete[] patternArray; return result; } std::vector IndexSearcher::anubisSearch( boost::shared_ptr config, boost::shared_ptr hashGenerator, boost::shared_ptr > T, boost::shared_ptr > markers, boost::shared_ptr > SA, const std::string & pattern) throw(ConcordiaException) { std::vector hash = hashGenerator->generateHash(pattern)->getCodes(); return _concordiaSearcher->anubisSearch(config, T, markers, SA, hash); } boost::shared_ptr IndexSearcher::concordiaSearch( boost::shared_ptr hashGenerator, boost::shared_ptr > T, boost::shared_ptr > markers, boost::shared_ptr > SA, const std::string & pattern) throw(ConcordiaException) { boost::shared_ptr hashedPattern = hashGenerator->generateHash(pattern); boost::shared_ptr result = boost::shared_ptr( new ConcordiaSearchResult(hashedPattern)); _concordiaSearcher->concordiaSearch(result, T, markers, SA, hashedPattern->getCodes()); return result; }