Navigation Menu

Skip to content

fracek/indextank-clj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IndexTank-clj

Indextank API Library for Clojure.

How to use it

First thing first, define your private URL, you can find it in your dashboard

(def privurl "http://:r4and0m5tr1ng@asd.api.indextank.com")

INDEX MANAGEMENT

Now you can manage your indexes

(with-client privurl
    (indexes)                    ;; List all the indexes of the account
    (index-meta "myindex")       ;; Retrieves metadata of index "myindex"
    (create-index "blog")        ;; Create a new index
    (delete-index "myindex"))    ;; Remove the index "myindex"

INDEXING

You can add, update or delete documents from the index

(def first-post {:docid "p1" 
                 :fields {:title "Hello, World"
                          :text "my first post"}})
(def second-post {:docid "p2"
                  :fields {:title "Second post"
                           :text "Remember to subscribe"}})
(def third-post {:docid "p3"
                 :fields {:title "Third"
                          :text "I'm bored of this blog"}})
(def two-posts [second-post third-post])

(with-client privurl
    (add-document "blog" first-post) ;; Add one document
    (add-document "blog" two-posts)  ;; Add more documents at once
    (delete-document "blog" "p1"))   ;; Delete the doc with :docid "p1"

SCORING VARIABLES

You can add a scoring variable to your documents, document variables provide additional useful information to create more subtle and effective scoring functions.

(with-client privurl
    (score "blog" "p2" {"0" 100, "1" 2, "2" 3.5})) ;; 0 => likes
                                                   ;; 1 => Dislikes
                                                   ;; 2 => Average rating

CATEGORIES

You can add categories to your documents, that is like metadata associated with a document

(with-client privurl
    (categorize "blog" "p2" {"author" "G. Verga"}))

SCORING FUNCTIONS

Scoring functions can be used when searching the index to provide specific orderings for the results. You can read more about this functions on the official documentation.

(def new-function "-age * relevance")       ;; Define a new function

(with-client privurl
    (functions "blog")                      ;; List the functions of the index
    (define-function "blog" 1 new-function) ;; Add the function to
                                            ;; the index
    (delete-function "blog" 0))             ;; Remove the default
                                            ;; scoring function

SEARCHING

You can search your documents in the index. To learn more about the search refer to the documentation.

(def opts {:start 0 :len 20 :function 1})   ;; Define some search options
                                            ;; Start => for paginatin, first position to return
                                            ;; Len   => how many results
                                            ;; Function => the scoring function to sort results

(with-client privurl
    (search "blog" "text:subscribe")        ;; Search for 'subscribe in te text
    (search "blog" "text:subsribe" opts))   ;; Search with different options

PROMOTING RESULTS

You can promote a document to the top of a query's result page.

(with-client privurl
    (promote "blog" "p2" "subscribe"))       ;; When I will search for 'subscribe' 'p2' will be the first result

Known Issues

  • IndexTank-clj doesn't support all the searching options at the moment.

License

Copyright © 2011 Francesco Ceccon

Distributed under the Eclipse Public License, the same as Clojure. Please read the LICENSE file.

About

Indextank.com API Library for Clojure

Resources

License

Stars

Watchers

Forks

Packages

No packages published