File: RingoFastIndexFetch.cs

package info (click to toggle)
indigo 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 48,936 kB
  • sloc: ansic: 332,816; cpp: 169,470; python: 20,033; java: 13,701; cs: 9,979; asm: 8,475; sql: 6,743; xml: 6,354; javascript: 1,245; sh: 555; php: 506; makefile: 54
file content (76 lines) | stat: -rw-r--r-- 2,512 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System.IO;
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Runtime.Serialization.Formatters.Binary;

namespace indigo
{
   public class RingoFastIndexFetch
   {
      RingoIndexData _index_data;
      bool highlighting;

      public int? nextAfterStorageId { get; set; }

      public RingoFastIndexFetch (RingoIndexData index_data)
      {
         _index_data = index_data;
      }

      public void prepareSub (string query, string options, bool highlighting, bool smarts)
      {
         int res = BingoCore.lib.ringoSetupMatch(smarts ? "RSMARTS" : "RSUB", query, options);
         if (res < 0)
            throw new Exception(BingoCore.lib.bingoGetError());
         BingoCore.lib.ringoSetHightlightingMode(highlighting ? 1 : 0);
         this.highlighting = highlighting;
      }

      public IEnumerable<FetchedData> fetch (SqlConnection conn)
      {
         byte[] fp;
         BingoCore.ringoGetQueryFingerprint(out fp);

         // Search using fast index
         _index_data.fingerprints.init(conn);
         _index_data.storage.validate(conn);

         IEnumerable<int> screened;
         if (!_index_data.fingerprints.ableToScreen(fp))
            screened = _index_data.storage.enumerateStorageIds(nextAfterStorageId);
         else
            screened = _index_data.fingerprints.screenSub(conn, fp, nextAfterStorageId);

         int cache_index = 0;
         foreach (int storage_id in screened)
         {
            if (_index_data.storage.isDeleted(storage_id, conn, ref cache_index))
               continue;

            byte[] data_with_cmf = _index_data.storage.get(storage_id, 4, -1, conn, ref cache_index);

            int ret = BingoCore.lib.ringoMatchTargetBinary(data_with_cmf,
               data_with_cmf.Length);

            if (ret == -2)
               throw new Exception(BingoCore.lib.bingoGetError());
            if (ret == -1)
               throw new Exception(BingoCore.lib.bingoGetWarning());

            if (ret == 1)
            {
               int id = _index_data.storage.getInt(storage_id, 0, conn, ref cache_index);
               FetchedData data = new FetchedData(id);
               if (highlighting)
                  data.str = BingoCore.ringoGetHightlightedReaction();
               yield return data;
            }
         }
      }
   }
}