Skip to content

Commit

Permalink
fix date
Browse files Browse the repository at this point in the history
  • Loading branch information
capjamesg committed Oct 18, 2024
1 parent 9296969 commit a69a049
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
14 changes: 7 additions & 7 deletions jamesql/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ def _create_reverse_index(
else:
self.tf_idf[word][score] = [document["uuid"]]

for w in document[index_by].split(" "):
if self.reverse_tf_idf[w].get(index_by) is None:
self.reverse_tf_idf[w][index_by] = {}
for w in document[index_by].split(" "):
if self.reverse_tf_idf[w].get(index_by) is None:
self.reverse_tf_idf[w][index_by] = {}

self.reverse_tf_idf[w][index_by][document["uuid"]] = score
self.reverse_tf_idf[w][index_by][document["uuid"]] = score

if self.reverse_tf_idf[w.lower()].get(index_by) is None:
self.reverse_tf_idf[w.lower()][index_by] = {}
if self.reverse_tf_idf[w.lower()].get(index_by) is None:
self.reverse_tf_idf[w.lower()][index_by] = {}

self.reverse_tf_idf[w.lower()][index_by][document["uuid"]] = score
self.reverse_tf_idf[w.lower()][index_by][document["uuid"]] = score

return index

Expand Down
2 changes: 1 addition & 1 deletion jamesql/script_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def start(self, items):
def decay(self, items):
# decay by half for every 30 days
# item is datetime.dateime object
days_since_post = (datetime.datetime.now() - items[0]).days
days_since_post = (datetime.datetime.now() - datetime.datetime.strptime(items[0], "%Y-%m-%dT%H:%M:%S")).days

return 0.9 ** (days_since_post / 30)

Expand Down
3 changes: 3 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ def test_search(
assert float(response["query_time"]) < 0.06


# TODO: TF/IDF needs to be calculated after all documents have been inserted
# Otherwise TF/IDF score will vary on document insertion order
# which we don't want
@pytest.mark.parametrize(
"query, top_document_name, top_document_score, raises_exception",
[
Expand Down

0 comments on commit a69a049

Please sign in to comment.