private void RetrieveMatches( ISearchWrapper wrapper, TopDocs hits, IList<MatchingDocument> matchList, Func<MatchingDocument,bool> doesMatch, int first, int count) { var scoreDocs = hits.scoreDocs; // Find the earliest acceptable document int docIndex = 0; Document doc; do { doc = wrapper.IndexSearcher.doc(scoreDocs[docIndex].doc); if (doesMatch(new MatchingDocument(doc))) break; ++docIndex; } while (docIndex < scoreDocs.Length); // Find the document that matches 'first' index int matchIndex = 0; while (matchIndex < first && docIndex < scoreDocs.Length) { doc = wrapper.IndexSearcher.doc(scoreDocs[docIndex].doc); ++docIndex; if (doesMatch(new MatchingDocument(doc))) ++matchIndex; } // Find the remaining matches while (matchList.Count < count && docIndex < scoreDocs.Length) { doc = wrapper.IndexSearcher.doc(scoreDocs[docIndex].doc); ++docIndex; var matchingDoc = new MatchingDocument(doc); if (doesMatch(matchingDoc)) { matchList.Add(matchingDoc); } } }
private bool DoesMatch(MatchingDocument doc) { var mimeType = doc.MimeType; var matches = FileTypes.AcceptedMimeTypes.Contains(mimeType); if (!matches) Console.WriteLine("{0} was not accepted", mimeType); return matches; }
private string CheckMimeType(string url, MatchingDocument doc) { if (!FileTypes.AcceptedMimeTypes.Contains(doc.MimeType)) { throw new ArgumentException("Not a valid image url: " + url); } return doc.MimeType; }
private dynamic ToMatchingItem(MatchingDocument match, string[] propertyList) { var keywords = match.Keywords ?? ""; var path = match.SignatureIndexPath; var resolveValue = new Func<string,object>( name => { switch(name.ToLowerInvariant()) { case "id": return PathToId(path); case "relativepath": return Searcher.ToRelativePath(path); case "fullurl": return PathToUrl(path); case "thumburl": return PathToThumbUrl(path); case "imagename": return Path.GetFileName(path); case "keywords": return keywords.Split(','); case "mimetype": return match.MimeType; case "createddate": return match.CreatedDate.Value.ToString(); case "formattedcreateddate": return match.CreatedDate.Value.ToString(ClientDateFormat); case "formattedcreatedtimestamp": return match.CreatedDate.Value.ToString(ClientDateTimeFormat); case "signature": return match.SignatureHash; case "length": return match.SignatureFileLength; case "geolocation": return match.GpsPosition; case "latitude": return match.Latitude; case "longitude": return match.Longitude; case "city": return match.City ?? ""; case "country": return match.Country ?? ""; case "locationname": return match.StandardName ?? match.City ?? ""; case "lensinfo": return match.LensInfo ?? ""; case "lensmodel": return match.LensModel ?? ""; case "make": return match.Make ?? ""; case "model": return match.Model ?? ""; case "slideurl": return PathToSlideUrl(path); } return null; }); dynamic mi = new ExpandoObject(); var miAccess = (IDictionary<String, Object>)mi; foreach (var propertyName in propertyList) { var propertyValue = resolveValue(propertyName); if (propertyValue != null) miAccess.Add(propertyName, propertyValue); } return mi; }