C # LINQ SEO General programming question, how to get search results correctly?

sorry for the title :)

Here is my main problem, I am trying to implement an SEO type request for a location.

Here are my examples

  • / Leeds
  • / Leeds_England
  • / Hampshire_England England_Leeds
  • / Europe_England

I try to get the location, now I break into "_" and then look through LINQ through my list for each part. Location

City Province Region Country Continent

If I find a number with a large number, I set the variable as "cityFound" and add the results to a range of locations.

Then I check LINQ again for these results in the split to see what I have, try and work out if each divided part is in the same place.

, , , "". , , , .

, , ? - , , !

, .

+3
5

, , - . , , .

- - . -, , . , -, - - -, . , , -. , . , . .

+1

, . URL-, , . , "" , . , . , , , , , .

0

, , , . , "SEO", . ( ).

, ... , . , .

, , .

0

. - , .

, - Las Vegas Phoenix.

. ( - # .)

class LocationResolver {
    private IEnumerable<Location> locations;
    private Map<String, Location> memory = new Map<String, Location>();

    public LocationResolver(IEnumerable<Location> locs) {
        locations = locs;
        //
        // Add any locations that need disambiguation
        //
        memory["/Las Vegas"] = FromUrl("/Las Vegas_Nevada");
        memory["/Phoenix"] = FromUrl("/Phoenix_Arizona");
    }

    public Location Resolve(string url) {
        Location result;
        if (memory.TryGet(url, out result)) {
            result = FindWithParts(url.Substring(1).Split('_'));
            memory[url] = result;
        }
        return result;
    }

    private Location FindWithParts(string[] parts) {
        string[] locParts = new string[5];
        for (Location l in locations) {
            locParts[0] = l.City;
            locParts[1] = l.Province;
            locParts[2] = l.Region;
            locParts[3] = l.Country;
            locParts[4] = l.Continent;
            bool found = true;
            for (int i = 0; i < parts.Length && found; i++)
                found = Array.IndexOf(locParts, parts[i]) >= 0;
            }
            if (found) {
                return l;
            }
        }
        return null;
    }
}
0

, , .

CityText ProvinceText ..

_ , , .

CityText = ProvinceText =

Then I looked at the results and looked at the results where.

Where are all the locations == Leeds

and all locations == West Yorkshire

and x and x

Then I have places below that satisfy all parts of the location.

Cheers for the code though!

Sarkie.

0
source

All Articles