# JSON検索結果にimage\_urlを表示する

**URL:** https://meta.discourse.org/t/display-image-url-in-the-json-search-results/171605
**Category:** Support
**Created:** [2020 年 11 月 29 日午前 4:04 UTC](https://meta.discourse.org/t/display-image-url-in-the-json-search-results/171605 "2020-11-29T04:04:20Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)
#### Post date: [2020 年 11 月 29 日午前 4:04 UTC](https://meta.discourse.org/t/display-image-url-in-the-json-search-results/171605/1 "2020-11-29T04:04:21Z")

</div>

検索結果の JSON で image\_url を表示したいと考えています。

クエリフォームで利用可能でしょうか？ソースコードを確認すると、現在は False を返しているようです。

`/search.json?q=loreal&image_url=true`

オンラインでデモを確認できます：[https://thuvienmuasam.com/t/may-han-mini-an-toan-gia-tot-mua-o-dau/1786（申し訳ありませんが、言語は投稿の末尾にあります）](https://thuvienmuasam.com/t/may-han-mini-an-toan-gia-tot-mua-o-dau/1786%EF%BC%88%E7%94%B3%E3%81%97%E8%A8%B3%E3%81%82%E3%82%8A%E3%81%BE%E3%81%9B%E3%82%93%E3%81%8C%E3%80%81%E8%A8%80%E8%AA%9E%E3%81%AF%E6%8A%95%E7%A8%BF%E3%81%AE%E6%9C%AB%E5%B0%BE%E3%81%AB%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%EF%BC%89)

---

<div class="post-metadata">

### Author: ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)
#### Post date: [2020 年 11 月 30 日午前 5:16 UTC](https://meta.discourse.org/t/display-image-url-in-the-json-search-results/171605/2 "2020-11-30T05:16:08Z")

</div>

> <https://github.com/discourse/discourse/blob/10a6824e5f49a69c43bf6cb3f09de0a1c57bb0d4/app/serializers/search_topic_list_item_serializer.rb>

ここはブロックされていますか

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/1/9132f9752cedf428cb47bb96339a1e7e8fb7a472.png)

---

<div class="post-metadata">

### Author: ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)
#### Post date: [2020 年 11 月 30 日午前 6:38 UTC](https://meta.discourse.org/t/display-image-url-in-the-json-search-results/171605/3 "2020-11-30T06:38:40Z")

</div>

@Bcat さん、こんにちは！

これ、ご覧になりましたか？

> [@Single topic API endpoint should contain \`image\_url\`](https://meta.discourse.org/t/single-topic-api-endpoint-should-contain-image-url/131020):
>
> When you fetch a list of all topics with a certain tag (e.g. [https://meta.discourse.org/tags/ui.json](https://meta.discourse.org/tags/ui.json)), each topic contains an image\_url field. If you fetch, however, only one topic (e.g. [https://meta.discourse.org/t/37245.json](https://meta.discourse.org/t/37245.json)) it does not contain an image\_url field. This is kind of inconsistent and it would help me a lot if it was available. Can you maybe add it? My workaround for the time being is: response.image\_url = (response.post\_stream.posts[0].cooked .match(/src=\"(.+?)\"/) || [])[1]…

---

<div class="post-metadata">

### Author: ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)
#### Post date: [2020 年 11 月 30 日午前 6:40 UTC](https://meta.discourse.org/t/display-image-url-in-the-json-search-results/171605/4 "2020-11-30T06:40:49Z")

</div>

クエリで json を使用する場合、category、tag、top、newest のすべてに `image_url` が含まれます。  
しかし、search では `image_url` が含まれません。

現在、リスト（10 トピック）を取得するために 1 回の JSON クエリを実行し、その後、画像を取得するために 10 回のクエリを実行しています。  
合計でサーバーへのクエリは 11 回になります。

---

<div class="post-metadata">

### Author: ![bombledmonk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bombledmonk/32/80322_2.png) [@bombledmonk](https://meta.discourse.org/u/bombledmonk)
#### Post date: [2021 年 1 月 5 日午前 3:59 UTC](https://meta.discourse.org/t/display-image-url-in-the-json-search-results/171605/5 "2021-01-05T03:59:17Z")

</div>

これが同じ問題かどうかは 100% 確信はありませんが、関連している可能性はあります。検索 API を使用しているところですが、この[クエリ](https://forum.digikey.com/search/query.json?term=Molex%202002182200%5Cu0026includ_blurbs=true)では、 **topics** 配列に_image\_url_が表示されなくなったようです。 **topics** 配列内のオブジェクトは[こちら](https://forum.digikey.com/t/molex-0638190900-obsolete-crimp-tool-replacement/10621)にリンクしており、そこには最初の投稿に画像が含まれていますが、[API ドキュメント](https://docs.discourse.org/#tag/Search)（もしかしたら私が誤解している可能性もありますが）を正しく理解している限り、_image\_url_は欠落しています。久しぶりに確認しましたが、以前はそのまま動作していたはずです。

 ![image](https://global.discourse-cdn.com/meta/original/3X/6/a/6adc63ece00863ffa7e23d7a400411afe4ece3b9.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/e/0/e0296cee59a9b1a08d636edd9405d51ac40bd41f.png)

---

<div class="post-metadata">

### Author: ![Bcat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bcat/32/163148_2.png) [@Bcat](https://meta.discourse.org/u/Bcat)
#### Post date: [2021 年 1 月 5 日午前 6:29 UTC](https://meta.discourse.org/t/display-image-url-in-the-json-search-results/171605/6 "2021-01-05T06:29:22Z")

</div>

はい、もうそこにはありません。

Discourse に干渉する外部ソリューションが必要な場合は、お勧めできます。
