Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » General » Downloads
 
Add your own
alternative version

hOOt - full text search engine

, 22 Jun 2013 CPOL
Smallest full text search engine (lucene replacement) built from scratch using inverted WAH bitmap index, highly compact storage, operating in database and document modes
hoot_v1.0-noexe.zip
hoot_v1.0.zip
fastJSON.dll
Hoot
Properties
SampleApp
newifilter
Properties
Settings.settings
hoot_v1.1-noexe.zip
Hoot_v1.1.zip
fastJSON.dll
_svn
all-wcprops
entries
text-base
AssemblyInfo.cs.svn-base
_svn
all-wcprops
entries
text-base
ComHelper.cs.svn-base
FilterLoader.cs.svn-base
FilterReader.cs.svn-base
IFilter.cs.svn-base
Settings.settings
_svn
all-wcprops
entries
text-base
AssemblyInfo.cs.svn-base
Resources.Designer.cs.svn-base
Resources.resx.svn-base
Settings.Designer.cs.svn-base
Settings.settings.svn-base
hoot_v1.2-noexe.zip
Hoot_v1.2.zip
fastJSON.dll
Settings.settings
hoot_v1.3-noexe.zip
Hoot_v1.3.zip
fastJSON.dll
Settings.settings
hoot_v1.4-noexe.zip
Hoot_v1.4.zip
fastJSON.dll
Settings.settings
hoot_v1.5-noexe.zip
Hoot_v1.5.zip
fastJSON.dll
Settings.settings
Hoot_v2.0.zip
fastJSON
MGIndex
Settings.settings
Hoot_v2.1.zip
Settings.settings
Hoot_v2.2.1.zip
.gitignore
Settings.settings
Hoot_v2.2.zip
.gitignore
Settings.settings
sampleapp.exe_v2.2-noexe.zip
sampleapp.exe_v2.2.1-noexe.zip
SampleApp.EXE_v2.2.1.zip
Hoot.dll
SampleApp.exe
SampleApp.EXE_v2.2.zip
Hoot.dll
SampleApp.exe
sampleapp_exe-noexe.zip
sampleapp_exe.zip
fastJSON.dll
Hoot.dll
SampleApp.exe
sampleapp_exe_v1.1-noexe.zip
SampleApp_EXE_v1.1.zip
fastJSON.dll
Hoot.dll
SampleApp.exe
sampleapp_exe_v1.2-noexe.zip
SampleApp_EXE_v1.2.zip
fastJSON.dll
Hoot.dll
SampleApp.exe
sampleapp_exe_v1.3-noexe.zip
SampleApp_EXE_v1.3.zip
fastJSON.dll
Hoot.dll
SampleApp.exe
sampleapp_exe_v1.4-noexe.zip
SampleApp_EXE_v1.4.zip
fastJSON.dll
Hoot.dll
SampleApp.exe
sampleapp_exe_v1.5-noexe.zip
SampleApp_EXE_v1.5.zip
fastJSON.dll
Hoot.dll
SampleApp.exe
sampleapp_exe_v2.0-noexe.zip
SampleApp_EXE_v2.0.zip
Hoot.dll
SampleApp.exe
sampleapp_exe_v2.1-noexe.zip
SampleApp_EXE_v2.1.zip
Hoot.dll
SampleApp.exe
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RaptorDB.Common;

namespace RaptorDB
{
    internal interface IGetBytes<T>
    {
        byte[] GetBytes(T obj);
        T GetObject(byte[] buffer, int offset, int count);
    }

    internal class RDBDataType<T>
    {
        public static IGetBytes<T> ByteHandler()
        {
            Type type = typeof(T);

            if (type == typeof(int)) return (IGetBytes<T>)new int_handler<T>();
            else if (type == typeof(uint)) return (IGetBytes<T>)new uint_handler<T>();
            else if (type == typeof(long)) return (IGetBytes<T>)new long_handler<T>();
            else if (type == typeof(Guid)) return (IGetBytes<T>)new guid_handler<T>();
            else if (type == typeof(string)) return (IGetBytes<T>)new string_handler<T>();
            else if (type == typeof(DateTime)) return (IGetBytes<T>)new datetime_handler<T>();
            else if (type == typeof(decimal)) return (IGetBytes<T>)new decimal_handler<T>();
            else if (type == typeof(short)) return (IGetBytes<T>)new short_handler<T>();
            else if (type == typeof(float)) return (IGetBytes<T>)new float_handler<T>();
            else if (type == typeof(byte)) return (IGetBytes<T>)new byte_handler<T>();
            else if (type == typeof(double)) return (IGetBytes<T>)new double_handler<T>();

            return null;
        }

        public static byte GetByteSize(byte keysize)
        {
            byte size = 4;
            Type t = typeof(T);

            if (t == typeof(int)) size = 4;
            if (t == typeof(uint)) size = 4;
            if (t == typeof(long)) size = 8;
            if (t == typeof(Guid)) size = 16;
            if (t == typeof(DateTime)) size = 8;
            if (t == typeof(decimal)) size = 16;
            if (t == typeof(float)) size = 4;
            if (t == typeof(short)) size = 2;
            if (t == typeof(string)) size = keysize;
            if (t == typeof(byte)) size = 1;
            if (t == typeof(double)) size = 8;

            return size;
        }

        internal static object GetEmpty()
        {
            Type t = typeof(T);

            if (t == typeof(string))
                return "";

            return default(T);
        }
    }

    #region [  handlers  ]

    internal class double_handler<T> : IGetBytes<double>
    {
        public byte[] GetBytes(double obj)
        {
            return BitConverter.GetBytes(obj);
        }

        public double GetObject(byte[] buffer, int offset, int count)
        {
            return BitConverter.ToDouble(buffer, offset);
        }
    }

    internal class byte_handler<T> : IGetBytes<byte>
    {
        public byte[] GetBytes(byte obj)
        {
            return new byte[1] { obj };
        }

        public byte GetObject(byte[] buffer, int offset, int count)
        {
            return buffer[offset];
        }
    }

    internal class float_handler<T> : IGetBytes<float>
    {
        public byte[] GetBytes(float obj)
        {
            return BitConverter.GetBytes(obj);
        }

        public float GetObject(byte[] buffer, int offset, int count)
        {
            return BitConverter.ToSingle(buffer, offset);
        }
    }

    internal class decimal_handler<T> : IGetBytes<decimal>
    {
        public byte[] GetBytes(decimal obj)
        {
            byte[] b = new byte[16];
            var bb = decimal.GetBits(obj);
            int index = 0;
            foreach (var d in bb)
            {
                byte[] db = Helper.GetBytes(d, false);
                Buffer.BlockCopy(db, 0, b, index, 4);
                index += 4;
            }

            return b;
        }

        public decimal GetObject(byte[] buffer, int offset, int count)
        {
            int[] i = new int[4];
            i[0] = Helper.ToInt32(buffer, offset);
            offset += 4;
            i[1] = Helper.ToInt32(buffer, offset);
            offset += 4;
            i[2] = Helper.ToInt32(buffer, offset);
            offset += 4;
            i[3] = Helper.ToInt32(buffer, offset);
            offset += 4;

            return new decimal(i);
        }
    }

    internal class short_handler<T> : IGetBytes<short>
    {
        public byte[] GetBytes(short obj)
        {
            return Helper.GetBytes(obj, false);
        }

        public short GetObject(byte[] buffer, int offset, int count)
        {
            return Helper.ToInt16(buffer, offset);
        }
    }

    internal class string_handler<T> : IGetBytes<string>
    {
        public byte[] GetBytes(string obj)
        {
            return Helper.GetBytes(obj);
        }

        public string GetObject(byte[] buffer, int offset, int count)
        {
            return Helper.GetString(buffer, offset, (short)count);
        }
    }

    internal class int_handler<T> : IGetBytes<int>
    {
        public byte[] GetBytes(int obj)
        {
            return Helper.GetBytes(obj, false);
        }

        public int GetObject(byte[] buffer, int offset, int count)
        {
            return Helper.ToInt32(buffer, offset);
        }
    }

    internal class uint_handler<T> : IGetBytes<uint>
    {
        public byte[] GetBytes(uint obj)
        {
            return Helper.GetBytes(obj, false);
        }

        public uint GetObject(byte[] buffer, int offset, int count)
        {
            return (uint)Helper.ToInt32(buffer, offset);
        }
    }

    internal class long_handler<T> : IGetBytes<long>
    {
        public byte[] GetBytes(long obj)
        {
            return Helper.GetBytes(obj, false);
        }

        public long GetObject(byte[] buffer, int offset, int count)
        {
            return Helper.ToInt64(buffer, offset);
        }
    }

    internal class guid_handler<T> : IGetBytes<Guid>
    {
        public byte[] GetBytes(Guid obj)
        {
            return obj.ToByteArray();
        }

        public Guid GetObject(byte[] buffer, int offset, int count)
        {
            byte[] b = new byte[16];
            Buffer.BlockCopy(buffer, offset, b, 0, 16);
            return new Guid(b);
        }
    }

    internal class datetime_handler<T> : IGetBytes<DateTime>
    {
        public byte[] GetBytes(DateTime obj)
        {
            return Helper.GetBytes(obj.Ticks, false);
        }

        public DateTime GetObject(byte[] buffer, int offset, int count)
        {
            long ticks = Helper.ToInt64(buffer, offset);

            return new DateTime(ticks);
        }
    }
    #endregion
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mehdi Gholam
Architect
United Kingdom United Kingdom
Mehdi first started programming when he was 8 on BBC+128k machine in 6512 processor language, after various hardware and software changes he eventually came across .net and c# which he has been using since v1.0.
He is formally educated as a system analyst Industrial engineer, but his programming passion continues.
 
* Mehdi is the 5th person to get 6 out of 7 Platinums on CodeProject (13th Jan'12)

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 22 Jun 2013
Article Copyright 2011 by Mehdi Gholam
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid