Skip to content

Commit 181e0a7

Browse files
committed
Allow phonetic search to be toggled in repo UI
1 parent c9a665a commit 181e0a7

File tree

6 files changed

+81
-10
lines changed

6 files changed

+81
-10
lines changed

api/src/common/elastic-index.js

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export async function indexItem({ location = "workspace", configuration, item, c
6161
tokenizer: "standard",
6262
filter: [
6363
"lowercase",
64-
"synonym_filter",
6564
"nyingarn-phonetic"
6665
]
6766
},

api/src/routes/repository.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,22 @@ async function postRepositorySearchHandler(req) {
137137
);
138138
}
139139
if (req.body.text) {
140+
let textQueries = [];
141+
textQueries.push(
142+
esb.matchQuery("name", req.body.text).fuzziness("AUTO"),
143+
esb.matchQuery("description", req.body.text).fuzziness("AUTO"),
144+
);
145+
if (req.body.is_phonetic) {
146+
textQueries.push(
147+
esb.matchQuery("phoneticText", req.body.text).fuzziness("AUTO"),
148+
);
149+
} else {
150+
textQueries.push(
151+
esb.matchQuery("text", req.body.text).fuzziness("AUTO"),
152+
);
153+
}
140154
mustMatchQuery.push(
141-
esb
142-
.boolQuery()
143-
.should([
144-
esb.matchQuery("name", req.body.text).fuzziness("AUTO"),
145-
esb.matchQuery("description", req.body.text).fuzziness("AUTO"),
146-
esb.matchQuery("text", req.body.text).fuzziness("AUTO"),
147-
])
155+
esb.boolQuery().should(textQueries)
148156
);
149157
}
150158
let esbQuery = esb.requestBodySearch().query(esb.boolQuery().must(mustMatchQuery)).size(1000);

docker-compose.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,15 @@ services:
136136
command: ["npm", "run", "develop"]
137137

138138
elastic:
139-
image: elasticsearch:8.4.1
139+
image: elasticsearch:8.16.0
140140
hostname: elastic
141141
environment:
142142
- discovery.type=single-node
143143
- ES_JAVA_OPTS=-Xms750m -Xmx750m
144144
- xpack.security.enabled=false
145145
- node.name=search
146+
volumes:
147+
- ./elasticsearch-plugins:/plugins
146148
ulimits:
147149
memlock:
148150
soft: -1
@@ -154,6 +156,12 @@ services:
154156
- IPC_LOCK
155157
ports:
156158
- 9200:9200
159+
command: >
160+
/bin/sh -c "
161+
./bin/elasticsearch-plugin remove nyingarn-phonetic-search;
162+
./bin/elasticsearch-plugin install https://github.com/r-tae/nyingarn-phonetic-search/releases/download/v1.0.0/nyingarn-phonetic-search-1.0-SNAPSHOT.zip;
163+
/usr/local/bin/docker-entrypoint.sh"
164+
157165
158166
edge:
159167
image: nginx:latest

ui-repository/src/components/home-page/Search.component.vue

+8-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
@change="search"
4242
/>
4343
</el-form-item>
44+
<el-form-item>
45+
<el-checkbox
46+
v-model="data.form.is_phonetic"
47+
size="large"
48+
@blur="search"
49+
@change="search">phonetic search</el-checkbox>
50+
</el-form-item>
4451
<el-form-item>
4552
<el-button @click="search" size="large">
4653
<i class="fa-solid fa-magnifying-glass fa-xl"></i>
@@ -114,7 +121,7 @@
114121

115122
<script setup>
116123
import { ref, reactive, inject, onMounted } from "vue";
117-
import { ElAutocomplete, ElForm, ElFormItem, ElButton } from "element-plus";
124+
import { ElAutocomplete, ElForm, ElFormItem, ElCheckbox, ElButton } from "element-plus";
118125
import pluralize from "pluralize";
119126
import { useRouter } from "vue-router";
120127
import { useStore } from "vuex";

ui/src/components/Sidebar.component.vue

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default {
7575
icon: "fa-solid fa-landmark",
7676
},
7777
{ name: "Operations", path: "/admin/operations", icon: "fa-solid fa-cog" },
78+
{ name: "Search config", path: "/admin/search-config", icon: "fa-solid fa-ranking-star" },
7879
],
7980
};
8081
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<template>
2+
<div class="flex flex-col space-y-4" v-loading="data.loading">
3+
<div class="p-8 bg-red-200 rounded">
4+
<div>
5+
<textarea v-model="data.synonyms" placeholder="add synonyms"></textarea>
6+
</div>
7+
</div>
8+
<div>
9+
<el-button @click="setSynonyms">set synonyms</el-button>
10+
</div>
11+
</div>
12+
</template>
13+
14+
<script setup>
15+
import { reactive, onMounted, onBeforeUnmount, inject } from "vue";
16+
17+
const $http = inject("$http");
18+
19+
let data = reactive({
20+
loading: true,
21+
synonyms: []
22+
});
23+
24+
onMounted(async () => {
25+
await getSynonyms();
26+
// ({view} = setupCodeMirror());
27+
});
28+
29+
onBeforeUnmount(async () => {
30+
await setSynonyms();
31+
});
32+
33+
async function getSynonyms() {
34+
data.loading = true;
35+
let response = await $http.get({ route: `/search-synonyms` });
36+
data.synonyms = (await response.text())
37+
data.loading = false;
38+
}
39+
40+
async function setSynonyms() {
41+
data.loading = true;
42+
await $http.post({
43+
route: `/search-synonyms`,
44+
body: data.synonyms
45+
});
46+
data.loading = false;
47+
}
48+
</script>

0 commit comments

Comments
 (0)