* fixed non-ascii characters not working in normal symbol search * implemented support for non-ascii characters in fulltext search * fixed fulltext search not working for symbols with lowest and highest character codes in a file * using wstring in FullTextSearchIndex (causes this index to be dependent on text encoding selected in app settings) * implemented rebuilding FullTextSearchIndex if used text encoding changed in app settings * added utility lib
48 lines
969 B
C++
48 lines
969 B
C++
#include "data/fulltextsearch/FullTextSearchIndex.h"
|
|
#include <limits>
|
|
|
|
#include "utility/logging/logging.h"
|
|
#include "utility/tracing.h"
|
|
|
|
void FullTextSearchIndex::addFile(Id fileId, const std::wstring& file)
|
|
{
|
|
if( file.empty() )
|
|
{
|
|
LOG_ERROR("empty file not added to fulltextsearch index");
|
|
}
|
|
|
|
if ( file.size() >= std::numeric_limits<int>::max() )
|
|
{
|
|
LOG_ERROR("file too big not added to fulltextsearch index");
|
|
}
|
|
|
|
FullTextSearchFile fts_file(fileId, SuffixArray(file));
|
|
m_files.push_back(fts_file);
|
|
}
|
|
|
|
std::vector<FullTextSearchResult> FullTextSearchIndex::searchForTerm(const std::wstring& term) const
|
|
{
|
|
TRACE();
|
|
|
|
std::vector<FullTextSearchResult> ret;
|
|
FullTextSearchResult hit;
|
|
for (auto& f : m_files)
|
|
{
|
|
hit.fileId = f.fileId;
|
|
hit.positions = f.array.searchForTerm(term);
|
|
ret.push_back(hit);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
size_t FullTextSearchIndex::fileCount() const
|
|
{
|
|
return m_files.size();
|
|
}
|
|
|
|
void FullTextSearchIndex::clear()
|
|
{
|
|
m_files.clear();
|
|
}
|
|
|