Hi,
This is a bit tricky but I think you can achieve it as follows:
1. have a field called "location_facet" which holds the logical path of
the location for each address (e.g. /Eurpoe/England/London)
2. have another multi valued filed "location_search" that holds all the
locations - your "catchall" field.
3. When the user searches for "England", perform the search on the
"location_search" field.
4. Always facet on the "location_facet" field
5. When you get the response, drop the most common prefix from all the
facet values, so for example if you search on "England":
returned facets:
/Europe/England/London..............5
/Europe/England/Manchester........6
/Europe/England/Liverpool...........3
after dropping the common prefix (which is /Europe/England):
London............5
Manchester.....6
Liverpool........3
note that theoretically (and perhaps even realistically) you might also
have multiple prefixes (for example, in the US you can definitely have
several cities with the same name in different states), in which case
you'd probably want to group these results by the prefix:
(for the sake of the argument, let's assume there's an "England" state
in the US :-))
/Europe/England
London............5
Manchester......6
Liverpool.........3
/North America/USA/England
AnotherCity..........10
On the client side, when the user clicks on one of the facet values, you
should use value path as a wildcard filter on the "location_facet"
field. For example, if the user click on London (the city in England),
the you should add the following filter:
location_facet:/Europe/England/London/*
this is a bit of manual work to do on the results, but I think it should
work, but maybe someone has a better idea on how to do it in a cleaner way.
cheers,
Uri
thibault jouannic wrote:
Hi Solr users,
This is my first post on this list, so nice to meet you.
I need to do something with solr, but I have no idea how to achieve this. Let
me describe my problem.
I'm building an address search engine. In my Solr schema, I've got many fields
like «country», «state», «town», «street».
I want my users to search an address by location, so I've set up a catchall
field containing a copy of all the other fields. This is my default search
field.
I want to propose a dynamic facet search : if a user searches for the term
«USA», the used facet.field will be «state», but if he searches for «Chicago»,
facet.field will be «street». If a user is searching for an address in Chicago,
it would be stupid to propose a facet search on the «country» field, would'nt
it?
However, how can I know which field is matched ? If the user search «France»,
how can I know if this is a country or a town ?
Is anybody has an idea?
Best regards,
Thibault.