开发者

How can I intelligently group rows of integers for a faceted search?

I'm not even quite sure what terms I should be using for what I want, so any advice on what I'm even asking for would be very welcome.

Basically, my web site lists user-generated accommodations. Each has a rent price, which users will be able to query in our new faceted search box.

Users search by city, and within each city I'd like to present a different rent grouping. That is to say that in City #1, if we have listings ranging from $200 - $1000, I'd like to present checkboxes for:

  • less than $300
  • $301 - $500
  • $501 - $700
  • more than $700

However, if City #2 has values that range from $500 - $1500, I want the ranges above to change accordingly. So, if I say that I want 5 or 6 range options in each city, I think I have two options:

  1. Take the min and max values and just split the difference. I don't like this idea beca开发者_JAVA百科use one listing with a rent of $10,000 will throw the whole scale off.

  2. Intelligently calculate the ranges using means, medians etc.

Number 2 is what I need help with. I'm a web developer that gets logic, but was never strong on math and statistics at school. Can anyone point me towards a guide that'll help me figure this out?


If you're looking for 4 groups, you need 3 splitpoints. Take the median of your whole set to get the middle one, then the median of those above and below that to get your other two.


Instead of trying to figure out the scale dynamically based upon the data set, why not have a static scale (or formula for determining scale) and then determine if there is data to support displaying the search options.

For example, if your scale is [(0-300), (301, 600), (601-700), ...] and your dataset contains [$250, $500, $550, $1000] then you would need to display [(0-300), (301-600), (1001-1300)].

You could figure this out with LINQ.


Split your data by quantity.

Something like this (pseudo-C code): Let "set" be the data, "n" be the number of entries, and "s" be the number of splits.

int increment = ceil(n/s);
int start = 0;
int end = increment;
OrderSet(set); // So set[0] is min and set[n-1] is max
for (int i = 0; i < s; i++)
{
  while (set[end] == set[start] && end < n - 1)
    end++;
  AddGroup(start, end);

  if (end == n - 1)
    break;

  start = end;
  end = start + increment;
  if (end >= n)
    end = n - 1;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜