public static LuceneResultNode SearchEx(IndexBase index, SearchNode node) { try { var query = MultiFieldQueryParser.Parse(Lucene.Net.Util.Version.LUCENE_29, node.Queries, node.Fields, node.Occurs, new PanGuAnalyzer(true)); foreach (NumberRangeNode n in node.NumberRangeFiters) { query = new FilteredQuery(query, NumericRangeFilter.NewIntRange(n.FieldName, n.MinValue, n.MaxValue, true, true)); } foreach (LongRangeNode lr in node.LongRnageFilters) { query = new FilteredQuery(query, NumericRangeFilter.NewLongRange(lr.FieldName, lr.MinValue, lr.MaxValue, true, true)); } foreach (ContainFilterNode cf in node.ContainFilters) { query = new FilteredQuery(query, new ContainFilter(new Term(cf.FieldName, cf.Text))); } return(ResponseSearch(index, query, node, 0)); } catch (Lucene.Net.QueryParsers.ParseException) { return(new LuceneResultNode() { AllCount = 0, Result = new List <string>() }); } catch (Exception ex) { throw ex; } }
/// <summary> /// Creates a new memory mapped tags index. /// </summary> /// <param name="file"></param> public TagsIndex(MemoryMappedFile file) { _stringIndex = new MemoryMappedIndex <string>(file, MemoryMappedDelegates.ReadFromString, MemoryMappedDelegates.WriteToString); _tagsIndex = new MemoryMappedIndex <int[]>(file, MemoryMappedDelegates.ReadFromIntArray, MemoryMappedDelegates.WriteToIntArray); _tagsReverseIndex = new MemoryMappedHugeDictionary <int[], uint>(file, MemoryMappedDelegates.ReadFromIntArray, MemoryMappedDelegates.WriteToIntArray, MemoryMappedDelegates.ReadFromUInt32, MemoryMappedDelegates.WriteToUInt32, (x) => { var hash = 0; for (int idx = 0; idx < x.Length; idx++) { hash = hash ^ x[idx].GetHashCode(); } return(hash); }, (x, y) => { var comp = x.Length.CompareTo(y.Length); if (comp == 0) { for (int idx = 0; idx < x.Length; idx++) { comp = x[idx].CompareTo(y[idx]); if (comp != 0) { return(comp); } } return(0); } return(comp); }); _stringReverseIndex = new MemoryMappedHugeDictionary <string, int>(file, MemoryMappedDelegates.ReadFromString, MemoryMappedDelegates.WriteToString, MemoryMappedDelegates.ReadFromInt32, MemoryMappedDelegates.WriteToInt32); }
/// <summary> /// 添加索引 /// </summary> public static void AddIndex(List <IndexNode> nodes, IndexBase index) { foreach (var node in nodes) { index.AddIndex(CreateDoucment(node)); } }
/// <summary> /// Returns matrix index base. /// </summary> /// <returns></returns> public IndexBase GetMatIndexBase() { IndexBase indexBase = CudaSparseNativeMethods.cusparseGetMatIndexBase(_descr); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseGetMatIndexBase", res)); return(indexBase); }
/// <summary> /// Creates a new tags index given an existing string index and tags index. /// </summary> /// <param name="stringIndex"></param> /// <param name="tagsIndex"></param> internal TagsIndex(IndexBase <string> stringIndex, IndexBase <int[]> tagsIndex) { _stringIndex = stringIndex; _tagsIndex = tagsIndex; _stringReverseIndex = null; _tagsReverseIndex = null; }
/// <summary> /// Sets matrix index base /// </summary> /// <param name="indexBase"></param> public void SetMatIndexBase(IndexBase indexBase) { res = CudaSparseNativeMethods.cusparseSetMatIndexBase(_descr, indexBase); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSetMatIndexBase", res)); if (res != cusparseStatus.Success) { throw new CudaSparseException(res); } }
private static void checkLE(IndexBase indexByValue) { var keyType = new KeyInfo(KeyDataType.IntKey, KeyType.ScalarIndex, "test", true); //non existent value in the middle { var result1 = indexByValue.GetMany(MakeIntValue(12, keyType), QueryOperator.Le); Assert.AreEqual(result1.Count, 3); var count = indexByValue.GetCount(MakeIntValue(12, keyType), QueryOperator.Le); Assert.AreEqual(count, 3); } //existent value in the middle { var result1 = indexByValue.GetMany(MakeIntValue(13, keyType), QueryOperator.Le); Assert.AreEqual(result1.Count, 4); var count = indexByValue.GetCount(MakeIntValue(13, keyType), QueryOperator.Le); Assert.AreEqual(count, 4); } //value < all { var result1 = indexByValue.GetMany(MakeIntValue(0, keyType), QueryOperator.Le); Assert.AreEqual(result1.Count, 0); var count = indexByValue.GetCount(MakeIntValue(0, keyType), QueryOperator.Le); Assert.AreEqual(count, 0); } //value > all { var result1 = indexByValue.GetMany(MakeIntValue(99, keyType), QueryOperator.Le); Assert.AreEqual(result1.Count, 6); var count = indexByValue.GetCount(MakeIntValue(99, keyType), QueryOperator.Le); Assert.AreEqual(count, 6); } //first value { var result1 = indexByValue.GetMany(MakeIntValue(1, keyType), QueryOperator.Le).OrderBy(o => o.PrimaryKey) .ToList(); Assert.AreEqual(result1.Count, 1); Assert.AreEqual(result1[0].PrimaryKey.ToString(), "#1"); var count = indexByValue.GetCount(MakeIntValue(1, keyType), QueryOperator.Le); Assert.AreEqual(count, 1); } }
public Index() { _base = new IndexBase(); _base.Initialize(); _games = new List <string> { "Pong", "Nox", }; }
public static void DeleteVideo(LiveVideoNode video, IndexBase index) { var terms = new List <Term>(video.Items.Count + 1); terms.Add(new Term(LiveEpgNode.ChannelId, video.Main.ChannelID.ToString())); foreach (var parade in video.Items) { terms.Add(new Term(LiveEpgNode.ParadeId, parade.ID.ToString())); } index.DeleteDocument(terms.ToArray()); }
private void AppendConstraintBase(IndexBase constraint, string primaryKeyString, string unique) { string clustered = constraint.Clustered ? "CLUSTERED" : "NONCLUSTERED"; string ignoreDupKey = constraint.IgnoreDupKey ? "IGNORE_DUP_KEY = ON" : "IGNORE_DUP_KEY = OFF"; string padIndex = constraint.PadIndex ? "PAD_INDEX = ON" : "PAD_INDEX = OFF"; string kName; string keys = new KeysBuilder(constraint.Keys).Build(constraint.Name, out kName); TemplatePlatformEmitter te = new TemplatePlatformEmitter("ConstraintTemplate", kName, unique + clustered, keys, "WITH(" + padIndex + "," + ignoreDupKey + ")", primaryKeyString); _stringBuilder.Append(te.Emit(constraint)); }
public Index() { _base = new IndexBase(); _games = new List <string> { "Corporation Tycoon", "Kaiju", "Nox", "Pong", }; }
public static void AddTag(TagNode tag, string dimension, IndexBase index) { var builder = new StringBuilder(); //Dictionary<int, string[]> fbcodes = new Dictionary<int, string[]>(tag.Channels.Keys.Count); foreach (var plat in tag.Channels.Keys) { var indexx = VideoNodeKeyArray.Instance.Items[VideoNodeKeyArray.Instance.FindKey(plat.PlatForm, 0, plat.Auth)]; builder.Append(indexx); builder.Append(SplitArray.DH); //IEnumerable<string> fbcode = null; //var query = tag.Channels[plat].Select(v => ListCache.Instance.Dictionary[v].ForbiddenAreas); //foreach (var q in query) //{ // if (fbcode == null) // fbcode = q; // else // fbcode = fbcode.Intersect(q); //} //fbcodes[indexx] = fbcode.ToArray(); } if (builder.Length < 2) { return; } var node = new IndexNode(); var indexnames = new List <KeyValuePair <string, string> >(3); var name = new KeyValuePair <string, string>(EpgIndexNode.Name, tag.Language[CustomArray.LanguageArray[0]].Title); var cnname = new KeyValuePair <string, string>(EpgIndexNode.CnName, string.Format("{0}{1}", tag.Language[CustomArray.LanguageArray[0]].Title, SplitArray.IndexCnName)); var pindex = new KeyValuePair <string, string>(EpgIndexNode.PlatformIndex, string.Format("{0}{1}", builder.Remove(builder.Length - 1, 1), SplitArray.IndexFlag)); //foreach (var fbcode in fbcodes) //{ // var fb = new KeyValuePair<string, string>(string.Format("{0}{1}", EpgIndexNode.ForbiddenCode, fbcode.Key), string.Format("{0},{1}", string.Join(",", ForbiddenAreaCache.Instance.ForbiddenNames.Except(fbcode.Value).ToArray()), SplitArray.IndexFlag)); // indexnames.Add(fb); //} indexnames.Add(name); indexnames.Add(cnname); indexnames.Add(pindex); var indexvalues = new List <KeyValuePair <string, string> >(2); var vid = new KeyValuePair <string, string>(EpgIndexNode.IndexValue, tag.Language[CustomArray.LanguageArray[0]].Title); var dimen = new KeyValuePair <string, string>(EpgIndexNode.Flags, dimension); indexvalues.Add(vid); indexvalues.Add(dimen); node.IndexNames = indexnames; node.IndexValues = indexvalues; LuceneNetUtils.AddIndex(node, index); }
public void Bee_dead_status_should_update_with_damage(BeeType type, int damage, bool dead) { var bee = new Bee { BeeType = type, Health = 100, Name = "Test bee" }; var beeService = new IndexBase(); beeService.DamageBee(bee, damage); Assert.Equal(dead, bee.Dead); }
protected override void OnValueChanged(IndexBase element, bool oldValue, bool newValue) { if (element.Entity != null) { if (!element.Entity.nHydrateModel.IsLoading && !element.Store.InUndo) { if (element.IndexType == IndexTypeConstants.PrimaryKey) { throw new Exception("This is a managed index and cannot be modified."); } } } base.OnValueChanged(element, oldValue, newValue); }
/// <summary> /// </summary> public SparseVector(long aSize, long aNnz, CudaDeviceVariable <indexT> indices, CudaDeviceVariable <dataT> values, IndexBase aIdxBase) { size = aSize; nnz = aNnz; idxBase = aIdxBase; descr = new cusparseSpVecDescr(); typeIndices = IndexTypeTranslator.GetType(typeof(indexT)); typeData = CudaDataTypeTranslator.GetType(typeof(dataT)); res = CudaSparseNativeMethods.cusparseCreateSpVec(ref descr, size, nnz, indices.DevicePointer, values.DevicePointer, typeIndices, idxBase, typeData); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCreateSpVec", res)); if (res != cusparseStatus.Success) { throw new CudaSparseException(res); } }
public void Health_should_not_go_down_if_bee_is_dead() { var bee = new Bee { BeeType = BeeType.Drone, Health = 25, Name = "Test bee", Dead = true }; var beeService = new IndexBase(); beeService.DamageBee(bee, 150); Assert.Equal(25, bee.Health); }
public static void InsertVideo(LiveVideoNode video, IndexBase index) { var builder = new StringBuilder(); foreach (var authnode in video.PlatForms) { builder.Append(VideoNodeKeyArray.Instance.Items[VideoNodeKeyArray.Instance.FindKey(authnode.PlatformName, 0, authnode.Licence)]); builder.Append(SplitArray.DH); } if (builder.Length < 2) { return; } var nodes = CreateNewNode(video, builder.ToString()); index.InsertIndex(nodes); }
/// <summary> /// </summary> private SparseMatrix(cusparseSpMatDescr aDescr, long aRows, long aCols, long aNnz, IndexBase aIdxBase, IndexType aTypeIndices, cudaDataType aTypeData) { rows = aRows; cols = aCols; nnz = aNnz; idxBase = aIdxBase; descr = aDescr; typeIndices = aTypeIndices; typeData = aTypeData; format = Format.COO; res = CudaSparseNativeMethods.cusparseSpMatGetFormat(descr, ref format); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseSpMatGetFormat", res)); if (res != cusparseStatus.Success) { throw new CudaSparseException(res); } }
public static int DistinctSearch(IndexBase index, SearchNode node, XElement root) { try { var query = MultiFieldQueryParser.Parse(Lucene.Net.Util.Version.LUCENE_29, node.Queries, node.Fields, node.Occurs, new PanGuAnalyzer(true)); foreach (ContainFilterNode cf in node.ContainFilters) { query = new FilteredQuery(query, new ContainFilter(new Term(cf.FieldName, cf.Text))); } return(ResponseDistinctSearch(index, query, node, root)); } catch (Lucene.Net.QueryParsers.ParseException) { return(0); } catch (Exception ex) { throw ex; } }
public static SparseMatrix <indexT1, dataT1> CreateCooAoS <indexT1, dataT1>( long rows, long cols, long nnz, CudaDeviceVariable <indexT1> cooInd, CudaDeviceVariable <dataT1> cooValues, IndexBase idxBase) where indexT1 : struct where dataT1 : struct { cusparseSpMatDescr descr = new cusparseSpMatDescr(); IndexType typeIndices = IndexTypeTranslator.GetType(typeof(indexT1)); cudaDataType typeData = CudaDataTypeTranslator.GetType(typeof(dataT1)); cusparseStatus res = CudaSparseNativeMethods.cusparseCreateCooAoS(ref descr, rows, cols, nnz, cooInd.DevicePointer, cooValues.DevicePointer, typeIndices, idxBase, typeData); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cusparseCreateCooAoS", res)); if (res != cusparseStatus.Success) { throw new CudaSparseException(res); } return(new SparseMatrix <indexT1, dataT1>(descr, rows, cols, nnz, idxBase, typeIndices, typeData)); }
private static int ResponseDistinctSearch(IndexBase index, Query query, SearchNode snode, XElement root) { var searcher = new IndexSearcher(index.Directory, true); try { var docs = searcher.Search(query, null, SettingCache.MaxHit); IEnumerable <string> results; if (!snode.IsNoPaging) { results = docs.scoreDocs.Select(v => searcher.Doc(v.doc).Get(snode.IndexValue)).Distinct(); } else { results = docs.scoreDocs.Select(v => LuceneNetUtils.FormatTraditionChinese(searcher.Doc(v.doc).Get(snode.IndexValue))).Distinct(); } return(LuceneNetUtils.PageList(results, snode, root)); } finally { searcher.Close(); } }
public static LuceneResultNode SearchMaxHit(IndexBase index, SearchNode node, int maxHit) { try { var query = MultiFieldQueryParser.Parse(Lucene.Net.Util.Version.LUCENE_29, node.Queries, node.Fields, node.Occurs, new PanGuAnalyzer(true)); foreach (ContainFilterNode cf in node.ContainFilters) { query = new FilteredQuery(query, new ContainFilter(new Term(cf.FieldName, cf.Text))); } return(ResponseSearch(index, query, node, maxHit)); } catch (Lucene.Net.QueryParsers.ParseException) { return(new LuceneResultNode() { AllCount = 0, Result = new List <string>() }); } catch (Exception ex) { throw ex; } }
/// <summary> /// Creates a new tags index. /// </summary> /// <param name="readOnly"></param> public TagsIndex(bool readOnly) { _stringIndex = new Index <string>(); _tagsIndex = new Index <int[]>(); if (!readOnly) { // this index is not readonly. _stringReverseIndex = new Dictionary <string, int>(); _tagsReverseIndex = new Dictionary <int[], uint>( new DelegateEqualityComparer <int[]>( (obj) => { // assumed the array is sorted. var hash = obj.Length.GetHashCode(); for (int idx = 0; idx < obj.Length; idx++) { hash = hash ^ obj[idx].GetHashCode(); } return(hash); }, (x, y) => { if (x.Length == y.Length) { for (int idx = 0; idx < x.Length; idx++) { if (x[idx] != y[idx]) { return(false); } } return(true); } return(false); })); } }
/// <summary> /// Creates a new internal tags collection. /// </summary> /// <param name="stringIndex"></param> /// <param name="tags"></param> public InternalTagsCollection(IndexBase <string> stringIndex, int[] tags) { _stringIndex = stringIndex; _tags = tags; }
public void ExtremeCases() { //void index var keyType = new KeyInfo(KeyDataType.IntKey, KeyType.ScalarIndex, "test", true); IndexBase index = populate(); var result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Le); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Eq); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Gt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Ge); Assert.AreEqual(result.Count, 0); //one element index, value not found index = populate(15); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Le); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Eq); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Gt); Assert.AreEqual(result.Count, 1); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Ge); Assert.AreEqual(result.Count, 1); //one element index, value found index = populate(12); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Le); Assert.AreEqual(result.Count, 1); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Eq); Assert.AreEqual(result.Count, 1); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Gt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Ge); Assert.AreEqual(result.Count, 1); //two element index (different values) index = populate(12, 15); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Le); Assert.AreEqual(result.Count, 1); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Eq); Assert.AreEqual(result.Count, 1); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Gt); Assert.AreEqual(result.Count, 1); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Ge); Assert.AreEqual(result.Count, 2); //two element index (same value) index = populate(12, 12); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Le); Assert.AreEqual(result.Count, 2); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Eq); Assert.AreEqual(result.Count, 2); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Gt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Ge); Assert.AreEqual(result.Count, 2); //three element index (same value ==) index = populate(12, 12, 12); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Le); Assert.AreEqual(result.Count, 3); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Eq); Assert.AreEqual(result.Count, 3); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Gt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Ge); Assert.AreEqual(result.Count, 3); //three element index (same value !=) index = populate(15, 15, 15); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Le); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Lt); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Eq); Assert.AreEqual(result.Count, 0); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Gt); Assert.AreEqual(result.Count, 3); result = index.GetMany(MakeIntValue(12, keyType), QueryOperator.Ge); Assert.AreEqual(result.Count, 3); }
protected override void OnValueChanged(IndexBase element, bool oldValue, bool newValue) { if (element.Entity != null) { if (!element.Entity.nHydrateModel.IsLoading && !element.Store.InUndo) { if (element.IndexType == IndexTypeConstants.PrimaryKey) throw new Exception("This is a managed index and cannot be modified."); } } base.OnValueChanged(element, oldValue, newValue); }
public Index() { _base = new IndexBase(); }
public static extern SparseStatus cusparseSetMatIndexBase(IntPtr descrA, IndexBase indexBase);
public static extern SparseStatus cusparseZcsr2csc(IntPtr handle, int m, int n, int nnz, IntPtr csrVal, IntPtr csrRowPtr, IntPtr csrColInd, IntPtr cscVal, IntPtr cscRowInd, IntPtr cscColPtr, int copyValues, IndexBase idxBase);
/// <summary> /// Disposes this enumerator. /// </summary> public void Dispose() { _tags = null; _stringIndex = null; }
/// <summary> /// Creates a new internal tags collection. /// </summary> /// <param name="stringIndex"></param> /// <param name="tags"></param> public InternalTagsEnumerator(IndexBase <string> stringIndex, int[] tags) { _stringIndex = stringIndex; _tags = tags; }