public ICollection <CelestialObject> Search(SkyContext c, string searchString, Func <CelestialObject, bool> filterFunc, int maxCount = 50) { var match = searchRegex.Match(searchString.ToLowerInvariant()); if (match.Success) { int tyc1 = int.Parse(match.Groups["tyc1"].Value); short? tyc2 = match.Groups["tyc2"].Success ? short.Parse(match.Groups["tyc2"].Value) : (short?)null; string tyc3 = match.Groups["tyc3"].Value; if (tyc1 > 0 && tyc1 <= 9537) { Tycho2Region region = IndexRegions.ElementAt(tyc1 - 1); var stars = GetStarsInRegion(region, c, tyc2, tyc3); return(stars.Where(filterFunc).Take(maxCount).ToArray()); } } return(new CelestialObject[0]); }
public ICollection <SearchResultItem> Search(SkyContext c, string searchString, int maxCount = 50) { var match = searchRegex.Match(searchString.ToLowerInvariant()); if (match.Success) { int tyc1 = int.Parse(match.Groups["tyc1"].Value); short? tyc2 = match.Groups["tyc2"].Success ? short.Parse(match.Groups["tyc2"].Value) : (short?)null; string tyc3 = match.Groups["tyc3"].Value; if (tyc1 > 0 && tyc1 <= 9537) { Tycho2Region region = IndexRegions.ElementAt(tyc1 - 1); var stars = GetStarsInRegion(region, c, tyc2, tyc3); return(stars.Take(maxCount).Select(s => new SearchResultItem(s, s.ToString())).ToList()); } } return(new List <SearchResultItem>()); }
private ICollection <Tycho2Star> GetStarsInRegion(Tycho2Region region, SkyContext c, short?tyc2, string tyc3) { // seek reading position CatalogReader.BaseStream.Seek(CATALOG_RECORD_LEN * (region.FirstStarId - 1), SeekOrigin.Begin); // count of records in current region int count = (int)(region.LastStarId - region.FirstStarId); // read region in memory for fast access byte[] buffer = CatalogReader.ReadBytes(CATALOG_RECORD_LEN * count); var stars = new List <Tycho2Star>(); for (int i = 0; i < count && stars.Count < 50; i++) { Tycho2Star star = GetStar(c, buffer, i * CATALOG_RECORD_LEN, tyc2, tyc3); if (star != null) { stars.Add(star); } } return(stars); }
private ICollection <Tycho2Star> GetStarsInRegion(SkyContext c, Tycho2Region region, CrdsEquatorial eq, double angle, Func <float, bool> magFilter) { // seek reading position CatalogReader.BaseStream.Seek(CATALOG_RECORD_LEN * (region.FirstStarId - 1), SeekOrigin.Begin); // count of records in current region int count = (int)(region.LastStarId - region.FirstStarId); // read region in memory for fast access byte[] buffer = CatalogReader.ReadBytes(CATALOG_RECORD_LEN * count); var stars = new List <Tycho2Star>(); for (int i = 0; i < count; i++) { Tycho2Star star = GetStar(c, buffer, i * CATALOG_RECORD_LEN, eq, angle, magFilter); if (star != null) { stars.Add(star); } } return(stars); }