Add count of times word appears on a site to index.
This commit is contained in:
parent
f36ab2fbfb
commit
d30397cefa
3 changed files with 12 additions and 3 deletions
BIN
src/__pycache__/search.cpython-310.pyc
Normal file
BIN
src/__pycache__/search.cpython-310.pyc
Normal file
Binary file not shown.
14
src/index.py
14
src/index.py
|
|
@ -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__":
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue