|
@@ -4,12 +4,13 @@ import xss from 'xss';
|
|
|
import { SearchDelegatorName } from '~/interfaces/named-query';
|
|
import { SearchDelegatorName } from '~/interfaces/named-query';
|
|
|
import { IPageHasId } from '~/interfaces/page';
|
|
import { IPageHasId } from '~/interfaces/page';
|
|
|
import { IFormattedSearchResult, IPageWithSearchMeta, ISearchResult } from '~/interfaces/search';
|
|
import { IFormattedSearchResult, IPageWithSearchMeta, ISearchResult } from '~/interfaces/search';
|
|
|
|
|
+import {
|
|
|
|
|
+ DEFAULT_HIGHLIGHT_FRAGMENT_SIZE,
|
|
|
|
|
+ SearchDelegator, SearchQueryParser, SearchResolver, ParsedQuery, SearchableData, QueryTerms,
|
|
|
|
|
+} from '~/server/interfaces/search';
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
import { ObjectIdLike } from '../interfaces/mongoose-utils';
|
|
import { ObjectIdLike } from '../interfaces/mongoose-utils';
|
|
|
-import {
|
|
|
|
|
- SearchDelegator, SearchQueryParser, SearchResolver, ParsedQuery, SearchableData, QueryTerms,
|
|
|
|
|
-} from '../interfaces/search';
|
|
|
|
|
import NamedQuery from '../models/named-query';
|
|
import NamedQuery from '../models/named-query';
|
|
|
import { PageModel } from '../models/page';
|
|
import { PageModel } from '../models/page';
|
|
|
import { serializeUserSecurely } from '../models/serializers/user-serializer';
|
|
import { serializeUserSecurely } from '../models/serializers/user-serializer';
|
|
@@ -455,9 +456,11 @@ class SearchService implements SearchQueryParser, SearchResolver {
|
|
|
const pathMatch = highlightData['path.en'] || highlightData['path.ja'];
|
|
const pathMatch = highlightData['path.en'] || highlightData['path.ja'];
|
|
|
const isHtmlInPath = highlightData['path.en'] != null || highlightData['path.ja'] != null;
|
|
const isHtmlInPath = highlightData['path.en'] != null || highlightData['path.ja'] != null;
|
|
|
|
|
|
|
|
|
|
+ const shouldHighlight = pathMatch != null ? DEFAULT_HIGHLIGHT_FRAGMENT_SIZE >= pathMatch[0].length : false;
|
|
|
|
|
+
|
|
|
elasticSearchResult = {
|
|
elasticSearchResult = {
|
|
|
snippet: snippet != null && typeof snippet[0] === 'string' ? filterXss.process(snippet) : null,
|
|
snippet: snippet != null && typeof snippet[0] === 'string' ? filterXss.process(snippet) : null,
|
|
|
- highlightedPath: pathMatch != null && typeof pathMatch[0] === 'string' ? filterXss.process(pathMatch) : null,
|
|
|
|
|
|
|
+ highlightedPath: pathMatch != null && typeof pathMatch[0] === 'string' && shouldHighlight ? filterXss.process(pathMatch) : null,
|
|
|
isHtmlInPath,
|
|
isHtmlInPath,
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|