logo separator

[mkgmap-dev] multi-word street search

From Andrzej Popowski popej at poczta.onet.pl on Mon Dec 15 23:44:53 GMT 2014

Hi,

 > Selection list is not sorted and some streets are repeated in it

My next experiment to remove repeated streets, patch attached.

And here mkgmap for tests:
http://files.mkgmap.org.uk/download/240/mkgmap.jar

-- 
Best regards,
Andrzej
-------------- next part --------------
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr7.java	2014-12-15 13:02:46.823219100 +0100
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr7.java	2014-12-16 00:30:11.460899900 +0100
@@ -12,6 +12,8 @@
  */
 package uk.me.parabola.imgfmt.app.mdr;
 
+import java.nio.charset.Charset;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -40,9 +42,11 @@
 	private List<Mdr7Record> streets = new ArrayList<>();
 
 	private final int u2size = 1;
+	private final Charset charset;
 
 	public Mdr7(MdrConfig config) {
 		setConfig(config);
+		charset = config.getSort().getCharset();
 	}
 
 	public void addStreet(int mapId, String name, int lblOffset, int strOff, Mdr5Record mdrCity) {
@@ -56,13 +60,9 @@
 		allStreets.add(st);
 
 		boolean start = false;
-		int nameOffset = -1;
-		for (int i = 0; i < name.length() - 2; i++) {
-			char c = name.charAt(i);
-			if (c < ' ')
-				continue;
-
-			nameOffset++;
+		int nameOffset = (name.charAt(0) < ' ')? 1: 0;
+		for (; nameOffset < name.length() - 2; nameOffset++) {
+			char c = name.charAt(nameOffset);
 
 			if (Character.isWhitespace(c)) {
 				start = true;
@@ -83,8 +83,8 @@
 				st.setName(name);
 				st.setCity(mdrCity);
 				st.setNameOffset(nameOffset);
-				System.out.printf("%s %d\n", st.getName(), st.getNameOffset());
-				System.out.println("add partial " + st.getPartialName());
+				//System.out.printf("%s %d\n", st.getName(), st.getNameOffset());
+				//System.out.println("add partial " + st.getPartialName());
 				allStreets.add(st);
 				start = false;
 			}
@@ -101,7 +101,7 @@
 		Sort sort = getConfig().getSort();
 		List<SortKey<Mdr7Record>> sortedStreets = new ArrayList<SortKey<Mdr7Record>>(allStreets.size());
 		for (Mdr7Record m : allStreets) {
-			SortKey<Mdr7Record> sortKey = sort.createSortKey(m, m.getPartialName(),	m.getMapIndex()<<16+m.getNameOffset());
+			SortKey<Mdr7Record> sortKey = sort.createSortKey(m, m.getPartialName() + " " + m.getName(),	m.getMapIndex()<<16+m.getNameOffset());
 			sortedStreets.add(sortKey);
 		}
 		Collections.sort(sortedStreets);
@@ -262,8 +262,10 @@
 			if (hasStrings)
 				putStringOffset(writer, s.getStringOffset());
 
-			if (hasNameOffset)
-				writer.put((byte) (s.getNameOffset()));
+			if (hasNameOffset) {
+				byte skipName[] = name.substring(0, s.getNameOffset()).getBytes(charset);
+				writer.put((byte) (skipName.length));
+			}
 
 			putN(writer, u2size, trailingFlags);
 		}
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr7Record.java	2014-12-15 13:02:46.823219100 +0100
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr7Record.java	2014-12-15 18:19:36.359019000 +0100
@@ -83,7 +83,7 @@
 	 * @return A substring of name, starting at the nameOffset value.
 	 */
 	public String getPartialName() {
-		return nameOffset == 0 ? name : name.substring(nameOffset + ((name.charAt(0) < ' ')? 1: 0));
+		return nameOffset == 0 ? name : name.substring(nameOffset);
 	}
 
 	public String toString() {


More information about the mkgmap-dev mailing list