CCK Facet is buggy when using a CCK decimal field and the values of that field are non-integer. Integer values appear to work correctly. Some decimal values appear to work correctly. Other decimal values do not work correctly.

    To duplicate:
  • create a content type with a decimal text field widget.
  • create content of that type with varying values in the CCK field
  • create faceted search environment with the CCK field selected
  • enable the guided search block
  • search for values listed in the guided search block; some work; some don't.

You can find a demonstration here: http://irzoom.weait.com/facet

The integer values -1, 10, 12 and 20 work as expected. Decimal values of 1.5 and -1.5 work. Other decimal values return "Your search yielded no results" when they should return one or more nodes.

CommentFileSizeAuthor
#1 facet.png77.68 KBrweait
#1 facet-result.png93.45 KBrweait

Comments

rweait’s picture

StatusFileSize
new93.45 KB
new77.68 KB

Now with screen shots.

rweait’s picture

Project: CCK Facets » Faceted Search
Version: 5.x-1.x-dev » 6.x-1.x-dev
Component: Number Facets » General

Changed project to Faceted_Search.

It turns out that this bug appears in CCK_Facets but is created in Faceted_Search. Sorta.

Let's review. We've created a CCK decimal field and created a facet to use it. It displays properly in guided search and works sometimes, but fails sometimes when clicking on the linked values in guided search. We create a few nodes using this and have a look at the mysql tables.

mysql> select nid, field_img_diagonal_value from content_type_lens;

+-----+--------------------------+
| nid | field_img_diagonal_value |
+-----+--------------------------+
|   1 |                       10 | 
|   2 |                       12 | 
|   5 |                    28.24 | 
|   6 |                    10.16 |
+-----+--------------------------+

And this looks fine. So then we look at a typical query created by faceted_search.

mysql> select nid, field_img_diagonal_value from content_type_lens where field_img_diagonal_value = 10.16;
Empty set (0.35 sec)

"Empty Set"? What's that? I can see it right there, but mysql can't doesn't return it?

Sadly, float values are not always as they seem as documented here, http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html and here, http://74.54.63.139/tutorials/php/floating-point-comparisons-in-php-and-...

Adding a little bit of 'slack' to the query does find the node we're looking for like this.

mysql> select nid, field_img_diagonal_value from content_type_lens where field_img_diagonal_value > 10.1599 and field_img_diagonal_value < 10.1601;
+-----+--------------------------+
| nid | field_img_diagonal_value |
+-----+--------------------------+
|   6 |                    10.16 | 
+-----+--------------------------+
1 row in set (0.09 sec)

So what is the best way to resolve this? Do we add some 'slack' to the queries? Ask users to specify number of decimal places and add slack at decimalplace+1? Avoid using decimal and use text values instead?

What is a reasonable way to proceed?

kbahey at 2bits found and diagnosed the problem and I am very grateful to him.

david lesieur’s picture

Project: Faceted Search » CCK Facets
Version: 6.x-1.x-dev » 5.x-1.x-dev

Thanks for the investigation!

The problem is really in CCK Facets, since it is where the number comparison is added into the query. As explained on the page you have pointed to, we should probably define an acceptable tolerance for differences between the numbers and then do the comparison against the tolerance value.

This could be done in cck_facet_category::build_results_query(). The tolerance would thus be applied to all floating-point number comparisons, although I'm not sure yet if that's what we want...

kbahey’s picture

David

I think the problem is storing values as floats.

Just to test this, here is what I did:

Before:

mysql> desc content_type_lens;
+--------------------------+------------------+------+-----+---------+-------+
| Field                    | Type             | Null | Key | Default | Extra |
+--------------------------+------------------+------+-----+---------+-------+
...
| field_img_diagonal_value | float            | YES  |     | NULL    |       |

So, I changed it to decimal to see what the effect would be:

mysql> alter table content_type_lens change field_img_diagonal_value field_img_diagonal_value decimal(8,2);
Query OK, 13 rows affected, 4 warnings (0.01 sec)
Records: 13  Duplicates: 0  Warnings: 4

And the result is:

mysql> desc content_type_lens;
+--------------------------+------------------+------+-----+---------+-------+
| Field                    | Type             | Null | Key | Default | Extra |
+--------------------------+------------------+------+-----+---------+-------+
...

| field_img_diagonal_value | decimal(8,2)     | YES  |     | NULL    |       |

After that, faceted search and cck facets worked perfectly on whole numbers and fractions.

So, I think storing the numbers as decimals will solve this. The issue is that this is at the cck level, not faceted search nor cck facets.

Look here http://groups.drupal.org/node/8574 and search the page in your browser for "float". Perhaps we can comment there?

david lesieur’s picture

Great find! On the page you are pointing to, Karen says that D6 CCK offers both decimal and float types, so it looks like we'll still have to deal with floats...

rweait’s picture

And so we'll want to present a UI for the selection of decimal places in DEC and the tolerance or rounding amount for FLOAT. Can we drag Karen and other interested parties into this discussion? (Should that be here?)

david lesieur’s picture

Apparently, D6 CCK already provides the necessary UI for selecting the precision of decimal fields (I have not tried it). So, do we want a similar UI to define the tolerance/rounding of float fields? This should probably be discussed in the CCK issue queue... ;)

rweait’s picture

Project: CCK Facets » Content Construction Kit (CCK)
Version: 5.x-1.x-dev » 5.x-1.6-1
Component: General » number.module

changed to CCK issue queue.

karens’s picture

Status: Active » Closed (won't fix)

This is a limitation of the float field used in D5. See #501016: Big numbers (>10,000) get rounded up and other reports. This won't get fixed in D5. D6 has a proper decimal field.