00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include "msetcmp.h"
00023
00024
00025
00026
00027
00028
00029
00030 template<bool FORWARD_DID, bool CHECK_DID_ZERO> inline bool
00031 msetcmp_by_did(const Xapian::Internal::MSetItem &a,
00032 const Xapian::Internal::MSetItem &b)
00033 {
00034 if (FORWARD_DID) {
00035 if (CHECK_DID_ZERO) {
00036
00037 if (a.did == 0) return false;
00038 if (b.did == 0) return true;
00039 }
00040 return (a.did < b.did);
00041 } else {
00042 return (a.did > b.did);
00043 }
00044 }
00045
00046
00047 template<bool FORWARD_DID> bool
00048 msetcmp_by_relevance(const Xapian::Internal::MSetItem &a,
00049 const Xapian::Internal::MSetItem &b)
00050 {
00051 if (a.wt > b.wt) return true;
00052 if (a.wt < b.wt) return false;
00053 return msetcmp_by_did<FORWARD_DID, true>(a, b);
00054 }
00055
00056
00057 template<bool FORWARD_VALUE, bool FORWARD_DID> bool
00058 msetcmp_by_value(const Xapian::Internal::MSetItem &a,
00059 const Xapian::Internal::MSetItem &b)
00060 {
00061 if (!FORWARD_VALUE) {
00062
00063 if (a.did == 0) return false;
00064 if (b.did == 0) return true;
00065 }
00066 if (a.sort_key > b.sort_key) return FORWARD_VALUE;
00067 if (a.sort_key < b.sort_key) return !FORWARD_VALUE;
00068 return msetcmp_by_did<FORWARD_DID, FORWARD_VALUE>(a, b);
00069 }
00070
00071
00072 template<bool FORWARD_VALUE, bool FORWARD_DID> bool
00073 msetcmp_by_value_then_relevance(const Xapian::Internal::MSetItem &a,
00074 const Xapian::Internal::MSetItem &b)
00075 {
00076 if (!FORWARD_VALUE) {
00077
00078 if (a.did == 0) return false;
00079 if (b.did == 0) return true;
00080 }
00081 if (a.sort_key > b.sort_key) return FORWARD_VALUE;
00082 if (a.sort_key < b.sort_key) return !FORWARD_VALUE;
00083 if (a.wt > b.wt) return true;
00084 if (a.wt < b.wt) return false;
00085 return msetcmp_by_did<FORWARD_DID, FORWARD_VALUE>(a, b);
00086 }
00087
00088
00089 template<bool FORWARD_VALUE, bool FORWARD_DID> bool
00090 msetcmp_by_relevance_then_value(const Xapian::Internal::MSetItem &a,
00091 const Xapian::Internal::MSetItem &b)
00092 {
00093 if (!FORWARD_VALUE) {
00094
00095 if (a.did == 0) return false;
00096 if (b.did == 0) return true;
00097 }
00098 if (a.wt > b.wt) return true;
00099 if (a.wt < b.wt) return false;
00100 if (a.sort_key > b.sort_key) return FORWARD_VALUE;
00101 if (a.sort_key < b.sort_key) return !FORWARD_VALUE;
00102 return msetcmp_by_did<FORWARD_DID, FORWARD_VALUE>(a, b);
00103 }
00104
00105 static mset_cmp mset_cmp_table[] = {
00106
00107 msetcmp_by_relevance<false>,
00108 msetcmp_by_relevance<false>,
00109 msetcmp_by_relevance<true>,
00110 msetcmp_by_relevance<true>,
00111
00112 msetcmp_by_value<false, false>,
00113 msetcmp_by_value<true, false>,
00114 msetcmp_by_value<false, true>,
00115 msetcmp_by_value<true, true>,
00116
00117 msetcmp_by_value_then_relevance<false, false>,
00118 msetcmp_by_value_then_relevance<true, false>,
00119 msetcmp_by_value_then_relevance<false, true>,
00120 msetcmp_by_value_then_relevance<true, true>,
00121
00122 msetcmp_by_relevance_then_value<true, true>,
00123 msetcmp_by_relevance_then_value<false, true>,
00124 msetcmp_by_relevance_then_value<true, false>,
00125 msetcmp_by_relevance_then_value<false, false>
00126 };
00127
00128 mset_cmp get_msetcmp_function(Xapian::Enquire::Internal::sort_setting sort_by, bool sort_forward, bool sort_value_forward) {
00129 return mset_cmp_table[sort_by * 4 + sort_forward * 2 + sort_value_forward];
00130 }