Skip to content

fix: Exclude user page data from search response when user pages are disabled#10740

Merged
yuki-takei merged 21 commits intomasterfrom
fix/177549-block-user-page-searches
Mar 2, 2026
Merged

fix: Exclude user page data from search response when user pages are disabled#10740
yuki-takei merged 21 commits intomasterfrom
fix/177549-block-user-page-searches

Conversation

@arvid-e
Copy link
Contributor

@arvid-e arvid-e commented Jan 22, 2026

@arvid-e arvid-e requested a review from miya January 22, 2026 06:51
if (!query.includes('-prefix:/user')) {
query = `${query.trim()} -prefix:/user`;
}
}
Copy link
Member

@miya miya Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おそらく ElasticSearchClient 周りまで見る必要はなく Controller 層の修正のみで済む

ごめん、これは嘘で、normalizeQueryString の中でやった方が良さそうです。

const normalizeQueryString = (_queryString: string): string => {
let queryString = _queryString.trim();
queryString = removeAiMenthion(queryString).replace(/\s+/g, ' ');
return queryString;
};

@arvid-e arvid-e requested a review from miya January 26, 2026 06:05
@miya miya requested a review from yuki-takei January 26, 2026 06:08
const cleanQuery = query.replace(/prefix:\/user/g, '').trim();

if (!cleanQuery.includes('-prefix:/user')) {
const queryWithUserPrefix = `${cleanQuery.trim()} -prefix:/user`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanQuery 変数作成時 trim() 済みなので、ここで trim() をもう一回呼び出すのは冗長だとおもいます

@@ -0,0 +1,18 @@
export function removeUserPages(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • メソッド名から実装の内容が想像しにくいです
  • excludeUserPagesFromQuery とかはどうでしょうか?

return query;
}

const cleanQuery = query.replace(/prefix:\/user/g, '').trim();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文字列操作が甘い

  • prefix:/userouterouter になってしまう
  • apprefix:/userap になってしまう


const cleanQuery = query.replace(/prefix:\/user/g, '').trim();

if (!cleanQuery.includes('-prefix:/user')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらも同様

const normalizeQueryString = (
_queryString: string,
disableUserPages: boolean,
): string => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalizeQueryString はいじらず、const terms = this.parseQueryString(queryString); の結果である QueryTerms に対して prefix と not_prefix を操作すればいいんじゃないかね?

それから /user だけではなく、/user/ から始まるものも全て消す必要がある

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちなみに、parseSearchQuery() の返り値である ParsedQuery の queryString には特に操作を加える必要がない可能性が高い。おそらく appendFunctionScore で文字列長を数えるためだけに使われている。(要調査)

const normalizeQueryString = (
_queryString: string,
disableUserPages: boolean,
): string => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちなみに、parseSearchQuery() の返り値である ParsedQuery の queryString には特に操作を加える必要がない可能性が高い。おそらく appendFunctionScore で文字列長を数えるためだけに使われている。(要調査)

@arvid-e arvid-e requested review from miya and yuki-takei February 12, 2026 08:07

export function excludeUserPagesFromQuery(terms: QueryTerms): void {
terms.prefix = terms.prefix.filter((p) => !p.startsWith('/user'));
terms.not_prefix = terms.not_prefix.filter((p) => !p.startsWith('/user'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix:/userouter のような edge case を考えるようにしてください

@arvid-e arvid-e requested a review from yuki-takei February 17, 2026 07:45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

単体テスト追加してください

@arvid-e arvid-e requested a review from yuki-takei February 26, 2026 06:52
@arvid-e arvid-e requested a review from yuki-takei March 2, 2026 08:13
@yuki-takei yuki-takei merged commit 17e822c into master Mar 2, 2026
26 checks passed
@yuki-takei yuki-takei deleted the fix/177549-block-user-page-searches branch March 2, 2026 10:37
This was referenced Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants