public string SearchProducts(string searchterms, int searchIDResult) { checkCookieAndLogin(); XDocument doc = new XDocument(); using (var unit = (IServiceUnitOfWork)GetUnitOfWork()) { //var searchResultSet = ((IProductService)unit.Service<Product>()).SearchProducts(Client.User.LanguageID, // Client.User.ConnectorID.Value, // searchterms, // true, // true, // true, // true // ).Distinct(); LuceneIndexer indexer = new LuceneIndexer(); var modelList = indexer.GetSearchResultsFromIndex(searchterms); var results = new XElement("Results"); switch (searchIDResult) { default: // ProductID { results.Add(from p in modelList.Distinct() select new XElement("Product", new XAttribute("ID", p.ProductID), new XAttribute("Name", p.ProductName ?? ""), new XAttribute("Description", p.ProductDescription ?? ""), new XAttribute("ImagePath", !string.IsNullOrEmpty(p.ImagePath) ? string.Format("{0}/imagetranslate.ashx?mediapath={1}&width=128&height=96", BaseSiteUrl, p.ImagePath) : string.Empty) )); } break; case 1: // customer item number { //TODO : This needs some SQL/LINQ guru cleaning it up var products = unit.Service <VendorAssortment>().GetAll(); results.Add(from p in modelList.Distinct() where p.ProductName != null && !string.IsNullOrEmpty(p.ImagePath) select new XElement("Product", new XAttribute("ID", products.First(c => c.ProductID == p.ProductID).CustomItemNumber), new XAttribute("Name", p.ProductName), new XAttribute("Description", p.ProductDescription ?? ""), new XAttribute("ImagePath", string.Format("{0}/imagetranslate.ashx?mediapath={1}&width=128&height=96", BaseSiteUrl, p.ImagePath)) )); } break; } doc.Add(results); } return(doc.ToString()); }