Common lisp Montezuma
Montezuma is a full-text indexing/search engine library written entirely in Common Lisp.
https://code.google.com/archive/p/montezuma/
I have read some tutorials about montezuma and I want to show some simple examples.
We can get it by quicklisp:
CL-USER> (ql:quickload "montezuma")
To load "montezuma":
Load 1 ASDF system:
montezuma
; Loading "montezuma"
("montezuma")
CL-USER>
Now we are going to use montezuma
Creating an index
a) To create an in-memory index
(defparameter *index* (make-instance 'montezuma:index))
b) To create a persistent index
(defparameter *index* (make-instance 'montezuma:index :path "/tmp/index"))
Adding Documents
To add a document you can simply add a string or with some fields.
- (montezuma:add-document-to-index *index* "My example")
- (montezuma:add-document-to-index *index* '(("fruits" . "Apples")
("content" . "Red apple")))
We are going to add another record.
(montezuma:add-document-to-index *index* '(("fruits" . "Apples")
("content" . "green apple")))
finally into REPL
CL-USER> (montezuma:add-document-to-index *index* "My example")
NIL
CL-USER> (montezuma:add-document-to-index *index* '(("fruits" . "Apples")
("content" . "Red apple")))
NIL
CL-USER> (montezuma:add-document-to-index *index* '(("fruits" . "Apples")
("content" . "green apple")))
NIL
CL-USER>
Get the size of the *index*
CL-USER> (montezuma:size *index*)
3
Searching
Now that we have data in our index, how do we actually use this index to search the data? The index class offers two search methods, search and search-each.
CL-USER> (montezuma:search-each *index* "content:\"red apple\""
#'(lambda (doc score)
(format t "content value: ~a~%" (montezuma:document-value (montezuma:get-document *index* doc) "content"))
(format t "doc-number: ~a score: ~a ~%" doc score)) )
content value: Red apple
doc-number: 1 score: 1.5034157
1
Another example
CL-USER> (montezuma:search-each *index* "content:\"apple\""
#'(lambda (doc score)
(format t "content value: ~a~%" (montezuma:document-value (montezuma:get-document *index* doc) "content"))
(format t "doc-number: ~a score: ~a ~%" doc score)) )
content value: Red apple
doc-number: 1 score: 0.625
content value: green apple
doc-number: 2 score: 0.625
2
Delete a document
CL-USER> (montezuma:delete-document *index* 1)
T
#lisp #montezuma #full-text #indexing