Skip to content

Commit

Permalink
bump versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyson committed Jan 26, 2025
1 parent fac17da commit 209a1f9
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@ jobs:

- name: Post test coverage to Coveralls
run: mix coveralls.github --only ${{ matrix.typesense }}:true --trace
if: ${{ matrix.lint }}
if: ${{ matrix.lint && github.ref == 'refs/heads/main' }}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## major.minor.patch (yyyy.mm.dd)

## 1.0.1 (2025.01.26)

### Changed

* Bump dependency version.
* README banner image

## 1.0.0 (2025.01.19)

### Added
Expand Down
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# ExTypesense

<p align="center">
<img
alt="Typesense logo"
src="https://github.com/typesense/typesense/raw/main/assets/typesense_logo.svg"
width="298">
width="180">
<img
alt="lightning bolt svg"
height="40"
src="https://github.com/jaeyson/ex_typesense/raw/main/assets/lightning-bolt.svg"
width="200">
width="40">
<source
media="(prefers-color-scheme: dark)"
srcset="https://github.com/elixir-lang/elixir-lang.github.com/raw/main/images/logo/logo-dark.png">
<img
alt="Elixir logo"
src="https://github.com/elixir-lang/elixir-lang.github.com/raw/main/images/logo/logo.png"
width="200">
width="130">
</p>

<h1 align="center">ExTypesense</h1>

<p align="center">
<a href="https://hex.pm/packages/ex_typesense">
<img
Expand All @@ -37,12 +38,6 @@
src="https://github.com/jaeyson/ex_typesense/actions/workflows/ci.yml/badge.svg"
>
</a>
<a href="https://hexdocs.pm/ex_typesense/license.html">
<img
alt="ex_typesense license badge"
src="https://img.shields.io/hexpm/l/ex_typesense"
>
</a>
<a href="https://typesense.org/docs/27.1/api">
<img
alt="Latest Typesense version compatible badge"
Expand All @@ -55,6 +50,18 @@
src="https://coveralls.io/repos/github/jaeyson/ex_typesense/badge.svg?branch=main"
>
</a>
<a href="https://app.codacy.com/gh/jaeyson/ex_typesense/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade">
<img
alt="Codacy Badge"
src="https://app.codacy.com/project/badge/Grade/24302e4486f74e498ff0a2b67e3a1f59"
>
</a>
<a href="https://codescene.io/projects/63244">
<img
alt="CodeScene Average Code Health"
src="https://codescene.io/projects/63244/status-badges/average-code-health"
>
</a>
</p>

[Typesense](https://typesense.org) client for [Elixir](https://elixir-lang.org) with support for your Ecto schemas.
Expand Down
182 changes: 118 additions & 64 deletions guides/cheatsheet.cheatmd
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Cheatsheet Guide
# Cheatsheet Example

## Collections

{: .col-2}

### Create using schema
### 1. Create using schema

```elixir
# edit your Ecto schema
defmodule MyApp.Listings.Company do
use Ecto.Schema
@behaviour ExTypesense
Expand All @@ -32,9 +31,11 @@ defmodule MyApp.Listings.Company do

@impl ExTypesense
def get_field_types do
primary_field = __MODULE__.__schema__(:source) <> "_id"
name = __MODULE__.__schema__(:source)
primary_field = name <> "_id"

%{
name: name,
default_sorting_field: primary_field,
fields: [
%{name: primary_field, type: "int32"},
Expand All @@ -44,8 +45,11 @@ defmodule MyApp.Listings.Company do
}
end
end
```

### 2. Create the collection in `iex -S mix` shell

# then try this on iex -S mix
```elixir
iex> ExTypesense.create_collection(Company)
{:ok,
%OpenApiTypesense.CollectionResponse{
Expand All @@ -59,7 +63,6 @@ iex> ExTypesense.create_collection(Company)
}
}
```
{: .wrap}

### Create using map

Expand Down Expand Up @@ -88,14 +91,54 @@ iex> ExTypesense.create_collection(schema)
}
}
```
{: .wrap}

##

{: .col-2}

### List collections

```elixir
iex> ExTypesense.list_collections()
{:ok, []}
```

### Clone collections

```elixir
iex> ExTypesense.clone_collection("companies", "new_companies")
{:ok,
%OpenApiTypesense.CollectionResponse{
created_at: 1234567890,
default_sorting_field: "companies_id",
fields: [...],
name: "new_companies",
num_documents: 0,
symbols_to_index: [],
token_separators: []
}
}
```

### Get collection

```elixir
iex> ExTypesense.get_collection(MyApp.Context.Company)
{
:ok,
%OpenApiTypesense.CollectionResponse{
name: "companies",
fields: [...],
default_sorting_field: "company_id",
created_at: 1737896943,
enable_nested_fields: false,
num_documents: 0,
symbols_to_index: [],
token_separators: [],
voice_query_model: nil
}
}
```
{: .wrap}

### Update a collection

Expand All @@ -118,12 +161,54 @@ iex> ExTypesense.update_collection_fields("companies", schema)
}
}
```
{: .wrap}

### Drop a collection

```elixir
iex> ExTypesense.drop_collection(MyApp.Context.Company)

iex> ExTypesense.drop_collection("companies")
{
:ok,
%OpenApiTypesense.CollectionResponse{
name: "companies",
fields: [...],
default_sorting_field: "company_id",
created_at: 1737895283,
enable_nested_fields: false,
num_documents: 0,
symbols_to_index: [],
token_separators: [],
voice_query_model: nil
}
}
```

## Documents

{: .col-2}

### Indexes multiple documents with Ecto structs

```elixir
iex> posts = Post |> Repo.all()
iex> ExTypesense.import_documents(Post, posts)

{:ok, [%{"success" => true}, %{"success" => true}]}
```

### Delete a document by query

```elixir
iex> opts = [
...> filter_by: "num_employees:>100",
...> batch_size: 100
...> ]

iex> ExTypesense.delete_documents_by_query(Employee, opts)
{:ok, %OpenApiTypesense.Documents{num_deleted: 1}}
```

### Index a document using map

```elixir
Expand All @@ -133,15 +218,11 @@ iex> document = %{
...> companies_id: 1001,
...> country: "US"
...> }

iex> ExTypesense.index_document(document)
{:ok,
%{
id: "0",
collection_name: "companies",
company_name: "Malwart",
companies_id: 1001,
country: "US"
...
}
}
```
Expand All @@ -150,19 +231,36 @@ iex> ExTypesense.index_document(document)

```elixir
iex> post = Post |> limit(1) |> Repo.one()

iex> ExTypesense.index_document(post, :create)
{:ok,
%{
id: "12",
posts_id: 12,
title: "the quick brown fox",
collection_name: "posts"
...
}
}
```

### Update a document
### Indexes multiple documents with maps

```elixir
iex> documents = [
...> %{
...> company_name: "Industrial Mills, Co.",
...> doc_companies_id: 990,
...> country: "US"
...> },
...> %{
...> company_name: "Washing Machine, Inc.",
...> doc_companies_id: 10,
...> country: "US"
...> }
...> ]

iex> ExTypesense.import_documents("companies", documents)
{:ok, [%{"success" => true}, %{"success" => true}]}
```

### update using Ecto struct

```elixir
iex> post = Post |> limit(1) |> Repo.one()
Expand All @@ -179,11 +277,10 @@ iex> ExTypesense.update_document(post, 0)
}
```


### Delete a document

```elixir
iex> ExTypesense.delete_document(Post, 0)

{:ok,
%{
id: "0",
Expand All @@ -195,49 +292,6 @@ iex> ExTypesense.delete_document(Post, 0)
}
```

{: .wrap}

### Delete a document by query

```elixir
iex> opts = [
...> filter_by: "num_employees:>100",
...> batch_size: 100
...> ]

iex> ExTypesense.delete_documents_by_query(Employee, opts)
{:ok, %OpenApiTypesense.Documents{num_deleted: 1}}
```

### Indexes multiple documents with maps

```elixir
iex> documents = [
...> %{
...> company_name: "Industrial Mills, Co.",
...> doc_companies_id: 990,
...> country: "US"
...> },
...> %{
...> company_name: "Washing Machine, Inc.",
...> doc_companies_id: 10,
...> country: "US"
...> }
...> ]

iex> ExTypesense.import_documents("companies", documents)
{:ok, [%{"success" => true}, %{"success" => true}]}
```

### Indexes multiple documents with Ecto structs

```elixir
iex> posts = Post |> Repo.all()

iex> ExTypesense.import_documents(Post, posts)
{:ok, [%{"success" => true}, %{"success" => true}]}
```

## How to use search

{: .col-2}
Expand Down
6 changes: 3 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule ExTypesense.MixProject do
use Mix.Project

@source_url "https://github.com/jaeyson/ex_typesense"
@version "1.0.0"
@version "1.0.1"

def project do
[
Expand Down Expand Up @@ -40,7 +40,7 @@ defmodule ExTypesense.MixProject do
{:ex_doc, "~> 0.34", only: [:dev, :test], runtime: false},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:ecto, "~> 3.12", optional: true},
{:excoveralls, "~> 0.18", only: :test},
{:excoveralls, "~> 0.18", only: :test, runtime: false},
{:mix_audit, "~> 2.1", only: :test, runtime: false},
{:open_api_typesense, "~> 0.6"}
]
Expand All @@ -61,7 +61,7 @@ defmodule ExTypesense.MixProject do
],
extras: [
"CHANGELOG.md",
"README.md": [title: "Overview"],
"README.md",
"guides/running_local_typesense.md": [title: "Running local Typesense"],
"guides/cheatsheet.cheatmd": [title: "Cheatsheet"],
"LICENSE.md": [title: "License"],
Expand Down
Loading

0 comments on commit 209a1f9

Please sign in to comment.