propagate wasa nostem modifier

This commit is contained in:
dockes
2007-02-13 10:58:32 +00:00
parent b6d4fd34bd
commit 9084a6516b
3 changed files with 78 additions and 44 deletions
+44 -26
View File
@@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.7 2007-02-07 12:00:17 dockes Exp $ (C) 2006 J.F.Dockes";
static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.8 2007-02-13 10:58:31 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@@ -21,6 +21,7 @@ static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.7 2007-02-07 12:00:17 dockes Ex
#include "rcldb.h"
#include "searchdata.h"
#include "wasatorcl.h"
#include "debuglog.h"
Rcl::SearchData *wasaStringToRcl(const string &qs, string &reason)
{
@@ -44,6 +45,8 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
Rcl::SearchData *sdata = new Rcl::SearchData(Rcl::SCLT_AND);
WasaQuery::subqlist_t::iterator it;
Rcl::SearchDataClause *nclause;
for (it = wasa->m_subs.begin(); it != wasa->m_subs.end(); it++) {
switch ((*it)->m_op) {
case WasaQuery::OP_NULL:
@@ -53,16 +56,23 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
continue;
case WasaQuery::OP_LEAF:
if ((*it)->m_value.find_first_of(" \t\n\r") != string::npos) {
sdata->addClause
(new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE,
(*it)->m_value, 0,
(*it)->m_fieldspec));
nclause = new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE,
(*it)->m_value, 0,
(*it)->m_fieldspec);
} else {
sdata->addClause
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND,
(*it)->m_value,
(*it)->m_fieldspec));
nclause = new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND,
(*it)->m_value,
(*it)->m_fieldspec);
}
if (nclause == 0) {
LOGERR(("wasaQueryToRcl: out of memory\n"));
return 0;
}
if ((*it)->m_modifiers & WasaQuery::WQM_NOSTEM) {
fprintf(stderr, "Setting NOSTEM\n");
nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING);
}
sdata->addClause(nclause);
break;
case WasaQuery::OP_EXCL:
// Note: have to add dquotes which will be translated to
@@ -70,15 +80,24 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
// but should work. If there is actually a single
// word, it will not be taken as a phrase, and
// stem-expansion will work normally
sdata->addClause
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_EXCL,
string("\"") +
(*it)->m_value + "\"",
(*it)->m_fieldspec));
nclause = new Rcl::SearchDataClauseSimple(Rcl::SCLT_EXCL,
string("\"") +
(*it)->m_value + "\"",
(*it)->m_fieldspec);
if (nclause == 0) {
LOGERR(("wasaQueryToRcl: out of memory\n"));
return 0;
}
if ((*it)->m_modifiers & WasaQuery::WQM_NOSTEM)
nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING);
sdata->addClause(nclause);
break;
case WasaQuery::OP_OR:
// Concatenate all OR values as phrases. Hope there are no
// stray dquotes in there
// stray dquotes in there. Note that single terms won't be
// handled as real phrases inside searchdata.cpp (so the
// added dquotes won't interfer with stemming)
{
string orvalue;
WasaQuery::subqlist_t::iterator orit;
@@ -86,20 +105,19 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
orit != (*it)->m_subs.end(); orit++) {
orvalue += string("\"") + (*orit)->m_value + "\" ";
}
sdata->addClause
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR,
orvalue,
(*it)->m_fieldspec));
nclause = new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR,
orvalue,
(*it)->m_fieldspec);
if (nclause == 0) {
LOGERR(("wasaQueryToRcl: out of memory\n"));
return 0;
}
if ((*it)->m_modifiers & WasaQuery::WQM_NOSTEM)
nclause->setModifiers(Rcl::SearchDataClause::SDCM_NOSTEMMING);
sdata->addClause(nclause);
}
}
}
// File type and sort specs. We only know about mime types for now.
if (wasa->m_typeKind == WasaQuery::WQTK_MIME) {
for (vector<string>::const_iterator it = wasa->m_types.begin();
it != wasa->m_types.end(); it++) {
sdata->addFiletype(*it);
}
}
return sdata;
}