diff --git a/src/query/wasastringtoquery.cpp b/src/query/wasastringtoquery.cpp index cf815af2..b47e64da 100644 --- a/src/query/wasastringtoquery.cpp +++ b/src/query/wasastringtoquery.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: wasastringtoquery.cpp,v 1.2 2006-12-08 10:54:38 dockes Exp $ (C) 2006 J.F.Dockes"; +static char rcsid[] = "@(#$Id: wasastringtoquery.cpp,v 1.3 2006-12-10 17:03:08 dockes Exp $ (C) 2006 J.F.Dockes"; #endif /* * This program is free software; you can redistribute it and/or modify @@ -36,6 +36,30 @@ WasaQuery::~WasaQuery() void WasaQuery::describe(string &desc) const { + if (!m_types.empty()) { + desc += "type_restrict("; + for (vector::const_iterator it = m_types.begin(); + it != m_types.end(); it++) { + desc += *it + ", "; + } + desc.erase(desc.size() - 2); + desc += ")"; + } + if (m_sortSpec.size() > 1 || + (m_sortSpec.size() == 1 && m_sortSpec[0] != WQSK_REL)) { + desc += "sort_by("; + for (vector::const_iterator it = m_sortSpec.begin(); + it != m_sortSpec.end(); it++) { + switch (*it) { + case WQSK_DATE: desc += string("date") + ", ";break; + case WQSK_ALPHA: desc += string("name") + ", ";break; + case WQSK_GROUP: desc += string("group") + ", ";break; + case WQSK_REL: default: desc += string("relevance") + ", ";break; + } + } + desc.erase(desc.size() - 2); + desc += ")"; + } desc += "("; switch (m_op) { case OP_NULL: @@ -268,7 +292,49 @@ StringToWasaQuery::Internal::stringToQuery(const string& str, string& reason) // Isolated +- or fieldname: without a value. Ignore until // told otherwise. delete nclause; - return 0; + goto nextfield; + } + + // Field indicator ? + if (checkSubMatch(SMI_FIELD, match, reason)) { + // Check for special fields + if (match == string("mime")) { + if (query->m_typeKind == WasaQuery::WQTK_NONE) + query->m_typeKind = WasaQuery::WQTK_MIME; + if (query->m_typeKind == WasaQuery::WQTK_MIME) + query->m_types.push_back(nclause->m_value); + delete nclause; + goto nextfield; + } else if (match == string("group")) { + if (query->m_typeKind == WasaQuery::WQTK_NONE) + query->m_typeKind = WasaQuery::WQTK_GROUP; + if (query->m_typeKind == WasaQuery::WQTK_GROUP) + query->m_types.push_back(nclause->m_value); + delete nclause; + goto nextfield; + } else if (match == string("filetype") || + match == string("ext")) { + if (query->m_typeKind == WasaQuery::WQTK_NONE) + query->m_typeKind = WasaQuery::WQTK_EXT; + if (query->m_typeKind == WasaQuery::WQTK_EXT) + query->m_types.push_back(nclause->m_value); + delete nclause; + goto nextfield; + } else if (match == string("sort")) { + if (nclause->m_value == "score") { + query->m_sortSpec.push_back(WasaQuery::WQSK_REL); + } else if (nclause->m_value == "date") { + query->m_sortSpec.push_back(WasaQuery::WQSK_DATE); + } else if (nclause->m_value == "alpha") { + query->m_sortSpec.push_back(WasaQuery::WQSK_ALPHA); + } else if (nclause->m_value == "group") { + query->m_sortSpec.push_back(WasaQuery::WQSK_GROUP); + } + delete nclause; + goto nextfield; + } else { + nclause->m_fieldspec = match; + } } // +- indicator ? @@ -278,10 +344,6 @@ StringToWasaQuery::Internal::stringToQuery(const string& str, string& reason) nclause->m_op = WasaQuery::OP_LEAF; } - // Field indicator ? - if (checkSubMatch(SMI_FIELD, match, reason)) { - nclause->m_fieldspec = match; - } if (prev_or) { // We're in an OR subquery, add new subquery @@ -298,6 +360,7 @@ StringToWasaQuery::Internal::stringToQuery(const string& str, string& reason) prev_or = false; } + nextfield: // Advance current string position. We checked earlier that // the increment is strictly positive, so we won't loop // forever diff --git a/src/query/wasastringtoquery.h b/src/query/wasastringtoquery.h index dd765f19..54ac950b 100644 --- a/src/query/wasastringtoquery.h +++ b/src/query/wasastringtoquery.h @@ -1,6 +1,6 @@ #ifndef _WASASTRINGTOQUERY_H_INCLUDED_ #define _WASASTRINGTOQUERY_H_INCLUDED_ -/* @(#$Id: wasastringtoquery.h,v 1.2 2006-12-08 10:54:38 dockes Exp $ (C) 2006 J.F.Dockes */ +/* @(#$Id: wasastringtoquery.h,v 1.3 2006-12-10 17:03:08 dockes Exp $ (C) 2006 J.F.Dockes */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,20 +35,31 @@ public: enum Op {OP_NULL, OP_LEAF, OP_EXCL, OP_OR, OP_AND}; typedef vector subqlist_t; - WasaQuery() : m_op(OP_NULL) {} + WasaQuery() + : m_op(OP_NULL), m_typeKind(WQTK_NONE) + {} ~WasaQuery(); // Get string describing the query tree from this point void describe(string &desc) const; - WasaQuery::Op m_op; - string m_fieldspec; + WasaQuery::Op m_op; + string m_fieldspec; /* Valid for op == OP_LEAF */ - string m_value; + string m_value; /* Valid for conjunctions */ - vector m_subs; -}; + vector m_subs; + + /* Restrict results to some file type, defined by either mime, app group, + * or extension */ + enum TypeKind {WQTK_NONE, WQTK_MIME, WQTK_GROUP, WQTK_EXT}; + TypeKind m_typeKind; + vector m_types; + /* Sort on relevance, date, name or group */ + enum SortKind {WQSK_REL, WQSK_DATE, WQSK_ALPHA, WQSK_GROUP}; + vector m_sortSpec; +}; /** * Wasabi query string parser class. Could be a simple function diff --git a/src/query/wasatorcl.cpp b/src/query/wasatorcl.cpp index 9ec86545..58a336b5 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.1 2006-11-30 18:12:16 dockes Exp $ (C) 2006 J.F.Dockes"; +static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.2 2006-12-10 17:03:08 dockes Exp $ (C) 2006 J.F.Dockes"; #endif #ifndef TEST_WASATORCL @@ -8,7 +8,7 @@ static char rcsid[] = "@(#$Id: wasatorcl.cpp,v 1.1 2006-11-30 18:12:16 dockes Ex #include "searchdata.h" #include "wasatorcl.h" -Rcl::SearchData *wasatorcl(WasaQuery *wasa) +Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa) { if (wasa == 0) return 0; @@ -60,6 +60,13 @@ Rcl::SearchData *wasatorcl(WasaQuery *wasa) } } + // File type and sort specs. We only know about mime types for now. + if (wasa->m_typeKind == WasaQuery::WQTK_MIME) { + for (vector::const_iterator it = wasa->m_types.begin(); + it != wasa->m_types.end(); it++) { + sdata->addFiletype(*it); + } + } return sdata; } diff --git a/src/query/wasatorcl.h b/src/query/wasatorcl.h index e7acd1d7..d6211877 100644 --- a/src/query/wasatorcl.h +++ b/src/query/wasatorcl.h @@ -1,10 +1,13 @@ #ifndef _WASATORCL_H_INCLUDED_ #define _WASATORCL_H_INCLUDED_ -/* @(#$Id: wasatorcl.h,v 1.2 2006-12-08 17:18:34 dockes Exp $ (C) 2006 J.F.Dockes */ +/* @(#$Id: wasatorcl.h,v 1.3 2006-12-10 17:03:08 dockes Exp $ (C) 2006 J.F.Dockes */ + +#include +using std::string; #include "rcldb.h" #include "searchdata.h" -extern Rcl::SearchData *wasatorcl(WasaQuery *wasa); +extern Rcl::SearchData *wasaQueryToRcl(WasaQuery *wasa); #endif /* _WASATORCL_H_INCLUDED_ */