Skip to content

Commit de73dba

Browse files
authored
Merge branch 'master' into custom_domain
2 parents 8788e10 + 9df5a52 commit de73dba

File tree

11 files changed

+517
-31
lines changed

11 files changed

+517
-31
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ services:
131131
132132
You can read more about [docker compose override files](https://docs.docker.com/compose/multiple-compose-files/merge/).
133133
134+
#### Enabling semantic search
135+
136+
To enable semantic search that uses text embeddings, run `./scripts/nlp-setup`.
137+
138+
Before running `./scripts/nlp-setup`, ensure the following are true:
139+
140+
- search is enabled in `COMPOSE_PROFILES`:
141+
142+
```.env
143+
COMPOSE_PROFILES=...,search,...
144+
```
145+
- The default opensearch index (default name=`item`) is created and done indexing. This should happen the first time you run `./sndev start`, but it may take a few minutes for indexing to complete.
146+
147+
After `nlp-setup` is done, restart your containers to enable semantic search:
148+
149+
```
150+
> ./sndev restart
151+
```
134152

135153

136154
<br>

api/paidAction/downZap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export async function onPaid ({ invoice, actId }, { tx }) {
6262
// denormalize downzaps
6363
await tx.$executeRaw`
6464
WITH territory AS (
65-
SELECT COALESCE(r."subName", i."subName", 'meta')::TEXT as "subName"
65+
SELECT COALESCE(r."subName", i."subName", 'meta')::CITEXT as "subName"
6666
FROM "Item" i
6767
LEFT JOIN "Item" r ON r.id = i."rootId"
6868
WHERE i.id = ${itemAct.itemId}::INTEGER

api/paidAction/zap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export async function onPaid ({ invoice, actIds }, { tx }) {
151151
// NOTE: for the rows that might be updated by a concurrent zap, we use UPDATE for implicit locking
152152
await tx.$queryRaw`
153153
WITH territory AS (
154-
SELECT COALESCE(r."subName", i."subName", 'meta')::TEXT as "subName"
154+
SELECT COALESCE(r."subName", i."subName", 'meta')::CITEXT as "subName"
155155
FROM "Item" i
156156
LEFT JOIN "Item" r ON r.id = i."rootId"
157157
WHERE i.id = ${itemAct.itemId}::INTEGER

api/resolvers/item.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
FULL_COMMENTS_THRESHOLD
1616
} from '@/lib/constants'
1717
import { msatsToSats } from '@/lib/format'
18-
import { parse } from 'tldts'
1918
import uu from 'url-unshort'
2019
import { actSchema, advSchema, bountySchema, commentSchema, discussionSchema, jobSchema, linkSchema, pollSchema, validateSchema } from '@/lib/validate'
2120
import { defaultCommentSort, isJob, deleteItemByAuthor } from '@/lib/item'
@@ -26,6 +25,7 @@ import assertApiKeyNotPermitted from './apiKey'
2625
import performPaidAction from '../paidAction'
2726
import { GqlAuthenticationError, GqlInputError } from '@/lib/error'
2827
import { verifyHmac } from './wallet'
28+
import { parse } from 'tldts'
2929

3030
function commentsOrderByClause (me, models, sort) {
3131
const sharedSortsArray = []
@@ -613,7 +613,6 @@ export default {
613613
const urlObj = new URL(ensureProtocol(url))
614614
let { hostname, pathname } = urlObj
615615

616-
// remove subdomain from hostname
617616
const parseResult = parse(urlObj.hostname)
618617
if (parseResult?.subdomain?.length > 0) {
619618
hostname = hostname.replace(`${parseResult.subdomain}.`, '')
@@ -639,6 +638,9 @@ export default {
639638
} else if (urlObj.hostname === 'yewtu.be') {
640639
const matches = url.match(/(https?:\/\/)?yewtu\.be.*(v=|embed\/)(?<id>[_0-9a-z-]+)/i)
641640
similar = `^(http(s)?:\\/\\/)?yewtu\\.be\\/(watch\\?v\\=|embed\\/)${matches?.groups?.id}&?`
641+
} else {
642+
// only allow ending of mismatching search params
643+
similar += '(?:\\?.*)?$'
642644
}
643645

644646
return await itemQueryWithMeta({

awards.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,10 @@ cointastical,issue,#1962,#1217,good-first-issue,,,,2k,???,???
205205
Scroogey-SN,pr,#1975,#1964,good-first-issue,,,,20k,Scroogey@coinos.io,2025-04-02
206206
rideandslide,issue,#1986,#1985,good-first-issue,,,,2k,koiora@getalby.com,2025-04-02
207207
kristapsk,issue,#1976,#841,good-first-issue,,,,2k,???,???
208+
ed-kung,pr,#2070,#2061,good-first-issue,,,,20k,simplestacker@getalby.com,???
209+
ed-kung,issue,#2070,#2061,good-first-issue,,,,2k,simplestacker@getalby.com,???
210+
ed-kung,pr,#2070,#2058,easy,,,,100k,simplestacker@getalby.com,???
211+
ed-kung,pr,#2070,#2047,medium-hard,,,,500k,simplestacker@getalby.com,???
212+
SouthKoreaLN,pr,#2068,#2064,good-first-issue,,,,20k,south_korea_ln@stacker.news,???
213+
kepford,issue,#2068,#2064,good-first-issue,,,,2k,???,???
214+
SouthKoreaLN,pr,#2069,#1990,good-first-issue,,,,20k,south_korea_ln@stacker.news,???

components/item-act.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import { useSendWallets } from '@/wallets/index'
1818
const defaultTips = [100, 1000, 10_000, 100_000]
1919

2020
const Tips = ({ setOValue }) => {
21-
const tips = [...getCustomTips(), ...defaultTips].sort((a, b) => a - b)
21+
const customTips = getCustomTips()
22+
const defaultNoCustom = defaultTips.filter(d => !customTips.includes(d))
23+
const tips = [...customTips, ...defaultNoCustom].slice(0, 7).sort((a, b) => a - b)
24+
2225
return tips.map((num, i) =>
2326
<Button
2427
size='sm'
@@ -37,11 +40,7 @@ const Tips = ({ setOValue }) => {
3740
const getCustomTips = () => JSON.parse(window.localStorage.getItem('custom-tips')) || []
3841

3942
const addCustomTip = (amount) => {
40-
if (defaultTips.includes(amount)) return
41-
let customTips = Array.from(new Set([amount, ...getCustomTips()]))
42-
if (customTips.length > 3) {
43-
customTips = customTips.slice(0, 3)
44-
}
43+
const customTips = Array.from(new Set([amount, ...getCustomTips()])).slice(0, 7)
4544
window.localStorage.setItem('custom-tips', JSON.stringify(customTips))
4645
}
4746

docker-compose.yml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,31 +176,16 @@ services:
176176
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD}
177177
- plugins.security.disabled=true
178178
- discovery.type=single-node
179+
- "_JAVA_OPTIONS=-Xms2g -Xmx2g -XX:UseSVE=0"
179180
ports:
180181
- 9200:9200 # REST API
181182
- 9600:9600 # Performance Analyzer
182183
volumes:
183184
- os:/usr/share/opensearch/data
185+
- ./docker/opensearch/init-opensearch.sh:/usr/share/opensearch/init-opensearch.sh
184186
labels:
185187
CONNECT: "localhost:9200"
186-
command: >
187-
bash -c '
188-
set -m
189-
/usr/share/opensearch/opensearch-docker-entrypoint.sh &
190-
until curl -sS "http://localhost:9200/_cat/health?h=status" -ku admin:${OPENSEARCH_INITIAL_ADMIN_PASSWORD} | grep -q "green\|yellow"; do
191-
echo "Waiting for OpenSearch to start..."
192-
sleep 1
193-
done
194-
echo "OpenSearch started."
195-
curl \
196-
-H "Content-Type: application/json" \
197-
-X PUT \
198-
-d '{"mappings":{"properties":{"text":{"type":"text","analyzer":"english","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"title":{"type":"text","analyzer":"english","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}}' \
199-
"http://localhost:9200/item" \
200-
-ku admin:${OPENSEARCH_INITIAL_ADMIN_PASSWORD}
201-
echo "OpenSearch index created."
202-
fg
203-
'
188+
command: ["bash", "/usr/share/opensearch/init-opensearch.sh"]
204189
cpu_shares: "${CPU_SHARES_LOW}"
205190
os-dashboard:
206191
image: opensearchproject/opensearch-dashboards:2.17.0

docker/opensearch/init-opensearch.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
set -m
4+
5+
/usr/share/opensearch/opensearch-docker-entrypoint.sh &
6+
7+
# ---- Wait for OpenSearch to start
8+
9+
until curl -sS "http://localhost:9200/_cat/health?h=status" -ku admin:${OPENSEARCH_INITIAL_ADMIN_PASSWORD} | grep -q "green\|yellow"; do
10+
echo "Waiting for OpenSearch to start..."
11+
sleep 1
12+
done
13+
14+
# ---- If index doesn't exist, create it with default settings
15+
16+
index_exists=$(curl -s -o /dev/null -w "%{http_code}" -I "http://localhost:9200/$OPENSEARCH_INDEX")
17+
18+
if [ "$index_exists" -eq 200 ]; then
19+
echo "OpenSearch index $OPENSEARCH_INDEX already exists."
20+
else
21+
curl \
22+
-H "Content-Type: application/json" \
23+
-X PUT \
24+
-d '{
25+
"mappings": {
26+
"properties": {
27+
"text": {
28+
"type": "text",
29+
"analyzer": "english",
30+
"fields": {"keyword":{"type":"keyword","ignore_above":256}}
31+
},
32+
"title": {
33+
"type": "text",
34+
"analyzer": "english",
35+
"fields": {"keyword":{"type":"keyword","ignore_above":256}}
36+
}}}}' \
37+
"http://localhost:9200/$OPENSEARCH_INDEX" \
38+
-ku admin:${OPENSEARCH_INITIAL_ADMIN_PASSWORD}
39+
echo ""
40+
echo "OpenSearch index $OPENSEARCH_INDEX created."
41+
fi
42+
43+
fg

docs/dev/semantic-search.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1-
Getting semantic search setup in OpenSearch is currently a multistep, manual process. To configure semantic search, enter the following commands into OpenSearch's REST API. You can do this in Dev Tools in the OpenSearch Dashboard (after starting your SN dev environment, point your browser to localhost:5601). You can also use CURL to send these commands to localhost:9200.
1+
## Automated setup
2+
3+
To enable semantic search that uses text embeddings, run `./scripts/nlp-setup`.
4+
5+
Before running `./scripts/nlp-setup`, ensure the following are true:
6+
7+
- search is enabled in `COMPOSE_PROFILES`:
8+
9+
```.env
10+
COMPOSE_PROFILES=...,search,...
11+
```
12+
- The default opensearch index (default name=`item`) is created and done indexing. This should happen the first time you run `./sndev start`, but it may take a few minutes for indexing to complete.
13+
14+
After `nlp-setup` is done, restart your containers to enable semantic search:
15+
16+
```
17+
> ./sndev restart
18+
```
19+
20+
21+
## Manual setup
22+
23+
You can also set up and configure semantic search manually. To do so, enter the following commands into OpenSearch's REST API. You can do this in Dev Tools in the OpenSearch Dashboard (after starting your SN dev environment, point your browser to localhost:5601). You can also use CURL to send these commands to localhost:9200.
224
325
### step 1: configure the ml plugin
426
```json

0 commit comments

Comments
 (0)