~ubuntu-branches/ubuntu/jaunty/xapian-omega/jaunty-security

« back to all changes in this revision

Viewing changes to query.cc

  • Committer: Bazaar Package Importer
  • Author(s): Olly Betts
  • Date: 2008-08-08 08:23:01 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080808082301-9m19vqevpupv0grf
Tags: 1.0.7-3
debian/rules: Run "make all" and "make check" as separate commands to
avoid hitting parallel building bugs.  Related to #493390 and
#494247.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright 2001 James Aylett
5
5
 * Copyright 2001,2002 Ananova Ltd
6
6
 * Copyright 2002 Intercede 1749 Ltd
7
 
 * Copyright 2002,2003,2004,2005,2006,2007 Olly Betts
 
7
 * Copyright 2002,2003,2004,2005,2006,2007,2008 Olly Betts
 
8
 * Copyright 2008 Thomas Viehmann
8
9
 *
9
10
 * This program is free software; you can redistribute it and/or
10
11
 * modify it under the terms of the GNU General Public License as
653
654
                res += bra;
654
655
            } else {
655
656
                static const char * colours[] = {
656
 
                    "ffff66", "66ffff", "ff66ff", "6666ff", "ff6666",
657
 
                    "66ff66", "ffaa33", "33ffaa", "aa33ff", "33aaff"
 
657
                    "ffff66", "99ff99", "99ffff", "ff66ff", "ff9999",
 
658
                    "990000", "009900", "996600", "006699", "990099"
658
659
                };
659
 
                res += "<b style=\"color:black;background-color:#";
660
 
                res += colours[match % (sizeof(colours) / sizeof(colours[0]))];
 
660
                size_t idx = match % (sizeof(colours) / sizeof(colours[0]));
 
661
                const char * bg = colours[idx];
 
662
                if (strchr(bg, 'f')) {
 
663
                    res += "<b style=\"color:black;background-color:#";
 
664
                } else {
 
665
                    res += "<b style=\"color:white;background-color:#";
 
666
                }
 
667
                res += bg;
661
668
                res += "\">";
662
669
            }
663
670
            word = string(first.raw(), j.raw() - first.raw());
715
722
enum tagval {
716
723
CMD_,
717
724
CMD_add,
 
725
CMD_addfilter,
718
726
CMD_allterms,
719
727
CMD_and,
720
728
CMD_cgi,
756
764
CMD_list,
757
765
CMD_log,
758
766
CMD_lookup,
 
767
CMD_lower,
759
768
CMD_lt,
760
769
CMD_map,
761
770
CMD_max,
801
810
CMD_uniq,
802
811
CMD_unpack,
803
812
CMD_unstem,
 
813
CMD_upper,
804
814
CMD_url,
805
815
CMD_value,
806
816
CMD_version,
829
839
//name minargs maxargs evalargs ensure
830
840
{"",{CMD_,         N, N, 0, 0}},// commented out code
831
841
T(add,             0, N, N, 0), // add a list of numbers
 
842
T(addfilter,       1, 1, N, 0), // add filter term
832
843
T(allterms,        0, 1, N, 0), // list of all terms matching document
833
844
T(and,             1, N, 0, 0), // logical shortcutting and of a list of values
834
845
T(cgi,             1, 1, N, 0), // return cgi parameter value
872
883
T(list,            2, 5, N, 0), // pretty print list
873
884
T(log,             1, 2, 1, 0), // create a log entry
874
885
T(lookup,          2, 2, N, 0), // lookup in named cdb file
 
886
T(lower,           1, 1, N, 0), // convert string to lower case
875
887
T(lt,              2, 2, N, 0), // test <
876
888
T(map,             1, 2, 1, 0), // map a list into another list
877
889
T(max,             1, N, N, 0), // maximum of a list of values
920
932
T(unpack,          1, 1, N, 0), // convert 4 byte big endian binary string to a number
921
933
T(unstem,          1, 1, N, Q), // return list of probabilistic terms from
922
934
                                // the query which stemmed to this term
 
935
T(upper,           1, 1, N, 0), // convert string to upper case
923
936
T(url,             1, 1, N, 0), // url encode argument
924
937
T(value,           1, 2, N, 0), // return document value
925
938
T(version,         0, 0, N, 0), // omega version string
1057
1070
                value = int_to_string(total);
1058
1071
                break;
1059
1072
            }
 
1073
            case CMD_addfilter:
 
1074
                add_bterm(args[0]);
 
1075
                break;
1060
1076
            case CMD_allterms: {
1061
1077
                // list of all terms indexing document
1062
1078
                int id = q0;
1190
1206
                            format = "%d.%cG";
1191
1207
                        }
1192
1208
                    }
1193
 
                    intpart = size / 1024;
1194
 
                    fraction = size % 1024;
 
1209
                    intpart = unsigned(size) / 1024;
 
1210
                    fraction = unsigned(size) % 1024;
1195
1211
                }
1196
1212
                if (format) {
1197
1213
                    char buf[200];
1247
1263
            case CMD_freq:
1248
1264
                try {
1249
1265
                    value = int_to_string(mset.get_termfreq(args[0]));
1250
 
                } catch (...) {
 
1266
                } catch (const Xapian::InvalidOperationError&) {
 
1267
                    // An mset will raise this error if it's empty and not associated with
 
1268
                    // a search.
1251
1269
                    value = int_to_string(db.get_termfreq(args[0]));
1252
1270
                }
1253
1271
                break;
1456
1474
                close(fd); // FIXME: cache fds?
1457
1475
                break;
1458
1476
            }
 
1477
            case CMD_lower:
 
1478
                value = Xapian::Unicode::tolower(args[0]);
 
1479
                break;
1459
1480
            case CMD_lt:
1460
1481
                if (string_to_int(args[0]) < string_to_int(args[1]))
1461
1482
                    value = "true";
1889
1910
                }
1890
1911
                break;
1891
1912
            }
 
1913
            case CMD_upper:
 
1914
                value = Xapian::Unicode::toupper(args[0]);
 
1915
                break;
1892
1916
            case CMD_url:
1893
1917
                value = percent_encode(args[0]);
1894
1918
                break;