source: trunk/gsdl/src/mgpp/text/Queryer.cpp@ 926

Last change on this file since 926 was 926, checked in by kjm18, 24 years ago

added options to change index and level for searching

  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/**************************************************************************
2 *
3 * Queryer.cpp -- simple interactive query program
4 * Copyright (C) 1999 Rodger McNab
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: Queryer.cpp 926 2000-02-15 22:38:28Z kjm18 $
21 *
22 **************************************************************************/
23
24#include "MGQuery.h"
25#include "TextGet.h"
26
27#include "messages.h"
28#include "mg_files.h"
29
30#include "QueryParser.h"
31
32
33int main (int argc, char **argv) {
34 int ch;
35 char *textfilename = "";
36 char *indexfilename = "";
37 char *basePath = "";
38
39 opterr = 0;
40 msg_prefix = argv[0];
41
42 // process the command line arguments
43 while ((ch = getopt (argc, argv, "f:t:d:h")) != -1) {
44 switch (ch) {
45 case 'f': /* input file */
46 indexfilename = optarg;
47 break;
48 case 't':
49 textfilename = optarg;
50 break;
51 case 'd':
52 basePath = optarg;
53 set_basepath (basePath);
54 break;
55 case 'h':
56 case '?':
57 fprintf (stderr, "usage: %s [-h] [-d directory] -f name\n", argv[0]);
58 exit (1);
59 }
60 }
61
62 if (textfilename[0] == '\0' || indexfilename[0] == '\0') {
63 FatalError (1, "A file name must be specified with -f and -t \n");
64 }
65
66 // init the text system
67 TextData textData;
68 if (!textData.LoadData (textfilename)) {
69 FatalError (1, "Couldn't load text information for \"%s\"", textfilename);
70 }
71
72 // init the query system
73 IndexData indexData;
74 if (!indexData.LoadData (basePath, indexfilename)) {
75 FatalError (1, "Couldn't load index information for \"%s\"", indexfilename);
76 }
77
78 // do querying
79 QueryInfo queryInfo;
80 SetCStr (queryInfo.docLevel, "Document");
81 queryInfo.maxDocs = 50;
82 queryInfo.sortByRank = true;
83 queryInfo.exactWeights = false;
84 queryInfo.needRankInfo = true;
85 queryInfo.needTermFreqs = true;
86
87 ExtQueryResult queryResult;
88 char query[2048];
89 UCArray queryArray;
90 QueryNode *queryTree = NULL;
91
92 UCArray level;
93 level.clear();
94 //SetCStr(level, "");
95
96
97 while (true) {
98 // cerr << "getting next line\n";
99 cout << "> ";
100 cin.getline(query, 2048, '\n');
101 SetCStr (queryArray, query);
102
103 // check for commands
104 if (queryArray.size() >= 2 && queryArray[0] == '.') {
105 if (queryArray[1] == 'q') break; // quit
106
107
108 if (queryArray[1] == 'i') {
109 cout << "current index="<< queryInfo.docLevel << "\nchange to index:";
110 cin >> query;
111 queryInfo.docLevel.clear();
112 SetCStr(queryInfo.docLevel, query);
113 cout << "index set to " << queryInfo.docLevel <<"\n";
114 cin.getline(query, 2048, '\n');
115 }
116 if (queryArray[1] == 'l') {
117 cout << "current level="<< level << "\nchange to level:";
118 cin >> query;
119 level.clear();
120 SetCStr(level, query);
121 cout << "level set to " << level <<"\n";
122 cin.getline(query, 2048, '\n');
123 }
124
125
126 else if (queryArray[1] == 'p') {
127 // print
128 UCArray docText;
129 unsigned long docNum = 0;
130 cin >> docNum;
131 cin.getline(query, 2048, '\n'); // eat up return
132
133 if (!GetDocText (textData, queryInfo.docLevel, docNum, docText)) {
134 FatalError (1, "Error while trying to get document %u", docNum);
135 }
136
137 cout << docText << "\n";
138 }
139
140 } else {
141 // regular query
142 queryTree = ParseQuery (queryArray);
143
144 // print the query
145 PrintNode (cout, queryTree);
146
147 MGQuery (indexData, queryInfo, queryTree, queryResult, level);
148 cout << queryResult;
149 cout << "\n";
150
151 // delete the query
152 if (queryTree != NULL) delete queryTree;
153 queryTree = NULL;
154 }
155 }
156
157
158 // clean up, everybody clean up
159 textData.UnloadData ();
160 indexData.UnloadData ();
161}
162
Note: See TracBrowser for help on using the repository browser.