propagate wasa nostem modifier
This commit is contained in:
parent
b6d4fd34bd
commit
9084a6516b
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#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
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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 "rcldb.h"
|
||||||
#include "searchdata.h"
|
#include "searchdata.h"
|
||||||
#include "wasatorcl.h"
|
#include "wasatorcl.h"
|
||||||
|
#include "debuglog.h"
|
||||||
|
|
||||||
Rcl::SearchData *wasaStringToRcl(const string &qs, string &reason)
|
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);
|
Rcl::SearchData *sdata = new Rcl::SearchData(Rcl::SCLT_AND);
|
||||||
|
|
||||||
WasaQuery::subqlist_t::iterator it;
|
WasaQuery::subqlist_t::iterator it;
|
||||||
|
Rcl::SearchDataClause *nclause;
|
||||||
|
|
||||||
for (it = wasa->m_subs.begin(); it != wasa->m_subs.end(); it++) {
|
for (it = wasa->m_subs.begin(); it != wasa->m_subs.end(); it++) {
|
||||||
switch ((*it)->m_op) {
|
switch ((*it)->m_op) {
|
||||||
case WasaQuery::OP_NULL:
|
case WasaQuery::OP_NULL:
|
||||||
@ -53,16 +56,23 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
|
|||||||
continue;
|
continue;
|
||||||
case WasaQuery::OP_LEAF:
|
case WasaQuery::OP_LEAF:
|
||||||
if ((*it)->m_value.find_first_of(" \t\n\r") != string::npos) {
|
if ((*it)->m_value.find_first_of(" \t\n\r") != string::npos) {
|
||||||
sdata->addClause
|
nclause = new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE,
|
||||||
(new Rcl::SearchDataClauseDist(Rcl::SCLT_PHRASE,
|
(*it)->m_value, 0,
|
||||||
(*it)->m_value, 0,
|
(*it)->m_fieldspec);
|
||||||
(*it)->m_fieldspec));
|
|
||||||
} else {
|
} else {
|
||||||
sdata->addClause
|
nclause = new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND,
|
||||||
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND,
|
(*it)->m_value,
|
||||||
(*it)->m_value,
|
(*it)->m_fieldspec);
|
||||||
(*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;
|
break;
|
||||||
case WasaQuery::OP_EXCL:
|
case WasaQuery::OP_EXCL:
|
||||||
// Note: have to add dquotes which will be translated to
|
// 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
|
// but should work. If there is actually a single
|
||||||
// word, it will not be taken as a phrase, and
|
// word, it will not be taken as a phrase, and
|
||||||
// stem-expansion will work normally
|
// stem-expansion will work normally
|
||||||
sdata->addClause
|
nclause = new Rcl::SearchDataClauseSimple(Rcl::SCLT_EXCL,
|
||||||
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_EXCL,
|
string("\"") +
|
||||||
string("\"") +
|
(*it)->m_value + "\"",
|
||||||
(*it)->m_value + "\"",
|
(*it)->m_fieldspec);
|
||||||
(*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;
|
break;
|
||||||
case WasaQuery::OP_OR:
|
case WasaQuery::OP_OR:
|
||||||
// Concatenate all OR values as phrases. Hope there are no
|
// 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;
|
string orvalue;
|
||||||
WasaQuery::subqlist_t::iterator orit;
|
WasaQuery::subqlist_t::iterator orit;
|
||||||
@ -86,20 +105,19 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa)
|
|||||||
orit != (*it)->m_subs.end(); orit++) {
|
orit != (*it)->m_subs.end(); orit++) {
|
||||||
orvalue += string("\"") + (*orit)->m_value + "\" ";
|
orvalue += string("\"") + (*orit)->m_value + "\" ";
|
||||||
}
|
}
|
||||||
sdata->addClause
|
nclause = new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR,
|
||||||
(new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR,
|
orvalue,
|
||||||
orvalue,
|
(*it)->m_fieldspec);
|
||||||
(*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;
|
return sdata;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.12 2007-01-29 13:51:08 dockes Exp $ (C) 2006 J.F.Dockes";
|
static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.13 2007-02-13 10:58:31 dockes Exp $ (C) 2006 J.F.Dockes";
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -310,10 +310,10 @@ static void addPrefix(list<string>& terms, const string& prefix)
|
|||||||
* count)
|
* count)
|
||||||
*/
|
*/
|
||||||
bool StringToXapianQ::processUserString(const string &iq,
|
bool StringToXapianQ::processUserString(const string &iq,
|
||||||
const string &prefix,
|
const string &prefix,
|
||||||
string &ermsg,
|
string &ermsg,
|
||||||
list<Xapian::Query> &pqueries,
|
list<Xapian::Query> &pqueries,
|
||||||
int slack, bool useNear)
|
int slack, bool useNear)
|
||||||
{
|
{
|
||||||
LOGDEB(("StringToXapianQ:: query string: [%s]\n", iq.c_str()));
|
LOGDEB(("StringToXapianQ:: query string: [%s]\n", iq.c_str()));
|
||||||
ermsg.erase();
|
ermsg.erase();
|
||||||
@ -400,8 +400,8 @@ bool StringToXapianQ::processUserString(const string &iq,
|
|||||||
// Some version of xapian will accept only one OR clause
|
// Some version of xapian will accept only one OR clause
|
||||||
// inside NEAR, all others must be leafs
|
// inside NEAR, all others must be leafs
|
||||||
bool nostemexp =
|
bool nostemexp =
|
||||||
(op == Xapian::Query::OP_PHRASE || hadmultiple) ?
|
op == Xapian::Query::OP_PHRASE || hadmultiple;
|
||||||
true : false;
|
|
||||||
string sterm;
|
string sterm;
|
||||||
list<string>exp;
|
list<string>exp;
|
||||||
stripExpandTerm(nostemexp, *it, exp, sterm);
|
stripExpandTerm(nostemexp, *it, exp, sterm);
|
||||||
@ -472,10 +472,15 @@ static string fieldToPrefix(const string& i_field)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const string nullstemlang;
|
||||||
|
|
||||||
// Translate a simple OR, AND, or EXCL search clause.
|
// Translate a simple OR, AND, or EXCL search clause.
|
||||||
bool SearchDataClauseSimple::toNativeQuery(Rcl::Db &db, void *p,
|
bool SearchDataClauseSimple::toNativeQuery(Rcl::Db &db, void *p,
|
||||||
const string& stemlang)
|
const string& stemlang)
|
||||||
{
|
{
|
||||||
|
const string& l_stemlang = (m_modifiers&SDCM_NOSTEMMING)? nullstemlang:
|
||||||
|
stemlang;
|
||||||
|
|
||||||
m_terms.clear();
|
m_terms.clear();
|
||||||
m_groups.clear();
|
m_groups.clear();
|
||||||
Xapian::Query *qp = (Xapian::Query *)p;
|
Xapian::Query *qp = (Xapian::Query *)p;
|
||||||
@ -502,7 +507,7 @@ bool SearchDataClauseSimple::toNativeQuery(Rcl::Db &db, void *p,
|
|||||||
(m_parentSearch && !m_parentSearch->haveWildCards()) ||
|
(m_parentSearch && !m_parentSearch->haveWildCards()) ||
|
||||||
(m_parentSearch == 0 && !m_haveWildCards);
|
(m_parentSearch == 0 && !m_haveWildCards);
|
||||||
|
|
||||||
StringToXapianQ tr(db, stemlang, doBoostUserTerm);
|
StringToXapianQ tr(db, l_stemlang, doBoostUserTerm);
|
||||||
if (!tr.processUserString(m_text, prefix, m_reason, pqueries))
|
if (!tr.processUserString(m_text, prefix, m_reason, pqueries))
|
||||||
return false;
|
return false;
|
||||||
if (pqueries.empty()) {
|
if (pqueries.empty()) {
|
||||||
@ -516,7 +521,7 @@ bool SearchDataClauseSimple::toNativeQuery(Rcl::Db &db, void *p,
|
|||||||
|
|
||||||
// Translate a FILENAME search clause.
|
// Translate a FILENAME search clause.
|
||||||
bool SearchDataClauseFilename::toNativeQuery(Rcl::Db &db, void *p,
|
bool SearchDataClauseFilename::toNativeQuery(Rcl::Db &db, void *p,
|
||||||
const string& stemlang)
|
const string&)
|
||||||
{
|
{
|
||||||
Xapian::Query *qp = (Xapian::Query *)p;
|
Xapian::Query *qp = (Xapian::Query *)p;
|
||||||
*qp = Xapian::Query();
|
*qp = Xapian::Query();
|
||||||
@ -532,6 +537,8 @@ bool SearchDataClauseFilename::toNativeQuery(Rcl::Db &db, void *p,
|
|||||||
bool SearchDataClauseDist::toNativeQuery(Rcl::Db &db, void *p,
|
bool SearchDataClauseDist::toNativeQuery(Rcl::Db &db, void *p,
|
||||||
const string& stemlang)
|
const string& stemlang)
|
||||||
{
|
{
|
||||||
|
const string& l_stemlang = (m_modifiers&SDCM_NOSTEMMING)? nullstemlang:
|
||||||
|
stemlang;
|
||||||
LOGDEB(("SearchDataClauseDist::toNativeQuery\n"));
|
LOGDEB(("SearchDataClauseDist::toNativeQuery\n"));
|
||||||
m_terms.clear();
|
m_terms.clear();
|
||||||
m_groups.clear();
|
m_groups.clear();
|
||||||
@ -562,7 +569,7 @@ bool SearchDataClauseDist::toNativeQuery(Rcl::Db &db, void *p,
|
|||||||
}
|
}
|
||||||
string s = string("\"") + m_text + string("\"");
|
string s = string("\"") + m_text + string("\"");
|
||||||
bool useNear = (m_tp == SCLT_NEAR);
|
bool useNear = (m_tp == SCLT_NEAR);
|
||||||
StringToXapianQ tr(db, stemlang, doBoostUserTerm);
|
StringToXapianQ tr(db, l_stemlang, doBoostUserTerm);
|
||||||
if (!tr.processUserString(s, prefix, m_reason, pqueries, m_slack, useNear))
|
if (!tr.processUserString(s, prefix, m_reason, pqueries, m_slack, useNear))
|
||||||
return false;
|
return false;
|
||||||
if (pqueries.empty()) {
|
if (pqueries.empty()) {
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
#ifndef _SEARCHDATA_H_INCLUDED_
|
#ifndef _SEARCHDATA_H_INCLUDED_
|
||||||
#define _SEARCHDATA_H_INCLUDED_
|
#define _SEARCHDATA_H_INCLUDED_
|
||||||
/* @(#$Id: searchdata.h,v 1.9 2007-01-25 15:50:54 dockes Exp $ (C) 2004 J.F.Dockes */
|
/* @(#$Id: searchdata.h,v 1.10 2007-02-13 10:58:32 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structures to hold data coming almost directly from the gui
|
* Structures to hold data coming almost directly from the gui
|
||||||
@ -121,28 +121,37 @@ private:
|
|||||||
|
|
||||||
class SearchDataClause {
|
class SearchDataClause {
|
||||||
public:
|
public:
|
||||||
SearchDataClause(SClType tp) : m_tp(tp), m_parentSearch(0) {}
|
SearchDataClause(SClType tp)
|
||||||
|
: m_tp(tp), m_parentSearch(0), m_modifiers(SDCM_NONE)
|
||||||
|
{}
|
||||||
|
|
||||||
virtual ~SearchDataClause() {}
|
virtual ~SearchDataClause() {}
|
||||||
|
|
||||||
virtual bool toNativeQuery(Rcl::Db &db, void *, const string&) = 0;
|
virtual bool toNativeQuery(Rcl::Db &db, void *, const string&) = 0;
|
||||||
|
|
||||||
virtual bool isFileName() const {return m_tp==SCLT_FILENAME ? true: false;}
|
bool isFileName() const {return m_tp==SCLT_FILENAME ? true: false;}
|
||||||
|
|
||||||
virtual string getReason() const {return m_reason;}
|
virtual string getReason() const {return m_reason;}
|
||||||
|
|
||||||
virtual bool getTerms(vector<string>&, vector<vector<string> >&,
|
virtual bool getTerms(vector<string>&, vector<vector<string> >&,
|
||||||
vector<int>&) const
|
vector<int>&) const
|
||||||
{return true;}
|
{return true;}
|
||||||
virtual SClType getTp() {return m_tp;}
|
|
||||||
|
|
||||||
virtual void setParent(SearchData *p) {m_parentSearch = p;}
|
SClType getTp() {return m_tp;}
|
||||||
|
|
||||||
|
void setParent(SearchData *p) {m_parentSearch = p;}
|
||||||
|
|
||||||
friend class SearchData;
|
friend class SearchData;
|
||||||
|
|
||||||
|
enum Modifier {SDCM_NONE=0, SDCM_NOSTEMMING=1};
|
||||||
|
virtual void setModifiers(Modifier mod) {m_modifiers = mod;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
string m_reason;
|
string m_reason;
|
||||||
SClType m_tp;
|
SClType m_tp;
|
||||||
SearchData *m_parentSearch;
|
SearchData *m_parentSearch;
|
||||||
bool m_haveWildCards;
|
bool m_haveWildCards;
|
||||||
|
Modifier m_modifiers;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user