source: main/branches/64_bit_Greenstone/greenstone2/common-src/indexers/mg/src/text/query.docnums.c@ 23508

Last change on this file since 23508 was 23508, checked in by sjm84, 13 years ago

Committing 64 bit changes into the branch

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1/**************************************************************************
2 *
3 * query.docnums.c -- Docnums query evaluation
4 * Copyright (C) 1994 Neil Sharman
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * $Id: query.docnums.c 23508 2010-12-17 01:04:10Z sjm84 $
21 *
22 **************************************************************************/
23
24#include "sysfuncs.h"
25#include "filestats.h"
26#include "timing.h"
27
28#include "mg.h"
29#include "invf.h"
30#include "text.h"
31#include "lists.h"
32#include "backend.h"
33
34
35static DocList *
36AddToDocList (DocList * Docs, int res)
37{
38 int j;
39 /* Search the list for the word */
40 for (j = 0; j < Docs->num; j++)
41 if (Docs->DE[j].DocNum == res)
42 break;
43
44 /* Increment the weight if the word is in the list */
45 if (j < Docs->num)
46 Docs->DE[j].Weight++;
47 else
48 {
49 /* Create a new entry in the list for the new document */
50 Docs = ResizeDocList (Docs, Docs->num + 1);
51 Docs->DE[Docs->num].DocNum = res;
52 Docs->DE[Docs->num].Weight = 1;
53 Docs->DE[Docs->num].SeekPos = 0;
54 Docs->DE[Docs->num].Len = 0;
55 Docs->DE[Docs->num].CompTextBuffer = NULL;
56 Docs->DE[Docs->num].Next = NULL;
57 Docs->num++;
58 }
59 return (Docs);
60}
61
62void
63DocnumsQuery (query_data * qd, char *QueryLine)
64{
65 DocList *Docs = MakeDocList (0);
66 mg_u_long start = 0, finish;
67 int range = 0; /* is there a range or not ? */
68
69 /* find the start of the first word */
70 while (*QueryLine)
71 {
72 char *end;
73 finish = strtol (QueryLine, &end, 10);
74 if (end != (char *) QueryLine && finish >= 1 &&
75 finish <= qd->sd->sdh.num_of_docs)
76 {
77 mg_u_long i;
78 if (!range)
79 start = finish;
80 else
81 range = 0;
82 for (i = start; i <= finish; i++)
83 Docs = AddToDocList (Docs, i);
84 while (*end == ' ' || *end == '\t' || *end == '\n')
85 end++;
86 if (*end == '-')
87 {
88 start = finish;
89 range = 1;
90 end++;
91 }
92 }
93 else
94 break;
95 QueryLine = end;
96 }
97 FreeQueryDocs (qd);
98
99 qd->DL = Docs;
100}
Note: See TracBrowser for help on using the repository browser.