[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Address search algorithms

Mikel Lindsaar

5/30/2008 9:09:00 AM

[Note: parts of this message were removed to make it a legal post.]

Heya all,
Got an interesting little problem, not specifically Ruby, but I hope to
solve it with some nice ruby :)

I need to be able to do searches on a data set of a street address.

The address has three fields, what is needed is an efficient way to search
this address with partial data.

The addresses are in a database, what I am thinking is going through and pre
generating a search string based on the three concatenated address values
and then index this search column and search off that using the output from
the same algorithm on the entered search values.

Would full text search be the best solution here? The DB is on postgres by
the well.

The problem is that someone might want to search for "back st" and expect to
match "123 back street", or worse, "123 back lane" and get "123 back street"

Anyone else run into these sorts of problems, any feed back?


Mikel

3 Answers

Eleanor McHugh

5/30/2008 10:41:00 AM

0

On 30 May 2008, at 10:09, Mikel Lindsaar wrote:
> Heya all,
> Got an interesting little problem, not specifically Ruby, but I hope
> to
> solve it with some nice ruby :)
>
> I need to be able to do searches on a data set of a street address.
>
> The address has three fields, what is needed is an efficient way to
> search
> this address with partial data.

Assuming these are UK-only addresses, at the very least you should
have four fields:

* building name/number;
* street;
* town;
* postcode

and the national postcode database allows for seven if I remember
correctly - although it's usual for a couple of those to be blank.
Depending on how well normalised you want the database it can be a
good idea to split out the last three into their own tables and only
store keys in your main address table. You'll get the biggest gain
from doing that with towns, but streets are normally a good gain as
well. Oh, and obviously use indexes.

> The addresses are in a database, what I am thinking is going through
> and pre
> generating a search string based on the three concatenated address
> values
> and then index this search column and search off that using the
> output from
> the same algorithm on the entered search values.
>
> Would full text search be the best solution here? The DB is on
> postgres by
> the well.
>
> The problem is that someone might want to search for "back st" and
> expect to
> match "123 back street", or worse, "123 back lane" and get "123 back
> street"

* Keep a dictionary of well known abbreviations and massage the query
to expand these;
* store the street number in its own column (which won't necessarily
be numeric thanks to all the Flat 1's and 22B's lurking in the system,
not to mention named properties without a number etc.);
* store the postcode in its own column and filter by postcode whenever
possible;
* use a soundex algorithm to store all words as phonetic
approximations to deal with simple misspellings (bock vs. back, bak
vs. back);
* AND MOST IMPORTANTLY: constrain the way the user can enter a query
so that it keeps the query as simple as possible;
* use whatever full text search facility postgres has

> Anyone else run into these sorts of problems, any feed back?

Many many years ago :)
Out of interest, are you using the postcode database to generate your
address information, or is it user-submitted data? If the latter, make
sure you constrain how data can be submitted. And either way, do as
much pre-processing as possible to get the addresses into a normalised
form.


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-...
----
raise ArgumentError unless @reality.responds_to? :reason



Mikel Lindsaar

5/30/2008 12:08:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

>
> Many many years ago :)
>

Thanks all for your tips!

I have already implemented most of them... but some of them are also good
ideas.

> Out of interest, are you using the postcode database to generate your
address
> information, or is it user-submitted data? If the latter, make sure you
constrain
> how data can be submitted. And either way, do as much pre-processing as
> possible to get the addresses into a normalised form.

This is pre-existing data... the worst kind :)

Mikel

Eleanor McHugh

5/30/2008 12:23:00 PM

0

On 30 May 2008, at 13:08, Mikel Lindsaar wrote:
> This is pre-existing data... the worst kind :)

You have my sympathy ;)


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-...
----
raise ArgumentError unless @reality.responds_to? :reason