我已经编写了一个网站搜索,它遍历某个文件夹下的所有节点,然后根据某些条件过滤掉节点。该网站本身用于搜索公寓。这是我用于构建集合的功能:
private static List<Apartment> GetApartmentsCollection()
{
List<Apartment> apartmentsCollection = new List<Apartment>();
Document apartmentsContainer = new Document(Convert.ToInt32(ConfigurationManager.AppSettings["apartmentsContainerNodeId"]));
if (apartmentsContainer.HasChildren)
{
Document[] buildings = apartmentsContainer.Children;
foreach (Document building in buildings)
{
if (building.Published)
{
// Store building id for apartment
int buildingId = building.Id;
if (building.HasChildren)
{
Document[] apartments = building.Children;
foreach (Document apartment in apartments)
{
if (apartment.Published)
{
apartmentsCollection.Add(new Apartment(apartment.Id,
buildingId,
Convert.ToInt32(apartment.Text),
(int)apartment.getProperty("apartmentType").Value,
(int)apartment.getProperty("floor").Value,
(int)apartment.getProperty("status").Value,
(int)apartment.getProperty("bedrooms").Value,
Convert.ToInt32(apartment.getProperty("price").Value),
string.IsNullOrEmpty(apartment.getProperty("room1").Value.ToString()) == true ? -1 : Convert.ToInt32(apartment.getProperty("room1").Value.ToString()),
apartment.getProperty("room1Dimensions").Value.ToString(),
string.IsNullOrEmpty(apartment.getProperty("room2").Value.ToString()) == true ? -1 : Convert.ToInt32(apartment.getProperty("room2").Value.ToString()),
apartment.getProperty("room2Dimensions").Value.ToString(),
string.IsNullOrEmpty(apartment.getProperty("room3").Value.ToString()) == true ? -1 : Convert.ToInt32(apartment.getProperty("room3").Value.ToString()),
apartment.getProperty("room3Dimensions").Value.ToString(),
string.IsNullOrEmpty(apartment.getProperty("room4").Value.ToString()) == true ? -1 : Convert.ToInt32(apartment.getProperty("room4").Value.ToString()),
apartment.getProperty("room4Dimensions").Value.ToString(),
string.IsNullOrEmpty(apartment.getProperty("room5").Value.ToString()) == true ? -1 : Convert.ToInt32(apartment.getProperty("room5").Value.ToString()),
apartment.getProperty("room5Dimensions").Value.ToString(),
string.IsNullOrEmpty(apartment.getProperty("room6").Value.ToString()) == true ? -1 : Convert.ToInt32(apartment.getProperty("room6").Value.ToString()),
apartment.getProperty("room6Dimensions").Value.ToString(),
string.IsNullOrEmpty(apartment.getProperty("room7").Value.ToString()) == true ? -1 : Convert.ToInt32(apartment.getProperty("room7").Value.ToString()),
apartment.getProperty("room7Dimensions").Value.ToString(),
apartment.getProperty("totalArea").Value.ToString(),
apartment.getProperty("projectArea").Value.ToString()));
}
}
}
}
}
}
return apartmentsCollection;
}
唯一的问题是这需要 8 到 10 秒左右(即使只有大约 150 个节点顶部),这太长了。
请记住,这仅用于检索原始集合。然后我使用一些 linq 语句过滤掉结果,这需要几秒钟。最终,这导致搜索约 150 个节点需要大约 15 秒,这太长了。
我怎样才能加快速度?
谢谢