sorting 1st steps

This commit is contained in:
dockes 2005-12-01 16:23:09 +00:00
parent fb0f80ded2
commit 7a7e77cfae
7 changed files with 367 additions and 3 deletions

View File

@ -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

View File

@ -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 \

View File

@ -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();
}

199
src/qtgui/sort.ui Normal file
View File

@ -0,0 +1,199 @@
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>sort</class>
<widget class="QDialog">
<property name="name">
<cstring>sort</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>163</height>
</rect>
</property>
<property name="caption">
<string>Form1</string>
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout2</cstring>
</property>
<property name="geometry">
<rect>
<x>12</x>
<y>12</y>
<width>336</width>
<height>23</height>
</rect>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>textLabel1</cstring>
</property>
<property name="frameShape">
<enum>NoFrame</enum>
</property>
<property name="frameShadow">
<enum>Plain</enum>
</property>
<property name="text">
<string>Sort at most the </string>
</property>
</widget>
<widget class="QSpinBox">
<property name="name">
<cstring>mcntSB</cstring>
</property>
<property name="maxValue">
<number>10000</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>textLabel2</cstring>
</property>
<property name="text">
<string>most relevant results by:</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout3</cstring>
</property>
<property name="geometry">
<rect>
<x>12</x>
<y>41</y>
<width>336</width>
<height>23</height>
</rect>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<property name="name">
<cstring>fldCMB1</cstring>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>descCB1</cstring>
</property>
<property name="text">
<string>Descending</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout6</cstring>
</property>
<property name="geometry">
<rect>
<x>12</x>
<y>70</y>
<width>336</width>
<height>23</height>
</rect>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<property name="name">
<cstring>fldCMB2</cstring>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>descCB2</cstring>
</property>
<property name="text">
<string>Descending</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout10</cstring>
</property>
<property name="geometry">
<rect>
<x>12</x>
<y>99</y>
<width>336</width>
<height>23</height>
</rect>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<property name="name">
<cstring>fldCMB3</cstring>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>descCB3</cstring>
</property>
<property name="text">
<string>Descending</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>descCB4</cstring>
</property>
<property name="geometry">
<rect>
<x>183</x>
<y>130</y>
<width>164</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Descending</string>
</property>
</widget>
<widget class="QComboBox">
<property name="name">
<cstring>fldCMB4</cstring>
</property>
<property name="geometry">
<rect>
<x>13</x>
<y>129</y>
<width>164</width>
<height>21</height>
</rect>
</property>
</widget>
</widget>
<includes>
<include location="local" impldecl="in implementation">sort.ui.h</include>
</includes>
<functions>
<function>init()</function>
</functions>
<layoutdefaults spacing="6" margin="11"/>
</UI>

19
src/qtgui/sort.ui.h Normal file
View File

@ -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()
{
}

88
src/query/sortseq.cpp Normal file
View File

@ -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 <algorithm>
#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;
}

39
src/query/sortseq.h Normal file
View File

@ -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 <vector>
#include <string>
#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<Field> crits;
std::vector<bool> 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<Rcl::Doc> m_docs;
std::vector<int> m_pcs;
};
#endif /* _SORTSEQ_H_INCLUDED_ */