如何用sphinx实现颜色搜索?

发布于 2024-09-24 18:14:30 字数 318 浏览 7 评论 0原文

使用 mysql 按主色搜索照片非常简单。假设照片最主要颜色的 r、g、b 值已经存储在数据库中,这可以通过以下方式实现:

SELECT * FROM colors
WHERE    ABS(dominant_r - :r) < :threshold
AND      ABS(dominant_g - :g) < :threshold
AND      ABS(dominant_b - :b) < :threshold

我想知道,是否可以将颜色存储在 sphinx 中并执行使用sphinx搜索引擎进行查询?

谢谢!

searching a photo by dominant colors using mysql is quite simple. assuming that the r,g,b values of the most dominant colors of the photo is already stored in the database, this could be achieved for example by something like:

SELECT * FROM colors
WHERE    ABS(dominant_r - :r) < :threshold
AND      ABS(dominant_g - :g) < :threshold
AND      ABS(dominant_b - :b) < :threshold

i wonder, if it's anyhow possible to store the colors in sphinx and perform the querying using the sphinx search engine?

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘦怹 2024-10-01 18:14:30

我已经用狮身人面像搜索了颜色。就在那里 http://code.google.com/p/hppg/。它是如何运作的?
非常简单,对于每种颜色,我将其主色存储在数据库中。数据库表,用于sphinx索引,有名为“colors”的列,其内容按以下方式填充:

/**
     * This part was changed based on formula 
     * 
     * It fits here better than algorithm
     * 
     * http://en.wikipedia.org/wiki/Tag_cloud
     * 15400 is number of maximum matches based on indexed thumbnail size 120x130 px.
     * */

   $max = 15400;
   $min = 25;
   $rmax = 50;
   $rmin = 1;

   $colorIndex = array();
   foreach ($colorsMaximumImage as $color)
   {
       $colorIndexString = trim(str_repeat(' pld'.$color['pallete_id'],round((($rmin*($color['count']-25))/($max-$min))*100)));
       if ($colorIndexString != '')
       $colorIndex[] = $colorIndexString;
   }

我在这里使用标记公式,以避免非常大的索引。计数是自定义托盘项目匹配的次数。它工作得很好,可以在项目主页找到一些实时站点的示例。这样我们就可以同时按颜色和关键字搜索:)。目前我仍在尝试以获得最佳结果......

I have done search for colors with sphinx. It's there http://code.google.com/p/hppg/. How it works?
Very simple, for each color I store it's dominant colors in database. Database table, witch is used for sphinx indexing, has column named "colors", it's content is filled in the following way:

/**
     * This part was changed based on formula 
     * 
     * It fits here better than algorithm
     * 
     * http://en.wikipedia.org/wiki/Tag_cloud
     * 15400 is number of maximum matches based on indexed thumbnail size 120x130 px.
     * */

   $max = 15400;
   $min = 25;
   $rmax = 50;
   $rmin = 1;

   $colorIndex = array();
   foreach ($colorsMaximumImage as $color)
   {
       $colorIndexString = trim(str_repeat(' pld'.$color['pallete_id'],round((($rmin*($color['count']-25))/($max-$min))*100)));
       if ($colorIndexString != '')
       $colorIndex[] = $colorIndexString;
   }

I used tagging formula here, to avoid very big index. Count is the number of times custom pallete item was matched. It works just fine, some examples of live sites can be found at project home page. Such way we can search by color and keyword at the same time :). Currently I'm still experimenting to get best result of it...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文