public void ShouldReadSubFingerprintsByReference() { var trackReference = new SolrModelReference("track-id"); var results = new SolrQueryResults <SubFingerprintDTO>(); var dto = new SubFingerprintDTO { Clusters = new[] { "CA" }, SubFingerprintId = "123-123", Hashes = new Dictionary <int, long>(), SequenceAt = 10d, SequenceNumber = 10, TrackId = "track-id" }; results.AddRange(new List <SubFingerprintDTO> { dto }); solr.Setup(s => s.Query("trackId:track-id")).Returns(results); dictionaryToHashConverter.Setup(dhc => dhc.FromSolrDictionaryToHashes(It.IsAny <IDictionary <int, long> >())) .Returns(new long[0]); hashConverter.Setup(hc => hc.ToBytes(It.IsAny <long[]>(), It.IsAny <int>())).Returns(new byte[0]); var subs = subFingerprintDao.ReadHashedFingerprintsByTrackReference(trackReference); Assert.AreEqual(1, subs.Count); CollectionAssert.AreEqual(new[] { "CA" }, subs.First().Clusters); }
public static SubFingerprintData CopyToSubFingerprintData(SubFingerprintDTO dto) { return(new SubFingerprintData( dto.HashBins, (uint)dto.SequenceNumber, (float)dto.SequenceAt, new ModelReference <string>(dto.SubFingerprintId), new ModelReference <string>(dto.TrackId))); }
private SubFingerprintData GetSubFingerprintData(SubFingerprintDTO dto) { long[] hashes = GetHashes(dto); return(new SubFingerprintData( hashes, dto.SequenceNumber, dto.SequenceAt, new ModelReference <long>(dto.Id), new ModelReference <int>(dto.TrackId))); }
private SubFingerprintData GetSubFingerprintData(SubFingerprintDTO dto) { long[] resultHashBins = this.dictionaryToHashConverter.FromSolrDictionaryToHashes(dto.Hashes); var sub = new SubFingerprintData( resultHashBins, dto.SequenceNumber, dto.SequenceAt, new SolrModelReference(dto.SubFingerprintId), new SolrModelReference(dto.TrackId)); return(sub); }
private long[] GetHashes(SubFingerprintDTO dto) { long[] hashes = new[] { dto.HashTable_0, dto.HashTable_1, dto.HashTable_2, dto.HashTable_3, dto.HashTable_4, dto.HashTable_5, dto.HashTable_6, dto.HashTable_7, dto.HashTable_8, dto.HashTable_9, dto.HashTable_10, dto.HashTable_11, dto.HashTable_12, dto.HashTable_13, dto.HashTable_14, dto.HashTable_15, dto.HashTable_16, dto.HashTable_17, dto.HashTable_18, dto.HashTable_19, dto.HashTable_20, dto.HashTable_21, dto.HashTable_22, dto.HashTable_23, dto.HashTable_24 }; return(hashes); }
public SubFingerprintData ReadSubFingerprintDataByReference(IModelReference id) { // Get fingerprint collection var col = db.GetCollection <SubFingerprintDTO>("fingerprints"); // ensure indexes col.EnsureIndex(x => x.SubFingerprintId); // return by id var result = col.FindById(new BsonValue(id.Id)); return(SubFingerprintDTO.CopyToSubFingerprintData(result)); }
public void SolrFrameworkCanRunComplexQueries() { var doc1 = new SubFingerprintDTO { SubFingerprintId = "1", TrackId = "1", Hashes = new Dictionary <int, long> { { 0, 10 }, { 1, 11 }, { 2, 12 }, { 3, 13 }, { 4, 14 } } }; var doc2 = new SubFingerprintDTO { SubFingerprintId = "2", TrackId = "2", Hashes = new Dictionary <int, long> { { 0, 10 }, { 1, 11 }, { 2, 20 }, { 3, 21 }, { 4, 22 } } }; var solr = DependencyResolver.Current.Get <ISolrOperations <SubFingerprintDTO> >(); solr.Add(doc1); solr.Add(doc2); solr.Commit(); var query = new SolrQuery("_query_:\"{!edismax mm=4}hashTable_0:10 hashTable_1:11 hashTable_2:12 hashTable_3:21 hashTable_4:22\" _query_:\"{!edismax mm=4}hashTable_0:10 hashTable_1:11 hashTable_2:20 hashTable_3:21 hashTable_4:22\""); var docs = solr.Query(query); Assert.AreEqual(1, docs.Count); var result = docs.First(); Assert.AreEqual(doc2.SubFingerprintId, result.SubFingerprintId); this.TearDownDocs(solr, new List <SubFingerprintDTO> { doc1, doc2 }); }
public void InsertHashDataForTrack(IEnumerable <HashedFingerprint> hashes, IModelReference trackReference) { var dtos = hashes.Select(hash => SubFingerprintDTO.CopyToSubFingerprintDTO(trackReference, hash)) .ToList(); // Get fingerprint collection var col = db.GetCollection <SubFingerprintDTO>("fingerprints"); // insert hashes objects // Note! If we are using a separate table for // the hashtables we should ignore the HashBin property on the SubFingerprintDTO // to avoid duplicating the information and making the // database larger than neccesary // e.g. var mapper = BsonMapper.Global.Entity<SubFingerprintDTO>().Ignore(x => x.HashBins); // don't use the hashbin element,rather a separate table var bson = col.InsertBulk(dtos); // then insert the HashBin property into a separate table // note: this makes the database significantly larger foreach (var dto in dtos) { // insert each hash as a separate object InsertHashBinsToSeparateTable(dto.HashBins, dto.SubFingerprintId, (string)trackReference.Id); } }
private HashedFingerprint GetHashedFingerprint(SubFingerprintDTO subFingerprintDto) { long[] hashBins = dictionaryToHashConverter.FromSolrDictionaryToHashes(subFingerprintDto.Hashes); byte[] signature = hashConverter.ToBytes(hashBins, fingerprintLength); return(new HashedFingerprint(signature, hashBins, subFingerprintDto.SequenceNumber, subFingerprintDto.SequenceAt, subFingerprintDto.Clusters)); }