~ubuntu-branches/ubuntu/quantal/ruby-ferret/quantal

« back to all changes in this revision

Viewing changes to ext/q_prefix.c

  • Committer: Package Import Robot
  • Author(s): Cédric Boutillier
  • Date: 2012-06-14 23:04:48 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20120614230448-wd5se4ia1yz7dvms
Tags: 0.11.8.4+debian-1
* New upstream version from a new source
  + the new code fixes format security issues (Closes: #672069)
  + change homepage to https://github.com/jkraemer/ferret/
* Build for all Ruby versions (Closes: #655636)
  + change depends accordingly
  + do not set shebang of bin/ferret to ruby1.8
* Repack source to remove convenience copy of bzlib
  + build-dep on libbz2-dev
  + dversionmangle in debian/watch
  + add debian/README.source explaining how to clean the source
* debian/patches:
  + disable_load_path_manipulation.patch: do not override $LOAD_PATH
  + disable_test_causing_segfault.patch: temporarily disable a test known to
    cause segfaults
  + fix_compatibility_with_minitest.patch: fix a failing test with Ruby1.9
  + use_system_bzlib.patch: adapt the source to use system libbz2
  + fix_typos_in_source_code.patch: correct some spelling errors in the
    source code
  + block_variables_have_local_scopes.patch: fix syntax in
    bin/ferret-browser
* Override dh_auto_clean to remove test/temp when cleaning
* Bump Standards-Version to 3.9.3 (no changes needed)
* Set priority of transitional packages to extra
* Add myself to Uploaders:
* Update copyright to DEP-5 copyright-format/1.0
* Add TUTORIAL and debian/README.source to documents
* Override lintian warnings about duplicate descriptions of transitional
  packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include <string.h>
2
2
#include "search.h"
 
3
#include "symbol.h"
 
4
#include "internal.h"
3
5
 
4
6
/****************************************************************************
5
7
 *
9
11
 
10
12
#define PfxQ(query) ((PrefixQuery *)(query))
11
13
 
12
 
static char *prq_to_s(Query *self, const char *current_field) 
 
14
static char *prq_to_s(Query *self, Symbol default_field)
13
15
{
14
16
    char *buffer, *bptr;
15
17
    const char *prefix = PfxQ(self)->prefix;
16
 
    const char *field = PfxQ(self)->field;
17
18
    size_t plen = strlen(prefix);
18
 
    size_t flen = strlen(field);
 
19
    size_t flen = sym_len(PfxQ(self)->field);
19
20
 
20
21
    bptr = buffer = ALLOC_N(char, plen + flen + 35);
21
22
 
22
 
    if (strcmp(field, current_field) != 0) {
23
 
        sprintf(bptr, "%s:", field);
24
 
        bptr += flen + 1;
 
23
    if (PfxQ(self)->field != default_field) {
 
24
        bptr += sprintf(bptr, "%s:", S(PfxQ(self)->field));
25
25
    }
26
26
 
27
 
    sprintf(bptr, "%s*", prefix);
28
 
    bptr += plen + 1;
 
27
    bptr += sprintf(bptr, "%s*", prefix);
29
28
    if (self->boost != 1.0) {
30
29
        *bptr = '^';
31
30
        dbl_to_s(++bptr, self->boost);
36
35
 
37
36
static Query *prq_rewrite(Query *self, IndexReader *ir)
38
37
{
39
 
    const char *field = PfxQ(self)->field;
40
 
    const int field_num = fis_get_field_num(ir->fis, field);
41
 
    Query *volatile q = multi_tq_new_conf(field, MTQMaxTerms(self), 0.0);
 
38
    const int field_num = fis_get_field_num(ir->fis, PfxQ(self)->field);
 
39
    Query *volatile q = multi_tq_new_conf(PfxQ(self)->field,
 
40
                                          MTQMaxTerms(self), 0.0);
42
41
    q->boost = self->boost;        /* set the boost */
43
42
 
44
43
    if (field_num >= 0) {
48
47
        size_t prefix_len = strlen(prefix);
49
48
 
50
49
        TRY
51
 
            do { 
 
50
            do {
52
51
                if (strncmp(term, prefix, prefix_len) != 0) {
53
52
                    break;
54
53
                }
64
63
 
65
64
static void prq_destroy(Query *self)
66
65
{
67
 
    free(PfxQ(self)->field);
68
66
    free(PfxQ(self)->prefix);
69
67
    q_destroy_i(self);
70
68
}
71
69
 
72
70
static unsigned long prq_hash(Query *self)
73
71
{
74
 
    return str_hash(PfxQ(self)->field) ^ str_hash(PfxQ(self)->prefix);
 
72
    return sym_hash(PfxQ(self)->field) ^ str_hash(PfxQ(self)->prefix);
75
73
}
76
74
 
77
75
static int prq_eq(Query *self, Query *o)
78
76
{
79
 
    return (strcmp(PfxQ(self)->prefix, PfxQ(o)->prefix) == 0) 
80
 
        && (strcmp(PfxQ(self)->field,  PfxQ(o)->field) == 0);
 
77
    return (strcmp(PfxQ(self)->prefix, PfxQ(o)->prefix) == 0)
 
78
        && (PfxQ(self)->field == PfxQ(o)->field);
81
79
}
82
80
 
83
 
Query *prefixq_new(const char *field, const char *prefix)
 
81
Query *prefixq_new(Symbol field, const char *prefix)
84
82
{
85
83
    Query *self = q_new(PrefixQuery);
86
84
 
87
 
    PfxQ(self)->field       = estrdup(field);
 
85
    PfxQ(self)->field       = field;
88
86
    PfxQ(self)->prefix      = estrdup(prefix);
89
87
    MTQMaxTerms(self)       = PREFIX_QUERY_MAX_TERMS;
90
88