Switch to unified view

a/src/rcldb/synfamily.cpp b/src/rcldb/synfamily.cpp
...
...
16
 */
16
 */
17
#ifndef TEST_SYNFAMILY
17
#ifndef TEST_SYNFAMILY
18
18
19
#include "autoconfig.h"
19
#include "autoconfig.h"
20
20
21
#include <fnmatch.h>
22
21
#include <iostream>
23
#include <iostream>
22
#include <algorithm>
24
#include <algorithm>
23
25
24
#include "debuglog.h"
26
#include "debuglog.h"
27
#include "cstr.h"
25
#include "xmacros.h"
28
#include "xmacros.h"
26
#include "synfamily.h"
29
#include "synfamily.h"
27
#include "smallut.h"
30
#include "smallut.h"
28
31
29
using namespace std;
32
using namespace std;
...
...
138
    string root = (*m_trans)(term);
141
    string root = (*m_trans)(term);
139
    string filter_root;
142
    string filter_root;
140
    if (filtertrans)
143
    if (filtertrans)
141
    filter_root = (*filtertrans)(term);
144
    filter_root = (*filtertrans)(term);
142
145
143
    /* We could call XapSynFamily::synExpand() here instead of doing it
144
       ourselves... */
145
    string key = m_prefix + root;
146
    string key = m_prefix + root;
146
147
147
    LOGDEB(("XapCompSynFamMbr::synExpand([%s]): term [%s] root [%s] \n", 
148
    LOGDEB(("XapCompSynFamMbr::synExpand([%s]): term [%s] root [%s] \n", 
148
        m_prefix.c_str(), term.c_str(), root.c_str()));
149
        m_prefix.c_str(), term.c_str(), root.c_str()));
149
150
...
...
179
    LOGDEB(("XapCompSynFamMbr::synExpand([%s]): term [%s] -> [%s]\n",
180
    LOGDEB(("XapCompSynFamMbr::synExpand([%s]): term [%s] -> [%s]\n",
180
        m_prefix.c_str(), term.c_str(), stringsToString(result).c_str()));
181
        m_prefix.c_str(), term.c_str(), stringsToString(result).c_str()));
181
    return true;
182
    return true;
182
}
183
}
183
184
185
186
bool XapComputableSynFamMember::keyWildExpand(const string& inexp,
187
                        vector<string>& result,
188
                        SynTermTrans *filtertrans)
189
{
190
    LOGDEB(("XapCompSynFam::keyWildExpand: [%s]\n", inexp.c_str()));
191
    
192
    // Transform input into our key format (e.g.: case-folded + diac-stripped)
193
    string stripped_exp = (*m_trans)(inexp);
194
195
    // If set, compute filtering term (e.g.: only case-folded)
196
    string filter_exp;
197
    if (filtertrans)
198
  filter_exp = (*filtertrans)(inexp);
199
200
    // Find the initial section before any special chars
201
    string::size_type es = stripped_exp.find_first_of(cstr_wildSpecStChars);
202
    string is; // Initial section
203
    switch (es) {
204
    case string::npos: 
205
  // No special chars, no expansion.
206
  result.push_back(inexp);
207
  return true;
208
  break;
209
    case 0: 
210
  // Input starts with special char: start at bottom
211
  is = m_prefix; 
212
  break;
213
    default: 
214
  // Compute initial section
215
  is = m_prefix + stripped_exp.substr(0, es); 
216
  break;
217
    }
218
219
    // Input to matching: prefix + transformed input
220
    string matchin = m_prefix + stripped_exp;
221
    string::size_type preflen = m_prefix.size();
222
223
    string ermsg;
224
    try {
225
        for (Xapian::TermIterator xit = m_family.getdb().synonym_keys_begin(is);
226
             xit != m_family.getdb().synonym_keys_end(is); xit++) {
227
      LOGDEB(("  Checking1 [%s] against [%s]\n", (*xit).c_str(),
228
          matchin.c_str()));
229
      if (fnmatch(matchin.c_str(), (*xit).c_str(), 0) == FNM_NOMATCH)
230
      continue;
231
232
      // Push all the synonyms if they match the secondary filter
233
      for (Xapian::TermIterator xit1 = 
234
           m_family.getdb().synonyms_begin(*xit);
235
       xit1 != m_family.getdb().synonyms_end(*xit); xit1++) {
236
      string term = *xit1;
237
      if (filtertrans) {
238
          string term1 = (*filtertrans)(term);
239
          LOGDEB((" Testing [%s] against [%s]\n", 
240
              term1.c_str(), filter_exp.c_str()));
241
          if (fnmatch(filter_exp.c_str(), 
242
              term1.c_str(), 0) == FNM_NOMATCH) {
243
          continue;
244
          }
245
      }
246
      LOGDEB(("XapCompSynFam::keyWildExpand: Pushing %s\n", 
247
          (*xit1).c_str()));
248
      result.push_back(*xit1);
249
      }
250
      // Same with key itself
251
      string term = (*xit).substr(preflen);
252
      if (filtertrans) {
253
      string term1 = (*filtertrans)(term);
254
      LOGDEB((" Testing [%s] against [%s]\n", 
255
          term1.c_str(), filter_exp.c_str()));
256
      if (fnmatch(filter_exp.c_str(), 
257
              term1.c_str(), 0) == FNM_NOMATCH) {
258
          continue;
259
      }
260
      }
261
      LOGDEB(("XapCompSynFam::keyWildExpand: Pushing [%s]\n", 
262
          term.c_str()));
263
      result.push_back(term);
264
        }
265
    } XCATCHERROR(ermsg);
266
    if (!ermsg.empty()) {
267
        LOGERR(("XapCompSynFam::keyWildExpand: error: term [%s]\n",
268
                inexp.c_str()));
269
        result.push_back(inexp);
270
        return false;
271
    }
272
    return true;
184
}
273
}
274
275
276
} // Namespace Rcl
185
277
186
#else  // TEST_SYNFAMILY 
278
#else  // TEST_SYNFAMILY 
187
#include "autoconfig.h"
279
#include "autoconfig.h"
188
280
189
#include <stdio.h>
281
#include <stdio.h>