Liking cljdoc? Tell your friends :D

Lucene

Lucene module for Crux making use of Apache Lucene.

Note: This module is in alpha and likely to change.

Setup

crux-lucene runs in-process as part of the Crux node as a Crux module.

First, add the crux-lucene dependency to your project:

deps.edn
juxt/crux-lucene {:mvn/version "{crux_version}-alpha"}
pom.xml
<dependency>
    <groupId>juxt</groupId>
    <artifactId>crux-lucene</artifactId>
    <version>{crux_version}-alpha</version>
</dependency>

Add the following to your node configuration:

JSON
{
  "crux.lucene/lucene-store": {
        "db-dir": "lucene",
  }
}
Clojure
{...
 :crux.lucene/lucene-store {:db-dir "lucene-dir"}}
EDN
{...
 :crux.lucene/lucene-store {:db-dir "lucene-dir"}}

Querying

All text fields in a document will be automatically indexed. You can then you use the in-built text-search fn in your datalog:

{:find '[?e]
 :where '[[(text-search :name "Ivan") [[?e]]]
 [?e :crux.db/id]]}

The destructuring available is entity-id, matched-value and score. For example, to return the full search results tuple:

{:find '[?e ?v ?s]
 :where '[[(text-search :name "Ivan") [[?e ?v ?s]]]
 [?e :crux.db/id]]}

You can use standard Lucene search capabilities:

{:find '[?e]
 :where '[[(text-search :name "Iva*") [[?e]]]
 [?e :crux.db/id]]}

Will return all entities that with a :name that starts with "Iva". See the Lucene documentation for more information.

You can search across all attributes:

{:find '[?e ?v ?a ?s]
 :where '[[(wildcard-text-search "Iva*") [[?e ?v ?a ?s]]]
 [?e :crux.db/id]]}

Will return all entities that have an attribute with a value that matches "Iva". The destructured binding also contains a which is the attribute.

Can you improve this documentation? These fine people already did:
User & Dan Mason
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close