|
a/src/query/wasatorcl.cpp |
|
b/src/query/wasatorcl.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.7 2007-02-07 12:00:17 dockes Exp $ (C) 2006 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.8 2007-02-13 10:58:31 dockes Exp $ (C) 2006 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
19 |
*/
|
19 |
*/
|
20 |
#include "wasastringtoquery.h"
|
20 |
#include "wasastringtoquery.h"
|
21 |
#include "rcldb.h"
|
21 |
#include "rcldb.h"
|
22 |
#include "searchdata.h"
|
22 |
#include "searchdata.h"
|
23 |
#include "wasatorcl.h"
|
23 |
#include "wasatorcl.h"
|
|
|
24 |
#include "debuglog.h"
|
24 |
|
25 |
|
25 |
Rcl::SearchData *wasaStringToRcl(const string &qs, string &reason)
|
26 |
Rcl::SearchData *wasaStringToRcl(const string &qs, string &reason)
|
26 |
{
|
27 |
{
|
27 |
StringToWasaQuery parser;
|
28 |
StringToWasaQuery parser;
|
28 |
WasaQuery *wq = parser.stringToQuery(qs, reason);
|
29 |
WasaQuery *wq = parser.stringToQuery(qs, reason);
|
|
... |
|
... |
42 |
return 0;
|
43 |
return 0;
|
43 |
|
44 |
|
44 |
Rcl::SearchData *sdata = new Rcl::SearchData(Rcl::SCLT_AND);
|
45 |
Rcl::SearchData *sdata = new Rcl::SearchData(Rcl::SCLT_AND);
|
45 |
|
46 |
|
46 |
WasaQuery::subqlist_t::iterator it;
|
47 |
WasaQuery::subqlist_t::iterator it;
|
|
|
48 |
Rcl::SearchDataClause *nclause;
|
|
|
49 |
|
47 |
for (it = wasa->m_subs.begin(); it != wasa->m_subs.end(); it++) {
|
50 |
for (it = wasa->m_subs.begin(); it != wasa->m_subs.end(); it++) {
|
48 |
switch ((*it)->m_op) {
|
51 |
switch ((*it)->m_op) {
|
49 |
case WasaQuery::OP_NULL:
|
52 |
case WasaQuery::OP_NULL:
|
50 |
case WasaQuery::OP_AND:
|
53 |
case WasaQuery::OP_AND:
|
51 |
default:
|
54 |
default:
|
52 |
// ??
|
55 |
// ??
|
53 |
continue;
|
56 |
continue;
|
54 |
case WasaQuery::OP_LEAF:
|
57 |
case WasaQuery::OP_LEAF:
|
55 |
if ((*it)->m_value.find_first_of(" \t\n\r") != string::npos) {
|
58 |
if ((*it)->m_value.find_first_of(" \t\n\r") != string::npos) {
|
56 |
sdata->addClause
|
|
|
57 |
(new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE,
|
59 |
nclause = new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE,
|
58 |
(*it)->m_value, 0,
|
60 |
(*it)->m_value, 0,
|
59 |
(*it)->m_fieldspec));
|
61 |
(*it)->m_fieldspec);
|
60 |
} else {
|
62 |
} else {
|
61 |
sdata->addClause
|
|
|
62 |
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND,
|
63 |
nclause = new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND,
|
63 |
(*it)->m_value,
|
64 |
(*it)->m_value,
|
64 |
(*it)->m_fieldspec));
|
65 |
(*it)->m_fieldspec);
|
65 |
}
|
66 |
}
|
|
|
67 |
if (nclause == 0) {
|
|
|
68 |
LOGERR(("wasaQueryToRcl: out of memory\n"));
|
|
|
69 |
return 0;
|
|
|
70 |
}
|
|
|
71 |
if ((*it)->m_modifiers & WasaQuery::WQM_NOSTEM) {
|
|
|
72 |
fprintf(stderr, "Setting NOSTEM\n");
|
|
|
73 |
nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING);
|
|
|
74 |
}
|
|
|
75 |
sdata->addClause(nclause);
|
66 |
break;
|
76 |
break;
|
67 |
case WasaQuery::OP_EXCL:
|
77 |
case WasaQuery::OP_EXCL:
|
68 |
// Note: have to add dquotes which will be translated to
|
78 |
// Note: have to add dquotes which will be translated to
|
69 |
// phrase if there are several words in there. Not pretty
|
79 |
// phrase if there are several words in there. Not pretty
|
70 |
// but should work. If there is actually a single
|
80 |
// but should work. If there is actually a single
|
71 |
// word, it will not be taken as a phrase, and
|
81 |
// word, it will not be taken as a phrase, and
|
72 |
// stem-expansion will work normally
|
82 |
// stem-expansion will work normally
|
73 |
sdata->addClause
|
|
|
74 |
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_EXCL,
|
83 |
nclause = new Rcl::SearchDataClauseSimple(Rcl::SCLT_EXCL,
|
75 |
string("\"") +
|
84 |
string("\"") +
|
76 |
(*it)->m_value + "\"",
|
85 |
(*it)->m_value + "\"",
|
77 |
(*it)->m_fieldspec));
|
86 |
(*it)->m_fieldspec);
|
|
|
87 |
|
|
|
88 |
if (nclause == 0) {
|
|
|
89 |
LOGERR(("wasaQueryToRcl: out of memory\n"));
|
|
|
90 |
return 0;
|
|
|
91 |
}
|
|
|
92 |
if ((*it)->m_modifiers & WasaQuery::WQM_NOSTEM)
|
|
|
93 |
nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING);
|
|
|
94 |
sdata->addClause(nclause);
|
78 |
break;
|
95 |
break;
|
79 |
case WasaQuery::OP_OR:
|
96 |
case WasaQuery::OP_OR:
|
80 |
// Concatenate all OR values as phrases. Hope there are no
|
97 |
// Concatenate all OR values as phrases. Hope there are no
|
81 |
// stray dquotes in there
|
98 |
// stray dquotes in there. Note that single terms won't be
|
|
|
99 |
// handled as real phrases inside searchdata.cpp (so the
|
|
|
100 |
// added dquotes won't interfer with stemming)
|
82 |
{
|
101 |
{
|
83 |
string orvalue;
|
102 |
string orvalue;
|
84 |
WasaQuery::subqlist_t::iterator orit;
|
103 |
WasaQuery::subqlist_t::iterator orit;
|
85 |
for (orit = (*it)->m_subs.begin();
|
104 |
for (orit = (*it)->m_subs.begin();
|
86 |
orit != (*it)->m_subs.end(); orit++) {
|
105 |
orit != (*it)->m_subs.end(); orit++) {
|
87 |
orvalue += string("\"") + (*orit)->m_value + "\" ";
|
106 |
orvalue += string("\"") + (*orit)->m_value + "\" ";
|
88 |
}
|
107 |
}
|
89 |
sdata->addClause
|
|
|
90 |
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR,
|
108 |
nclause = new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR,
|
91 |
orvalue,
|
109 |
orvalue,
|
92 |
(*it)->m_fieldspec));
|
110 |
(*it)->m_fieldspec);
|
|
|
111 |
if (nclause == 0) {
|
|
|
112 |
LOGERR(("wasaQueryToRcl: out of memory\n"));
|
|
|
113 |
return 0;
|
|
|
114 |
}
|
|
|
115 |
if ((*it)->m_modifiers & WasaQuery::WQM_NOSTEM)
|
|
|
116 |
nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING);
|
|
|
117 |
sdata->addClause(nclause);
|
93 |
}
|
118 |
}
|
94 |
}
|
119 |
}
|
95 |
}
|
120 |
}
|
96 |
|
121 |
|
97 |
// File type and sort specs. We only know about mime types for now.
|
|
|
98 |
if (wasa->m_typeKind == WasaQuery::WQTK_MIME) {
|
|
|
99 |
for (vector<string>::const_iterator it = wasa->m_types.begin();
|
|
|
100 |
it != wasa->m_types.end(); it++) {
|
|
|
101 |
sdata->addFiletype(*it);
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
return sdata;
|
122 |
return sdata;
|
105 |
}
|
123 |
}
|