|
|
@@ -29,7 +29,7 @@ class SearchService implements SearchQueryParser, SearchResolver {
|
|
|
|
|
|
isErrorOccuredOnSearching: boolean | null
|
|
|
|
|
|
- delegator: any & SearchDelegator
|
|
|
+ fullTextSearchDelegator: any & SearchDelegator
|
|
|
|
|
|
nqDelegators: {[key in SearchDelegatorName]: SearchDelegator} // TODO: initialize
|
|
|
|
|
|
@@ -41,20 +41,20 @@ class SearchService implements SearchQueryParser, SearchResolver {
|
|
|
this.isErrorOccuredOnSearching = null;
|
|
|
|
|
|
try {
|
|
|
- this.delegator = this.generateDelegator();
|
|
|
+ this.fullTextSearchDelegator = this.generateDelegator();
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
}
|
|
|
|
|
|
if (this.isConfigured) {
|
|
|
- this.delegator.init();
|
|
|
+ this.fullTextSearchDelegator.init();
|
|
|
this.registerUpdateEvent();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
get isConfigured() {
|
|
|
- return this.delegator != null;
|
|
|
+ return this.fullTextSearchDelegator != null;
|
|
|
}
|
|
|
|
|
|
get isReachable() {
|
|
|
@@ -80,19 +80,19 @@ class SearchService implements SearchQueryParser, SearchResolver {
|
|
|
|
|
|
registerUpdateEvent() {
|
|
|
const pageEvent = this.crowi.event('page');
|
|
|
- pageEvent.on('create', this.delegator.syncPageUpdated.bind(this.delegator));
|
|
|
- pageEvent.on('update', this.delegator.syncPageUpdated.bind(this.delegator));
|
|
|
- pageEvent.on('deleteCompletely', this.delegator.syncPagesDeletedCompletely.bind(this.delegator));
|
|
|
- pageEvent.on('delete', this.delegator.syncPageDeleted.bind(this.delegator));
|
|
|
- pageEvent.on('updateMany', this.delegator.syncPagesUpdated.bind(this.delegator));
|
|
|
- pageEvent.on('syncDescendants', this.delegator.syncDescendantsPagesUpdated.bind(this.delegator));
|
|
|
+ pageEvent.on('create', this.fullTextSearchDelegator.syncPageUpdated.bind(this.fullTextSearchDelegator));
|
|
|
+ pageEvent.on('update', this.fullTextSearchDelegator.syncPageUpdated.bind(this.fullTextSearchDelegator));
|
|
|
+ pageEvent.on('deleteCompletely', this.fullTextSearchDelegator.syncPagesDeletedCompletely.bind(this.fullTextSearchDelegator));
|
|
|
+ pageEvent.on('delete', this.fullTextSearchDelegator.syncPageDeleted.bind(this.fullTextSearchDelegator));
|
|
|
+ pageEvent.on('updateMany', this.fullTextSearchDelegator.syncPagesUpdated.bind(this.fullTextSearchDelegator));
|
|
|
+ pageEvent.on('syncDescendants', this.fullTextSearchDelegator.syncDescendantsPagesUpdated.bind(this.fullTextSearchDelegator));
|
|
|
|
|
|
const bookmarkEvent = this.crowi.event('bookmark');
|
|
|
- bookmarkEvent.on('create', this.delegator.syncBookmarkChanged.bind(this.delegator));
|
|
|
- bookmarkEvent.on('delete', this.delegator.syncBookmarkChanged.bind(this.delegator));
|
|
|
+ bookmarkEvent.on('create', this.fullTextSearchDelegator.syncBookmarkChanged.bind(this.fullTextSearchDelegator));
|
|
|
+ bookmarkEvent.on('delete', this.fullTextSearchDelegator.syncBookmarkChanged.bind(this.fullTextSearchDelegator));
|
|
|
|
|
|
const tagEvent = this.crowi.event('tag');
|
|
|
- tagEvent.on('update', this.delegator.syncTagChanged.bind(this.delegator));
|
|
|
+ tagEvent.on('update', this.fullTextSearchDelegator.syncTagChanged.bind(this.fullTextSearchDelegator));
|
|
|
}
|
|
|
|
|
|
resetErrorStatus() {
|
|
|
@@ -102,7 +102,7 @@ class SearchService implements SearchQueryParser, SearchResolver {
|
|
|
|
|
|
async reconnectClient() {
|
|
|
logger.info('Try to reconnect...');
|
|
|
- this.delegator.initClient();
|
|
|
+ this.fullTextSearchDelegator.initClient();
|
|
|
|
|
|
try {
|
|
|
await this.getInfoForHealth();
|
|
|
@@ -117,7 +117,7 @@ class SearchService implements SearchQueryParser, SearchResolver {
|
|
|
|
|
|
async getInfo() {
|
|
|
try {
|
|
|
- return await this.delegator.getInfo();
|
|
|
+ return await this.fullTextSearchDelegator.getInfo();
|
|
|
}
|
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
|
@@ -127,7 +127,7 @@ class SearchService implements SearchQueryParser, SearchResolver {
|
|
|
|
|
|
async getInfoForHealth() {
|
|
|
try {
|
|
|
- const result = await this.delegator.getInfoForHealth();
|
|
|
+ const result = await this.fullTextSearchDelegator.getInfoForHealth();
|
|
|
|
|
|
this.isErrorOccuredOnHealthcheck = false;
|
|
|
return result;
|
|
|
@@ -142,15 +142,15 @@ class SearchService implements SearchQueryParser, SearchResolver {
|
|
|
}
|
|
|
|
|
|
async getInfoForAdmin() {
|
|
|
- return this.delegator.getInfoForAdmin();
|
|
|
+ return this.fullTextSearchDelegator.getInfoForAdmin();
|
|
|
}
|
|
|
|
|
|
async normalizeIndices() {
|
|
|
- return this.delegator.normalizeIndices();
|
|
|
+ return this.fullTextSearchDelegator.normalizeIndices();
|
|
|
}
|
|
|
|
|
|
async rebuildIndex() {
|
|
|
- return this.delegator.rebuildIndex();
|
|
|
+ return this.fullTextSearchDelegator.rebuildIndex();
|
|
|
}
|
|
|
|
|
|
async parseSearchQuery(_queryString: string): Promise<ParsedQuery> {
|
|
|
@@ -171,8 +171,9 @@ class SearchService implements SearchQueryParser, SearchResolver {
|
|
|
const name = queryString.replace(replaceRegexp, '');
|
|
|
const nq = await NamedQuery.findOne({ name });
|
|
|
|
|
|
+ // will delegate to full-text search
|
|
|
if (nq == null) {
|
|
|
- throw Error('Named query was not found.');
|
|
|
+ return { queryString, terms: this.parseQueryString(queryString) };
|
|
|
}
|
|
|
|
|
|
const { aliasOf, delegatorName } = nq;
|
|
|
@@ -197,15 +198,11 @@ class SearchService implements SearchQueryParser, SearchResolver {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (terms == null) {
|
|
|
- throw Error('Either of terms or delegatorName must not be null');
|
|
|
- }
|
|
|
-
|
|
|
const data = {
|
|
|
queryString,
|
|
|
- terms,
|
|
|
+ terms: terms as QueryTerms,
|
|
|
};
|
|
|
- return [this.delegator, data];
|
|
|
+ return [this.fullTextSearchDelegator, data];
|
|
|
}
|
|
|
|
|
|
async searchKeyword(keyword: string, user, userGroups, searchOpts): Promise<Result<any> & MetaData> {
|