Skip to content

Commit d2f1fb0

Browse files
committed
feat: add by similarity
1 parent 3d08c81 commit d2f1fb0

File tree

8 files changed

+144
-79
lines changed

8 files changed

+144
-79
lines changed

Dockerfile

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ WORKDIR /data
2626
COPY --from=builder /app/main /app/main
2727

2828
ARG UNCONDITIONAL_API_SOURCE_REPO
29-
ARG UNCONDITIONAL_API_SOURCE_CLIENT_KEY
30-
ARG UNCONDITIONAL_API_FEED_REPO_HOST
31-
ARG UNCONDITIONAL_API_FEED_REPO_KEY
29+
ARG UNCONDITIONAL_API_FEED_REPO_INDEX
3230
ARG UNCONDITIONAL_API_LOG_ENV
3331

3432
ENV UNCONDITIONAL_API_SOURCE_REPO=${UNCONDITIONAL_API_SOURCE_REPO}
35-
ENV UNCONDITIONAL_API_SOURCE_CLIENT_KEY=${UNCONDITIONAL_API_SOURCE_CLIENT_KEY}
36-
ENV UNCONDITIONAL_API_FEED_REPO_HOST=${UNCONDITIONAL_API_FEED_REPO_HOST}
37-
ENV UNCONDITIONAL_API_FEED_REPO_KEY=${UNCONDITIONAL_API_FEED_REPO_KEY}
33+
ENV UNCONDITIONAL_API_FEED_REPO_INDEX=${UNCONDITIONAL_API_FEED_REPO_INDEX}
3834
ENV UNCONDITIONAL_API_LOG_ENV=${UNCONDITIONAL_API_LOG_ENV}
3935

40-
RUN /app/main index create --name feeds \
41-
--feed-repo-key="${UNCONDITIONAL_API_FEED_REPO_KEY}" \
42-
--feed-repo-host="${UNCONDITIONAL_API_FEED_REPO_HOST}"
36+
RUN --mount=type=secret,id=UNCONDITIONAL_API_SOURCE_CLIENT_KEY \
37+
--mount=type=secret,id=UNCONDITIONAL_API_FEED_REPO_HOST \
38+
--mount=type=secret,id=UNCONDITIONAL_API_FEED_REPO_KEY \
39+
UNCONDITIONAL_API_SOURCE_CLIENT_KEY="$(cat /run/secrets/UNCONDITIONAL_API_SOURCE_CLIENT_KEY)" \
40+
UNCONDITIONAL_API_FEED_REPO_HOST="$(cat /run/secrets/UNCONDITIONAL_API_FEED_REPO_HOST)" \
41+
UNCONDITIONAL_API_FEED_REPO_KEY="$(cat /run/secrets/UNCONDITIONAL_API_FEED_REPO_KEY)" \
42+
/app/main index create --name feeds
4343

4444
FROM scratch as release
4545
COPY --from=certificator /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
@@ -50,18 +50,14 @@ ARG UNCONDITIONAL_API_ADDRESS
5050
ARG UNCONDITIONAL_API_ALLOWED_ORIGINS
5151
ARG UNCONDITIONAL_API_PORT
5252
ARG UNCONDITIONAL_API_SOURCE_REPO
53-
ARG UNCONDITIONAL_API_SOURCE_CLIENT_KEY
5453
ARG UNCONDITIONAL_API_LOG_ENV
55-
ARG UNCONDITIONAL_API_FEED_REPO_HOST
56-
ARG UNCONDITIONAL_API_FEED_REPO_KEY
54+
ARG UNCONDITIONAL_API_FEED_REPO_INDEX
5755

5856
ENV UNCONDITIONAL_API_ADDRESS=${UNCONDITIONAL_API_ADDRESS}
5957
ENV UNCONDITIONAL_API_ALLOWED_ORIGINS=${UNCONDITIONAL_API_ALLOWED_ORIGINS}
6058
ENV UNCONDITIONAL_API_PORT=${UNCONDITIONAL_API_PORT}
6159
ENV UNCONDITIONAL_API_SOURCE_REPO=${UNCONDITIONAL_API_SOURCE_REPO}
62-
ENV UNCONDITIONAL_API_SOURCE_CLIENT_KEY=${UNCONDITIONAL_API_SOURCE_CLIENT_KEY}
6360
ENV UNCONDITIONAL_API_LOG_ENV=${UNCONDITIONAL_API_LOG_ENV}
64-
ENV UNCONDITIONAL_API_FEED_REPO_HOST=${UNCONDITIONAL_API_FEED_REPO_HOST}
65-
ENV UNCONDITIONAL_API_FEED_REPO_KEY=${UNCONDITIONAL_API_FEED_REPO_KEY}
61+
ENV UNCONDITIONAL_API_FEED_REPO_INDEX=${UNCONDITIONAL_API_FEED_REPO_INDEX}
6662

6763
ENTRYPOINT ["./app/main","serve", "--address", "0.0.0.0", "--port","8080","--feed-repo-index","feeds"]

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ test-integration:
5656
build:
5757
@go build --tags=release -o ${_PROJECT_DIRECTORY}/bin/unconditional-server
5858

59+
.PHONY: deploy
60+
61+
deploy:
62+
@sh ./scripts/deploy.sh
63+
5964
# Helpers
6065
check-variable-%: # detection of undefined variables.
6166
@[[ "${${*}}" ]] || (echo '*** Please define variable `${*}` ***' && exit 1)

api/api.gen.go

Lines changed: 32 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/swagger.yaml

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,85 @@
11
openapi: 3.0.2
22
x-stoplight:
3-
id: 44w9u0405b53e
3+
id: g0km90jnbo4i0
44
info:
55
title: Unconditional
6-
version: "1.0"
6+
version: '1.0'
77
servers:
8-
- url: "https://api.unconditional.day/v1"
9-
- url: "http://localhost:8080"
10-
- url: "127.0.0.1:8080"
8+
- url: 'https://api.unconditional.day/v1'
9+
- url: 'http://localhost:8080'
10+
- url: '127.0.0.1:8080'
1111
paths:
12-
"/v1/search/feed/{query}":
12+
'/v1/search/feed/{query}':
1313
get:
1414
responses:
15-
"200":
15+
'200':
1616
description: OK
1717
content:
1818
application/json:
1919
schema:
2020
type: array
2121
items:
22-
$ref: "#/components/schemas/FeedItem"
23-
"500":
22+
$ref: '#/components/schemas/FeedItem'
23+
'500':
2424
description: Internal Server Error
2525
content:
2626
application/json:
2727
schema:
2828
type: object
29-
$ref: "#/components/schemas/Error"
30-
parameters:
31-
- name: query
32-
in: path
33-
required: true
34-
schema:
35-
type: string
29+
$ref: '#/components/schemas/Error'
3630
x-stoplight:
37-
id: wosl2fd4xhhrd
38-
"/v1/search/context/{query}":
31+
id: e6uenhk2m21k5
32+
parameters:
33+
- schema:
34+
type: boolean
35+
in: query
36+
name: bySimilarity
37+
parameters:
38+
- schema:
39+
type: string
40+
name: query
41+
in: path
42+
required: true
43+
'/v1/search/context/{query}':
3944
get:
4045
responses:
41-
"200":
46+
'200':
4247
description: OK
4348
content:
4449
application/json:
4550
schema:
4651
type: object
47-
$ref: "#/components/schemas/SearchContextDetails"
48-
"500":
52+
$ref: '#/components/schemas/SearchContextDetails'
53+
'500':
4954
description: Internal Server Error
5055
content:
5156
application/json:
5257
schema:
5358
type: object
54-
$ref: "#/components/schemas/Error"
59+
$ref: '#/components/schemas/Error'
5560
parameters:
5661
- name: query
5762
in: path
5863
required: true
5964
schema:
6065
type: string
6166
x-stoplight:
62-
id: idoe8qr80ebxd
63-
"/v1/version":
67+
id: 7c394v6kr5tff
68+
/v1/version:
6469
get:
6570
summary: Your GET endpoint
6671
tags: []
6772
responses:
68-
"200":
73+
'200':
6974
description: OK
7075
content:
7176
application/json:
7277
schema:
7378
type: object
74-
$ref: "#/components/schemas/ServerVersion"
79+
$ref: '#/components/schemas/ServerVersion'
7580
operationId: get-v1-version
7681
x-stoplight:
77-
id: q4lvzczpgn9wh
82+
id: oucep4v9ubq2z
7883
requestBody:
7984
content:
8085
application/json:
@@ -98,7 +103,7 @@ components:
98103
type: string
99104
image:
100105
type: object
101-
$ref: "#/components/schemas/FeedImage"
106+
$ref: '#/components/schemas/FeedImage'
102107
date:
103108
type: string
104109
format: date-time
@@ -110,7 +115,7 @@ components:
110115
- language
111116
- date
112117
x-stoplight:
113-
id: xa4xmb6bpguaf
118+
id: kwewfmf4xgq3e
114119
FeedImage:
115120
type: object
116121
properties:
@@ -122,11 +127,11 @@ components:
122127
- url
123128
- title
124129
x-stoplight:
125-
id: cmmybtqamyqiy
130+
id: albynchitcqzu
126131
SearchContextDetails:
127132
type: object
128133
x-stoplight:
129-
id: 2bea7d1686f73
134+
id: fhfrlaebk9ask
130135
properties:
131136
title:
132137
type: string
@@ -156,51 +161,51 @@ components:
156161
- message
157162
- code
158163
x-stoplight:
159-
id: ugjrjhvkdmen2
164+
id: mffsjrkb81ot5
160165
ServerVersion:
161166
title: ServerVersion
162167
x-stoplight:
163-
id: 24qo1fm939bg5
168+
id: 4m4ndcimoercb
164169
type: object
165170
properties:
166171
source:
167-
$ref: "#/components/schemas/SourceReleaseVersion"
172+
$ref: '#/components/schemas/SourceReleaseVersion'
168173
build:
169-
$ref: "#/components/schemas/ServerBuildVersion"
174+
$ref: '#/components/schemas/ServerBuildVersion'
170175
required:
171176
- source
172177
- build
173178
SourceReleaseVersion:
174179
title: SourceReleaseVersion
175180
x-stoplight:
176-
id: ufsclw4vu3qp5
181+
id: qrni9cae7qsr6
177182
type: object
178183
properties:
179184
version:
180185
type: string
181186
x-stoplight:
182-
id: t6xp7ev3nprdj
187+
id: g42kpmf59e9sb
183188
lastUpdatedAt:
184189
type: string
185190
x-stoplight:
186-
id: 26hfi8gtj9bdi
191+
id: ozgly07pllzwb
187192
required:
188193
- version
189194
- lastUpdatedAt
190195
ServerBuildVersion:
191196
title: ServerBuildVersion
192197
x-stoplight:
193-
id: p7byzats6s3zt
198+
id: a6g4vsjso6ozw
194199
type: object
195200
properties:
196201
commit:
197202
type: string
198203
x-stoplight:
199-
id: eoik296b0ddt3
204+
id: 48tl37vuwu47p
200205
version:
201206
type: string
202207
x-stoplight:
203-
id: jup15zjavkg3a
208+
id: mwqxrg5t0vvst
204209
required:
205210
- commit
206211
- version

internal/app/feed.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
type FeedRepository interface {
88
// Search returns the results of a search query.
99
Find(query string) ([]Feed, error)
10+
// Search returns the results of a search query by similarity.
11+
FindBySimilarity(query string) ([]Feed, error)
1012
// Index indexes a document.
1113
Save(doc Feed) error
1214
// Update a document in index.

0 commit comments

Comments
 (0)