null+****@clear*****
null+****@clear*****
2010年 8月 5日 (木) 12:27:32 JST
Kouhei Sutou 2010-08-05 03:27:32 +0000 (Thu, 05 Aug 2010) New Revision: 6b3392c6e6f7fc16bb26f2a5a10814f27a9f1130 Log: add a test for sorting with index. Modified files: test/unit/fixtures/story/taiyaki/ddl.grn test/unit/story/taiyaki/test-geo.c Modified: test/unit/fixtures/story/taiyaki/ddl.grn (+3 -0) =================================================================== --- test/unit/fixtures/story/taiyaki/ddl.grn 2010-08-05 03:06:30 +0000 (dac8522) +++ test/unit/fixtures/story/taiyaki/ddl.grn 2010-08-05 03:27:32 +0000 (78d9d0b) @@ -1,5 +1,7 @@ table_create Bigram TABLE_PAT_KEY|KEY_NORMALIZE ShortText --default_tokenizer TokenBigram +table_create Locations TABLE_PAT_KEY WGS84GeoPoint + table_create Tags TABLE_PAT_KEY ShortText column_create Tags name COLUMN_SCALAR ShortText @@ -19,4 +21,5 @@ column_create Shops categories COLUMN_VECTOR Categories column_create Shops area COLUMN_SCALAR Areas column_create Tags index COLUMN_INDEX Shops tags +column_create Locations shop COLUMN_INDEX Shops location column_create Bigram name COLUMN_INDEX|WITH_POSITION|WITH_SECTION Shops name Modified: test/unit/story/taiyaki/test-geo.c (+31 -0) =================================================================== --- test/unit/story/taiyaki/test-geo.c 2010-08-05 03:06:30 +0000 (196cf76) +++ test/unit/story/taiyaki/test-geo.c 2010-08-05 03:27:32 +0000 (f9a6a69) @@ -22,6 +22,7 @@ #include "../../lib/grn-assertions.h" void test_in_circle(void); +void test_sort(void); void test_filter_by_tag_and_sort_by_distance_from_tokyo_tocho(void); void test_but_white(void); void test_drilldown(void); @@ -121,6 +122,36 @@ test_in_circle(void) } void +test_sort(void) +{ + gdouble yurakucho_latitude = 35.67487; + gdouble yurakucho_longitude = 139.76352; + gint distance = 3 * 1000; + + cut_assert_equal_string( + "[[[6]," + "[[\"name\",\"ShortText\"],[\"_score\",\"Int32\"]]," + "[\"銀座 かずや\",795]," + "[\"たいやき神田達磨 八重洲店\",1079]," + "[\"たい焼き鉄次 大丸東京店\",1390]," + "[\"築地 さのきや\",1723]," + "[\"にしみや 甘味処\",2000]," + "[\"しげ田\",2272]" + "]]", + send_command( + cut_take_printf( + "select Shops " + "--sortby 'geo_distance(location, \"%s\")' " + "--output_columns 'name, _score' " + "--filter 'geo_in_circle(location, \"%s\", %d)' " + "--scorer '_score=geo_distance(location, \"%s\")'", + grn_test_location_string(yurakucho_latitude, yurakucho_longitude), + grn_test_location_string(yurakucho_latitude, yurakucho_longitude), + distance, + grn_test_location_string(yurakucho_latitude, yurakucho_longitude)))); +} + +void test_filter_by_tag_and_sort_by_distance_from_tokyo_tocho(void) { gdouble tokyo_tocho_latitude = 35.689444;