Add count of times word appears on a site to index.

This commit is contained in:
rmgr 2023-11-30 08:03:43 +10:30
parent f36ab2fbfb
commit d30397cefa
3 changed files with 12 additions and 3 deletions

Binary file not shown.

View file

@ -23,9 +23,17 @@ def build_index():
if not word in ignored_words: if not word in ignored_words:
if not word in dictionary: if not word in dictionary:
dictionary[word] = [] dictionary[word] = []
if not url.strip() in dictionary[word]: matching_urls = list(filter(lambda entry: entry["url"] == url.strip(), dictionary[word]))
dictionary[word].append(url.strip()) if len(matching_urls) == 0:
# if not url.strip() in dictionary[word]:
entries = dictionary[word]
entry = {"url": url.strip(), "count": 1}
dictionary[word].append(entry)
else:
entries = dictionary[word]
entry = matching_urls[0]
entry["count"] += 1
entries.sort(reverse=True, key=lambda entry: entry["count"])
index.write(json.dumps(dictionary)) index.write(json.dumps(dictionary))
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -18,6 +18,7 @@ def search(query):
q = q.lower() q = q.lower()
if q in index: if q in index:
result.append(index[q]) result.append(index[q])
# result.sort(reverse= True,key=lambda entry: int(entry.count))
print(result) print(result)
return result return result