~ubuntu-branches/ubuntu/trusty/swish-e/trusty-proposed

« back to all changes in this revision

Viewing changes to src/search.c

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Drolez
  • Date: 2009-11-05 16:23:33 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20091105162333-9xf7dmhhhvt97bvw
Tags: 2.4.7-1
* New upstream release
* Added Japanese and Russian debconf translations. Closes: #543187, #512987

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
$Id: search.c,v 1.148 2006/10/18 15:07:51 karman Exp $
 
2
$Id: search.c 2291 2009-03-31 01:56:00Z karpet $
3
3
**
4
4
** Copyright (C) 1995, 1996, 1997, 1998 Hewlett-Packard Company
5
5
** Originally by Kevin Hughes, kev@kevcom.com, 3/11/94
142
142
 
143
143
#include "rank.h"
144
144
 
145
 
 
146
145
/* ------ static fucntions ----------- */
147
146
static int init_sort_propIDs( DB_RESULTS *db_results, struct swline *sort_word, DB_RESULTS *last );
148
147
static void query_index( DB_RESULTS *db_results );
175
174
 
176
175
void SwishRankScheme(SWISH *sw, int scheme)
177
176
{
178
 
        
179
177
    sw->RankScheme = scheme;
180
 
    
181
 
}
182
 
 
 
178
}
 
179
 
 
180
 
 
181
/*********************************************************************
 
182
* SwishReturnRawRank -- return unscaled swishrank values
 
183
* karman - Mon Mar 30 20:51:02 CDT 2009
 
184
*
 
185
*********************************************************************/
 
186
 
 
187
void SwishReturnRawRank(SWISH *sw, int flag)
 
188
{
 
189
    sw->ReturnRawRank = flag;
 
190
}
183
191
 
184
192
 
185
193
 
290
298
        srch->structure = structure;
291
299
}
292
300
 
 
301
int SwishGetStructure( SEARCH_OBJECT *srch )
 
302
{
 
303
    return srch ? srch->structure : 0;
 
304
}
293
305
 
294
306
void SwishPhraseDelimiter( SEARCH_OBJECT *srch, char delimiter )
295
307
{
298
310
}
299
311
 
300
312
 
 
313
char SwishGetPhraseDelimiter(SEARCH_OBJECT *srch)
 
314
{
 
315
    return srch ? srch->PhraseDelimiter : 0;
 
316
}
 
317
 
301
318
 
302
319
void SwishSetSort( SEARCH_OBJECT *srch, char *sort )
303
320
{
1573
1590
    rLen = 0;
1574
1591
    tLen = strlen(word);
1575
1592
    // Check for first "?" in current word (not reverse)
1576
 
    if ((q = strchr(word, '?')))
 
1593
    if ((q = (unsigned char*)strchr(word, '?')))
1577
1594
    {
1578
1595
        if (q != (unsigned char*)word && *(q - 1) == '\\') /* Check for an escaped * */
1579
1596
        {
1584
1601
            /* Check if it is at the end of the word */
1585
1602
            if (q == ((unsigned char*)word + strlen(word) - 1))
1586
1603
            {
1587
 
                strcpy(remains, q);   // including the last "?"
 
1604
                strcpy(remains, (char*)q);   // including the last "?"
1588
1605
                rLen = strlen(remains);
1589
1606
                word[strlen(word) - 1] = '\0';
1590
1607
            }
1591
1608
            else
1592
1609
            {
1593
 
                strcpy(remains, q);   // including the first "?"
 
1610
                strcpy(remains, (char*)q);   // including the first "?"
1594
1611
                rLen = strlen(remains);
1595
1612
                *q = '\0';
1596
1613
            }
1631
1648
            return NULL;
1632
1649
        }
1633
1650
        else
1634
 
            strcpy(myWord, resultword);   // Remember the word
 
1651
            strcpy(myWord, (char*)resultword);   // Remember the word
1635
1652
            
1636
1653
        efree(resultword);   /* Do not need it */
1637
1654
    }
1702
1719
            if (! wordID)
1703
1720
                break;          /* no more data */
1704
1721
            else
1705
 
              strcpy(myWord, resultword);
 
1722
              strcpy(myWord, (char*)resultword);
1706
1723
 
1707
1724
            efree(resultword);  /* Do not need it (although might be useful for highlighting some day) */
1708
1725
 
1818
1835
                break;          /* no more data */
1819
1836
 
1820
1837
            else
1821
 
                strcpy(myWord, resultword); // remember the word
 
1838
                strcpy(myWord, (char*)resultword); // remember the word
1822
1839
 
1823
1840
            efree(resultword);  /* Do not need it (although might be useful for highlighting some day) */
1824
1841
        }
2266
2283
            newRank = ((r1->rank * andLevel) + r2->rank) / (andLevel + 1);
2267
2284
 
2268
2285
 
2269
 
#ifdef DEBUG_RANK
2270
 
    fprintf( stderr, "\n----\nFile num: %d  1st score: %d  2nd score: %d  andLevel: %d  newRank:  %d\n----\n", r1->filenum, r1->rank, r2->rank, andLevel, newRank );
2271
 
#endif
 
2286
            if ( DEBUG_RANK )
 
2287
            {
 
2288
                fprintf( stderr, "File num: %d  1st score: %d  2nd score: %d  andLevel: %d  newRank:  %d\n----\n", 
 
2289
                    r1->filenum, r1->rank, r2->rank, andLevel, newRank );
 
2290
            }
2272
2291
            
2273
2292
 
2274
2293
            if(!new_results_list)
2321
2340
           *tmp;
2322
2341
    RESULT_LIST *new_results_list = NULL;
2323
2342
    RESULTS_OBJECT *results = db_results->results;
2324
 
 
2325
 
 
 
2343
    /* TODO use to detect rank size overflow 
 
2344
    unsigned int max_rank_size = 256 ^ sizeof(int);
 
2345
    */
2326
2346
 
2327
2347
    /* If either list is empty, just return the other */
2328
2348
    if (l_r1 == NULL)
2352
2372
 
2353
2373
        else /* Matching file number */
2354
2374
        {
2355
 
            int result_size;
 
2375
            int result_size, r1rank, r2rank;
2356
2376
            
2357
 
            /* Create a new RESULT - Should be a function to creete this, I'd think */
 
2377
            /* Create a new RESULT - Should be a function to create this, I'd think */
2358
2378
 
2359
2379
            result_size = sizeof(RESULT) + ( (r1->frequency + r2->frequency - 1) * sizeof(int) );
2360
2380
            rp = (RESULT *) Mem_ZoneAlloc(results->resultSearchZone, result_size );
2362
2382
 
2363
2383
            rp->fi.filenum = rp->filenum = r1->filenum;
2364
2384
 
2365
 
            rp->rank = ( r1->rank + r2->rank) * 2;  /* bump up the or terms */
 
2385
            /* TODO *2 breaks sort if rank > 2^32 */
 
2386
            
 
2387
            r1rank = r1->rank;
 
2388
            r2rank = r2->rank;
 
2389
                        
 
2390
            rp->rank = ( r1rank + r2rank );  /* bump up the or terms */
2366
2391
            
2367
 
#ifdef DEBUG_RANK
2368
 
    fprintf( stderr, "\n----\nFile num: %d  1st score: %d  2nd score: %d  newRank:  %d\n----\n", r1->filenum, r1->rank, r2->rank, rp->rank );
2369
 
#endif
 
2392
            if (DEBUG_RANK)
 
2393
            {
 
2394
                fprintf( stderr, "----\nFile num: %d  1st score: %d  2nd score: %d  newRank:  %d\n", 
 
2395
                    r1->filenum, r1->rank, r2->rank, rp->rank );
 
2396
            }
2370
2397
 
2371
2398
            rp->tfrequency = 0;
2372
2399
            rp->frequency = r1->frequency + r2->frequency;