From bf68c5ff2aec400687b13476cbdb5a768ddab8a3 Mon Sep 17 00:00:00 2001 From: dockes Date: Thu, 28 Aug 2008 15:43:57 +0000 Subject: [PATCH] use a refcntr for the sub SearchData --- src/query/wasatorcl.cpp | 15 +++++++++++++-- src/rcldb/searchdata.h | 27 ++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/query/wasatorcl.cpp b/src/query/wasatorcl.cpp index 01fad69c..fad62345 100644 --- a/src/query/wasatorcl.cpp +++ b/src/query/wasatorcl.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.14 2008-08-26 13:47:21 dockes Exp $ (C) 2006 J.F.Dockes"; +static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.15 2008-08-28 15:43:57 dockes Exp $ (C) 2006 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -29,6 +29,7 @@ using std::list; #include "debuglog.h" #include "smallut.h" #include "rclconfig.h" +#include "refcntr.h" Rcl::SearchData *wasaStringToRcl(const string &qs, string &reason) { @@ -56,6 +57,8 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa) Rcl::SearchData *sdata = new Rcl::SearchData(wasa->m_op == WasaQuery::OP_AND ? Rcl::SCLT_AND : Rcl::SCLT_OR); + LOGDEB2(("wasaQueryToRcl: %s chain\n", wasa->m_op == WasaQuery::OP_AND ? + "AND" : "OR")); WasaQuery::subqlist_t::iterator it; Rcl::SearchDataClause *nclause; @@ -68,6 +71,8 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa) LOGINFO(("wasaQueryToRcl: found bad NULL or AND q type in list\n")); continue; case WasaQuery::OP_LEAF: + LOGDEB2(("wasaQueryToRcl: leaf clause [%s]:[%s]\n", + (*it)->m_fieldspec.c_str(), (*it)->m_value.c_str())); unsigned int mods = (unsigned int)(*it)->m_modifiers; // Special cases (mime, category, dir filter ...). Not pretty. if (!stringicmp("mime", (*it)->m_fieldspec) || @@ -123,6 +128,8 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa) break; case WasaQuery::OP_EXCL: + LOGDEB2(("wasaQueryToRcl: excl clause [%s]:[%s]\n", + (*it)->m_fieldspec.c_str(), (*it)->m_value.c_str())); if (wasa->m_op != WasaQuery::OP_AND) { LOGERR(("wasaQueryToRcl: negative clause inside OR list!\n")); continue; @@ -147,12 +154,16 @@ Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa) break; case WasaQuery::OP_OR: + LOGDEB2(("wasaQueryToRcl: OR clause [%s]:[%s]\n", + (*it)->m_fieldspec.c_str(), (*it)->m_value.c_str())); // Create a subquery. Rcl::SearchData *sub = wasaQueryToRcl(*it); if (sub == 0) { continue; } - nclause = new Rcl::SearchDataClauseSub(Rcl::SCLT_SUB, sub); + nclause = + new Rcl::SearchDataClauseSub(Rcl::SCLT_SUB, + RefCntr(sub)); if (nclause == 0) { LOGERR(("wasaQueryToRcl: out of memory\n")); return 0; diff --git a/src/rcldb/searchdata.h b/src/rcldb/searchdata.h index 7714a78b..4de091ab 100644 --- a/src/rcldb/searchdata.h +++ b/src/rcldb/searchdata.h @@ -16,7 +16,7 @@ */ #ifndef _SEARCHDATA_H_INCLUDED_ #define _SEARCHDATA_H_INCLUDED_ -/* @(#$Id: searchdata.h,v 1.15 2008-07-01 11:51:51 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: searchdata.h,v 1.16 2008-08-28 15:43:57 dockes Exp $ (C) 2004 J.F.Dockes */ /** * Structures to hold data coming almost directly from the gui @@ -29,6 +29,7 @@ #include #include "rcldb.h" +#include "refcntr.h" #ifndef NO_NAMESPACES using std::vector; @@ -151,6 +152,11 @@ protected: SearchData *m_parentSearch; bool m_haveWildCards; Modifier m_modifiers; +private: + SearchDataClause(const SearchDataClause& r) {} + SearchDataClause& operator=(const SearchDataClause& r) { + return *this; + } }; /** @@ -193,7 +199,18 @@ protected: int m_slack; }; -/** Filename search clause. */ +/** Filename search clause. This is special because term expansion is only + * performed against the XSFN terms (it's performed against the main index + * for all other fields). Else we could just use a "filename:" field + * This doesn't really make sense (either). I think we could either expand + * filenames against all terms and then select the XSFN ones, or always perform + * expansion only against the field's terms ? Anyway this doesn't hurt + * much either. + * + * There is a big advantage though in expanding only against the + * field, especially for file names, because this makes searches for + * "*xx" much faster (no need to scan the whole main index). + */ class SearchDataClauseFilename : public SearchDataClauseSimple { public: SearchDataClauseFilename(const string& txt) @@ -225,13 +242,13 @@ public: class SearchDataClauseSub : public SearchDataClause { public: // We take charge of the SearchData * and will delete it. - SearchDataClauseSub(SClType tp, SearchData *sub) + SearchDataClauseSub(SClType tp, RefCntr sub) : SearchDataClause(tp), m_sub(sub) {} - virtual ~SearchDataClauseSub() {delete m_sub; m_sub = 0;} + virtual ~SearchDataClauseSub() {} virtual bool toNativeQuery(Rcl::Db &db, void *, const string& stemlang); protected: - SearchData *m_sub; + RefCntr m_sub; }; } // Namespace Rcl