static public bool ShouldAdd(ElasticsearchClient client, ref CandidateFile candidate) { var searchQuery = new { query = new { term = new { _id = candidate.AliasedPath } } }; ElasticsearchResponse<string> response; var timer = new ScopedTimer(); using (timer) { response = client.Search<string>(Media.IndexName, JsonConvert.SerializeObject(searchQuery)); } if (!FirstSearchMsec.HasValue) { FirstSearchMsec = timer.TotalMilliseconds; } if (!response.Success) { response.LogFailure(logger); return false; } candidate.Signature = CalculateSignature(candidate.FullFilename); candidate.LengthInBytes = new FileInfo(candidate.FullFilename).Length; var searchResponse = JsonConvert.DeserializeObject<SearchResponse>(response.Response); // if ((timer.TotalMilliseconds - searchResponse.Took) > 200) // { // logger.Warn("Search took {1} milliseconds for: {0}", candidate.AliasedPath, timer.TotalMilliseconds); // } // If there's more than one matching path or the signature is different, go through the add process // If it's not already in the index, add it. if (searchResponse.Hits.Total != 1) return true; var media = searchResponse.Hits.Hits.First().Media; if (media.Signature != candidate.Signature || media.LengthInBytes != candidate.LengthInBytes) { logger.Error("Add {0} due to mis-match ({0}, {1} -- {2}, {3})", candidate.AliasedPath, media.Signature, media.LengthInBytes, candidate.Signature, candidate.LengthInBytes); return true; } return false; }
public void Add(CandidateFile candidate) { candidateFiles.TryAdd(candidate.FullFilename.ToLower(), candidate); }
public ExifFolder(string folder, CandidateFile candidate) { Folder = folder; candidateFiles.TryAdd(candidate.FullFilename.ToLower(), candidate); }