From 7a7e77cfae3eed9114feeda59581520bf22a8800 Mon Sep 17 00:00:00 2001 From: dockes Date: Thu, 1 Dec 2005 16:23:09 +0000 Subject: [PATCH] sorting 1st steps --- src/lib/Makefile | 7 +- src/qtgui/recoll.pro | 3 +- src/qtgui/recollmain.ui.h | 15 +++ src/qtgui/sort.ui | 199 ++++++++++++++++++++++++++++++++++++++ src/qtgui/sort.ui.h | 19 ++++ src/query/sortseq.cpp | 88 +++++++++++++++++ src/query/sortseq.h | 39 ++++++++ 7 files changed, 367 insertions(+), 3 deletions(-) create mode 100644 src/qtgui/sort.ui create mode 100644 src/qtgui/sort.ui.h create mode 100644 src/query/sortseq.cpp create mode 100644 src/query/sortseq.h diff --git a/src/lib/Makefile b/src/lib/Makefile index 9683fde3..8082055c 100644 --- a/src/lib/Makefile +++ b/src/lib/Makefile @@ -13,7 +13,8 @@ OBJS = base64.o conftree.o csguess.o debuglog.o \ mimehandler.o mimeparse.o mimetype.o myhtmlparse.o pathhash.o pathut.o \ rclconfig.o rcldb.o rclinit.o readfile.o smallut.o \ textsplit.o transcode.o \ - unacpp.o unac.o docseq.o + unacpp.o unac.o docseq.o sortseq.o + SRCS = ../utils/conftree.cpp ../index/csguess.cpp ../utils/debuglog.cpp \ ../utils/execmd.cpp ../utils/idfile.cpp ../utils/md5.cpp \ ../utils/wipedir.cpp ../utils/fstreewalk.cpp \ @@ -26,7 +27,7 @@ SRCS = ../utils/conftree.cpp ../index/csguess.cpp ../utils/debuglog.cpp \ ../utils/base64.cpp ../utils/readfile.cpp ../utils/smallut.cpp \ ../common/textsplit.cpp ../utils/transcode.cpp \ ../common/unacpp.cpp ../unac/unac.c ../query/history.cpp \ - ../query/docseq.cpp + ../query/docseq.cpp ../query/sortseq.cpp librcl.a : $(OBJS) ar ru librcl.a $(OBJS) @@ -50,6 +51,8 @@ fstreewalk.o : ../utils/fstreewalk.cpp $(CXX) $(CXXFLAGS) -c $< history.o : ../query/history.cpp $(CXX) $(CXXFLAGS) -c $< +sortseq.o : ../query/sortseq.cpp + $(CXX) $(CXXFLAGS) -c $< docseq.o : ../query/docseq.cpp $(CXX) $(CXXFLAGS) -c $< mh_html.o : ../common/mh_html.cpp diff --git a/src/qtgui/recoll.pro b/src/qtgui/recoll.pro index e11d2c43..033b4196 100644 --- a/src/qtgui/recoll.pro +++ b/src/qtgui/recoll.pro @@ -9,7 +9,8 @@ SOURCES += main.cpp \ FORMS = recollmain.ui \ advsearch.ui \ - preview/preview.ui + preview/preview.ui \ + sort.ui IMAGES = images/filenew \ images/fileopen \ diff --git a/src/qtgui/recollmain.ui.h b/src/qtgui/recollmain.ui.h index 4cbae0d1..7e4ae476 100644 --- a/src/qtgui/recollmain.ui.h +++ b/src/qtgui/recollmain.ui.h @@ -37,6 +37,7 @@ using std::pair; #include "plaintorich.h" #include "advsearch.h" #include "rclversion.h" +#include "sortseq.h" extern "C" int XFlush(void *); @@ -385,7 +386,14 @@ void RecollMain::queryText_returnPressed() if (docsource) delete docsource; +#if TRYSORT + DocSequenceDb myseq(rcldb); + RclSortSpec ss; + ss.addCrit(RclSortSpec::RCLFLD_MTIME, false); + docsource = new DocSeqSorted(myseq, 10000, ss); +#else docsource = new DocSequenceDb(rcldb); +#endif listNextPB_clicked(); } @@ -600,7 +608,14 @@ void RecollMain::startAdvSearch(Rcl::AdvSearchData sdata) curPreview = 0; if (docsource) delete docsource; +#if TRYSORT + DocSequenceDb myseq(rcldb); + RclSortSpec ss; + ss.addCrit(RclSortSpec::RCLFLD_MTIME, true); + docsource = new DocSeqSorted(myseq, 10000, ss); +#else docsource = new DocSequenceDb(rcldb); +#endif listNextPB_clicked(); } diff --git a/src/qtgui/sort.ui b/src/qtgui/sort.ui new file mode 100644 index 00000000..706d96bb --- /dev/null +++ b/src/qtgui/sort.ui @@ -0,0 +1,199 @@ + +sort + + + sort + + + + 0 + 0 + 360 + 163 + + + + Form1 + + + + layout2 + + + + 12 + 12 + 336 + 23 + + + + + unnamed + + + + textLabel1 + + + NoFrame + + + Plain + + + Sort at most the + + + + + mcntSB + + + 10000 + + + 100 + + + + + textLabel2 + + + most relevant results by: + + + + + + + layout3 + + + + 12 + 41 + 336 + 23 + + + + + unnamed + + + + fldCMB1 + + + + + descCB1 + + + Descending + + + + + + + layout6 + + + + 12 + 70 + 336 + 23 + + + + + unnamed + + + + fldCMB2 + + + + + descCB2 + + + Descending + + + + + + + layout10 + + + + 12 + 99 + 336 + 23 + + + + + unnamed + + + + fldCMB3 + + + + + descCB3 + + + Descending + + + + + + + descCB4 + + + + 183 + 130 + 164 + 18 + + + + Descending + + + + + fldCMB4 + + + + 13 + 129 + 164 + 21 + + + + + + sort.ui.h + + + init() + + + diff --git a/src/qtgui/sort.ui.h b/src/qtgui/sort.ui.h new file mode 100644 index 00000000..e3776b55 --- /dev/null +++ b/src/qtgui/sort.ui.h @@ -0,0 +1,19 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you want to add, delete, or rename functions or slots, use +** Qt Designer to update this file, preserving your code. +** +** You should not define a constructor or destructor in this file. +** Instead, write your code in functions called init() and destroy(). +** These will automatically be called by the form's constructor and +** destructor. +*****************************************************************************/ + + +void sort::init() +{ + +} + + diff --git a/src/query/sortseq.cpp b/src/query/sortseq.cpp new file mode 100644 index 00000000..cbe709da --- /dev/null +++ b/src/query/sortseq.cpp @@ -0,0 +1,88 @@ +#ifndef lint +static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.1 2005-12-01 16:23:09 dockes Exp $ (C) 2005 J.F.Dockes"; +#endif +#include + +#include "debuglog.h" +#include "sortseq.h" + +using std::string; + +class CompareDocs { + RclSortSpec ss; +public: + CompareDocs(const RclSortSpec &sortspec) : ss(sortspec) {} + + int operator()(const Rcl::Doc &x, const Rcl::Doc &y) { + for (unsigned int i = 0; i < ss.crits.size(); i++) { + switch (ss.crits[i]) { + case RclSortSpec::RCLFLD_MTIME: + { + long xmtime = x.dmtime.empty() ? atol(x.fmtime.c_str()) : + atol(x.dmtime.c_str()); + long ymtime = y.dmtime.empty() ? atol(y.fmtime.c_str()) : + atol(y.dmtime.c_str()); + if (ss.dirs[i]) + return xmtime > ymtime; + else + return xmtime < ymtime; + } + continue; + case RclSortSpec::RCLFLD_URL: + if (ss.dirs[i]) + return x.url > y.url; + else + return x.url < y.url; + continue; + case RclSortSpec::RCLFLD_IPATH: + if (ss.dirs[i]) + return x.ipath > y.ipath; + else + return x.ipath < y.ipath; + continue; + case RclSortSpec::RCLFLD_MIMETYPE: + if (ss.dirs[i]) + return x.mimetype > y.mimetype; + else + return x.mimetype < y.mimetype; + continue; + } + } + // Did all comparisons: must be equal + return 0; + } +}; + +DocSeqSorted::DocSeqSorted(DocSequence &iseq, int cnt, RclSortSpec &sortspec) +{ + LOGDEB1(("DocSeqSorted:: input cnt %d\n", cnt)); + + m_docs.resize(cnt); + m_pcs.resize(cnt); + int i; + for (i = 0; i < cnt; i++) { + if (!iseq.getDoc(i, m_docs[i], &m_pcs[i])) { + LOGERR(("DocSeqSorted: getDoc failed for doc %d\n", i)); + break; + } + } + m_count = i; + LOGDEB1(("DocSeqSorted:: m_count %d\n", m_count)); + m_docs.resize(m_count); + m_pcs.resize(m_count); + m_title = string("Sorted ") + iseq.title(); + CompareDocs cmp(sortspec); + sort(m_docs.begin(), m_docs.end(), cmp); +} + +bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, int *percent, string *) +{ + LOGDEB1(("DocSeqSorted: fetching %d\n", num)); + + if (num >= m_count) + return false; + if (percent) + *percent = m_pcs[num]; + doc = m_docs[num]; + return true; +} diff --git a/src/query/sortseq.h b/src/query/sortseq.h new file mode 100644 index 00000000..af46b44a --- /dev/null +++ b/src/query/sortseq.h @@ -0,0 +1,39 @@ +#ifndef _SORTSEQ_H_INCLUDED_ +#define _SORTSEQ_H_INCLUDED_ +/* @(#$Id: sortseq.h,v 1.1 2005-12-01 16:23:09 dockes Exp $ (C) 2004 J.F.Dockes */ + +#include +#include + +#include "docseq.h" + +class RclSortSpec { + public: + enum Field {RCLFLD_URL, RCLFLD_IPATH, RCLFLD_MIMETYPE, RCLFLD_MTIME}; + void addCrit(Field fld, bool desc = false) { + crits.push_back(fld); + dirs.push_back(desc); + } + std::vector crits; + std::vector dirs; +}; + +/** + * A sorted sequence is created from the first N documents of another one, + * and sorts them according to the given criteria. + */ +class DocSeqSorted : public DocSequence { + public: + DocSeqSorted(DocSequence &iseq, int cnt, RclSortSpec &sortspec); + virtual ~DocSeqSorted() {} + virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0); + virtual int getResCnt() {return m_count;} + virtual std::string title() {return m_title;} + private: + std::string m_title; + int m_count; + std::vector m_docs; + std::vector m_pcs; +}; + +#endif /* _SORTSEQ_H_INCLUDED_ */