-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvertedIndex.cpp
More file actions
31 lines (27 loc) · 1.03 KB
/
invertedIndex.cpp
File metadata and controls
31 lines (27 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef INVERTED_INDEX_H // Include guard
#define INVERTED_INDEX_H
#include <bits/stdc++.h>
#include <boost/algorithm/string.hpp>
#include "trieAutoSuggestion.cpp"
#include <thread>
using namespace std;
using namespace boost::algorithm;
unordered_map<string,unordered_map<int, int>> invertedIndex; // to store word occurrences in documents
void buildTree(vector<string>&tokens,int docNumber)
{
for (int i = 0; i < tokens.size(); i++) {
string temp=tokens[i];
to_lower(temp);
invertedIndex[temp][docNumber]++;
}
}
void buildInvertedIndex(vector<string> &tokens, int docNumber) {
thread work1(buildTree,std::ref(tokens),docNumber);//used this thread to actually build the inverted index
thread work2(insertIntoTrie,std::ref(tokens));//Now use this thred to actually insert into trie;
work1.join();
work2.join();
}
unordered_map<string, unordered_map<int, int>> index() {//this function return the formed invertedIndex wherever needed for eg:- in query
return invertedIndex;
}
#endif // INVERTED_INDEX_H