Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
Information Retrieval
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gijs Hendriksen
Information Retrieval
Commits
df3bb8ca
Commit
df3bb8ca
authored
Nov 13, 2019
by
Gijs Hendriksen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement bulk index and index clearing
parent
f8f1c0a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
5 deletions
+33
-5
data.json
data.json
+10
-0
index.py
index.py
+11
-2
main.py
main.py
+12
-3
No files found.
data.json
0 → 100644
View file @
df3bb8ca
[
{
"name"
:
"doc1"
,
"body"
:
"I put on my robe and wizard hat"
},
{
"name"
:
"doc2"
,
"body"
:
"I put my wizard hat in the wizard closet"
}
]
index.py
View file @
df3bb8ca
import
duckdb
import
duckdb
import
json
import
os
import
os
from
collections
import
defaultdict
from
collections
import
defaultdict
...
@@ -73,8 +74,16 @@ class Index:
...
@@ -73,8 +74,16 @@ class Index:
self
.
cursor
.
execute
(
f"INSERT INTO terms VALUES (
{
term_id
}
,
{
doc_id
}
,
{
frequency
}
)"
)
self
.
cursor
.
execute
(
f"INSERT INTO terms VALUES (
{
term_id
}
,
{
doc_id
}
,
{
frequency
}
)"
)
def
bulk_index
(
self
,
filename
):
def
bulk_index
(
self
,
filename
):
# TODO read data from filename and index documents
with
open
(
filename
)
as
_file
:
pass
data
=
json
.
load
(
_file
)
for
document
in
data
:
self
.
index
(
document
)
def
clear
(
self
):
self
.
cursor
.
execute
(
"DELETE FROM terms"
)
self
.
cursor
.
execute
(
"DELETE FROM docs"
)
self
.
cursor
.
execute
(
"DELETE FROM dict"
)
def
print_index
(
self
):
def
print_index
(
self
):
print
(
'dict'
)
print
(
'dict'
)
...
...
main.py
View file @
df3bb8ca
...
@@ -6,6 +6,7 @@ from index import Index
...
@@ -6,6 +6,7 @@ from index import Index
def
bulk_index
(
index
,
args
):
def
bulk_index
(
index
,
args
):
filename
=
args
.
data
filename
=
args
.
data
index
.
bulk_index
(
filename
)
index
.
bulk_index
(
filename
)
index
.
print_index
()
def
query_index
(
index
,
args
):
def
query_index
(
index
,
args
):
...
@@ -13,6 +14,10 @@ def query_index(index, args):
...
@@ -13,6 +14,10 @@ def query_index(index, args):
# TODO use query terms to query index
# TODO use query terms to query index
def
clear_index
(
index
,
args
):
index
.
clear
()
def
main
():
def
main
():
parser
=
ArgumentParser
(
prog
=
'old_duck'
,
description
=
'OldDuck - A Python implementation of OldDog, using DuckDB'
)
parser
=
ArgumentParser
(
prog
=
'old_duck'
,
description
=
'OldDuck - A Python implementation of OldDog, using DuckDB'
)
...
@@ -21,12 +26,16 @@ def main():
...
@@ -21,12 +26,16 @@ def main():
parser_index
=
subparsers
.
add_parser
(
'index'
)
parser_index
=
subparsers
.
add_parser
(
'index'
)
parser_index
.
add_argument
(
'database'
,
help
=
'The database file to index the files to'
)
parser_index
.
add_argument
(
'database'
,
help
=
'The database file to index the files to'
)
parser_index
.
add_argument
(
'data'
,
help
=
'The file to read and index documents from'
)
parser_index
.
add_argument
(
'data'
,
help
=
'The file to read and index documents from'
)
parser
.
set_defaults
(
func
=
bulk_index
)
parser
_index
.
set_defaults
(
func
=
bulk_index
)
parser_query
=
subparsers
.
add_parser
(
'query'
)
parser_query
=
subparsers
.
add_parser
(
'query'
)
parser_query
.
add_argument
(
'database'
,
help
=
'The database file to
index the files to
'
)
parser_query
.
add_argument
(
'database'
,
help
=
'The database file to
query
'
)
parser_query
.
add_argument
(
'terms'
,
help
=
'The query terms'
,
nargs
=
'*'
)
parser_query
.
add_argument
(
'terms'
,
help
=
'The query terms'
,
nargs
=
'*'
)
parser
.
set_defaults
(
func
=
query_index
)
parser_query
.
set_defaults
(
func
=
query_index
)
parser_clear
=
subparsers
.
add_parser
(
'clear'
)
parser_clear
.
add_argument
(
'database'
,
help
=
'The database file to clear'
)
parser_clear
.
set_defaults
(
func
=
clear_index
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment