Improve search service's readme and components.
This commit is contained in:
parent
90a2346cc9
commit
c45b1da636
|
@ -9,11 +9,27 @@ export const api = axios.create({
|
|||
baseURL: process.env.API_URL,
|
||||
});
|
||||
|
||||
/**
|
||||
* The main Gymboard API namespace, containing various modules that deal with
|
||||
* different parts of the API, like auth or users.
|
||||
*/
|
||||
class GymboardApi {
|
||||
public readonly auth = new AuthModule();
|
||||
public readonly gyms = new GymsModule();
|
||||
public readonly users = new UsersModule();
|
||||
public readonly exercises = new ExercisesModule();
|
||||
public readonly leaderboards = new LeaderboardsModule();
|
||||
|
||||
/**
|
||||
* Gets the status of the Gymboard API.
|
||||
*/
|
||||
public async getStatus(): Promise<boolean> {
|
||||
try {
|
||||
await api.get('/status');
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
export default new GymboardApi();
|
||||
|
|
|
@ -31,7 +31,7 @@ class SearchApi {
|
|||
|
||||
public async getStatus(): Promise<boolean> {
|
||||
try {
|
||||
const response = await api.get(`/status`);
|
||||
await api.get('/status');
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
|
|
|
@ -40,10 +40,10 @@ import { useRoute, useRouter } from 'vue-router';
|
|||
import { DateTime } from 'luxon';
|
||||
import { getFileUrl } from 'src/api/cdn';
|
||||
import { getGymRoute } from 'src/router/gym-routing';
|
||||
import {useAuthStore} from "stores/auth-store";
|
||||
import {showApiErrorToast} from "src/utils";
|
||||
import {useI18n} from "vue-i18n";
|
||||
import {useQuasar} from "quasar";
|
||||
import {useAuthStore} from 'stores/auth-store';
|
||||
import {showApiErrorToast} from 'src/utils';
|
||||
import {useI18n} from 'vue-i18n';
|
||||
import {useQuasar} from 'quasar';
|
||||
|
||||
const submission: Ref<ExerciseSubmission | undefined> = ref();
|
||||
|
||||
|
|
|
@ -32,5 +32,4 @@ build/
|
|||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
gym-index/
|
||||
user-index/
|
||||
indexes/
|
||||
|
|
|
@ -2,8 +2,12 @@
|
|||
|
||||
A simple search API for Gymboard, backed by Apache Lucene. This application includes both indexing of Gyms and other searchable entities, and a public web interface for searching those indexes.
|
||||
|
||||
This application is configured with read-only access to the central Gymboard database, for its indexing operations.
|
||||
This application is configured with read-only access to the central Gymboard database for its indexing operations.
|
||||
|
||||
## Developing
|
||||
|
||||
Currently, this application is designed to boot up and immediately read the latest data from the Gymboard API's database to rebuild its indexes, then continue to do so at scheduled intervals.
|
||||
|
||||
Indexes are stored in the `indexes/` directory.
|
||||
|
||||
**Note:** At some point, it would be a lot more efficient to have this application listen for entity update events published by other services, instead of fully scanning the entire database for each index operation. But for now, that's not needed.
|
||||
|
|
|
@ -26,7 +26,7 @@ public class GymboardSearchApplication {
|
|||
private final JdbcIndexGenerator gymIndexGenerator;
|
||||
private final JdbcIndexGenerator userIndexGenerator;
|
||||
|
||||
@Scheduled(fixedRate = 1, timeUnit = TimeUnit.HOURS)
|
||||
@Scheduled(fixedRate = 1, timeUnit = TimeUnit.MINUTES)
|
||||
public void reIndex() {
|
||||
gymIndexGenerator.generate();
|
||||
userIndexGenerator.generate();
|
||||
|
|
|
@ -36,7 +36,7 @@ public class IndexComponents {
|
|||
@Bean
|
||||
public JdbcIndexGenerator userIndexGenerator(JdbcConnectionSupplier connectionSupplier) throws IOException {
|
||||
return new JdbcIndexGenerator(
|
||||
Path.of("user-index"),
|
||||
Path.of("indexes", "users"),
|
||||
connectionSupplier,
|
||||
PlainQueryResultSetSupplier.fromResourceFile("/sql/select-users.sql"),
|
||||
rs -> {
|
||||
|
@ -66,7 +66,7 @@ public class IndexComponents {
|
|||
@Bean
|
||||
public JdbcIndexGenerator gymIndexGenerator(JdbcConnectionSupplier connectionSupplier) throws IOException {
|
||||
return new JdbcIndexGenerator(
|
||||
Path.of("gym-index"),
|
||||
Path.of("indexes", "gyms"),
|
||||
connectionSupplier,
|
||||
PlainQueryResultSetSupplier.fromResourceFile("/sql/select-gyms.sql"),
|
||||
rs -> {
|
||||
|
|
|
@ -33,15 +33,7 @@ public class JdbcIndexGenerator {
|
|||
|
||||
public void generate() {
|
||||
log.info("Generating index at {}.", indexDir);
|
||||
if (Files.exists(indexDir)) {
|
||||
try {
|
||||
FileSystemUtils.deleteRecursively(indexDir);
|
||||
Files.createDirectories(indexDir);
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to reset index directory.", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
try (
|
||||
Connection conn = connectionSupplier.getConnection();
|
||||
ResultSet rs = resultSetSupplier.supply(conn);
|
||||
|
@ -62,7 +54,8 @@ public class JdbcIndexGenerator {
|
|||
log.error("Failed to add document.", e);
|
||||
}
|
||||
}
|
||||
log.info("Indexed {} entities.", count);
|
||||
long dur = System.currentTimeMillis() - start;
|
||||
log.info("Indexed {} entities for {} index in {} ms.", count, indexDir, dur);
|
||||
indexWriter.close();
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to prepare indexing components.", e);
|
||||
|
|
Loading…
Reference in New Issue