/[zanavi_public1]/navit/navit/search.c
ZANavi

Diff of /navit/navit/search.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 14 Revision 15
142{ 142{
143 struct search_list_level *le; 143 struct search_list_level *le;
144 int level=search_list_level(search_attr->type); 144 int level=search_list_level(search_attr->type);
145 this_->item=NULL; 145 this_->item=NULL;
146 interpolation_clear(&this_->inter); 146 interpolation_clear(&this_->inter);
147 //dbg(0,"enter\n"); 147 //dbg(0,"## enter\n");
148 //dbg(0,"level=%d\n", level); 148 //dbg(0,"## level=%d\n", level);
149 if (level != -1) { 149 if (level != -1)
150 {
150 this_->result.id=0; 151 this_->result.id=0;
151 this_->level=level; 152 this_->level=level;
152 le=&this_->levels[level]; 153 le=&this_->levels[level];
153 search_list_search_free(this_, level); 154 search_list_search_free(this_, level);
154 le->attr=attr_dup(search_attr); 155 le->attr=attr_dup(search_attr);
155 le->partial=partial; 156 le->partial=partial;
156 if (level > 0) { 157 if (level > 0)
158 {
157 le=&this_->levels[level-1]; 159 le=&this_->levels[level-1];
158 le->curr=le->list; 160 le->curr=le->list;
159 } 161 }
160 //dbg(0,"le=%p partial=%d\n", le, partial); 162 //dbg(0,"## le=%p partial=%d\n", le, partial);
163 }
161 } else if (search_attr->type == attr_postal) { 164 else if (search_attr->type == attr_postal)
165 {
162 g_free(this_->postal); 166 g_free(this_->postal);
163 this_->postal=g_strdup(search_attr->u.str); 167 this_->postal=g_strdup(search_attr->u.str);
164 } 168 }
165 //dbg(0,"return\n"); 169 //dbg(0,"## return\n");
166} 170}
167 171
168struct search_list_common * 172struct search_list_common *
169search_list_select(struct search_list *this_, enum attr_type attr_type, int id, int mode) 173search_list_select(struct search_list *this_, enum attr_type attr_type, int id, int mode)
170{ 174{
658static int 662static int
659search_add_result(struct search_list_level *le, struct search_list_common *slc) 663search_add_result(struct search_list_level *le, struct search_list_common *slc)
660{ 664{
661 struct search_list_common *slo; 665 struct search_list_common *slo;
662 char *merged; 666 char *merged;
667
668 //dbg(0,"enter\n");
669
663 slo=g_hash_table_lookup(le->hash, &slc->unique); 670 //slo=g_hash_table_lookup(le->hash, &slc->unique);
664 if (!slo) { 671 //if (!slo) {
665 g_hash_table_insert(le->hash, &slc->unique, slc); 672 //g_hash_table_insert(le->hash, &slc->unique, slc);
666 if (slc->postal && !slc->postal_mask) { 673 if (slc->postal && !slc->postal_mask)
674 {
667 slc->postal_mask=g_strdup(slc->postal); 675 slc->postal_mask=g_strdup(slc->postal);
668 } 676 }
677 // ******
678 g_list_free(le->list);
679 le->list=NULL;
680 // ******
669 le->list=g_list_append(le->list, slc); 681 le->list=g_list_append(le->list, slc);
670 return 1; 682 return 1;
671 } 683 //}
672 merged=search_postal_merge(slo->postal_mask, slc->postal); 684 merged=search_postal_merge(slo->postal_mask, slc->postal);
673 if (merged) { 685 if (merged)
686 {
674 g_free(slo->postal_mask); 687 g_free(slo->postal_mask);
675 slo->postal_mask=merged; 688 slo->postal_mask=merged;
676 } 689 }
677 return 0; 690 return 0;
678} 691}
717 break; 730 break;
718 if (slc->selected == leu->selected) 731 if (slc->selected == leu->selected)
719 break; 732 break;
720 } 733 }
721 } 734 }
735#if 0
722 //if (le->parent) 736 if (le->parent)
723 //{ 737 {
724 // //dbg(0,"mapset_search_new with item(%d,%d)\n", le->parent->item.id_hi, le->parent->item.id_lo); 738 dbg(0,"mapset_search_new with item(%d,%d)\n", le->parent->item.id_hi, le->parent->item.id_lo);
725 //} 739 }
726 //else 740 else
727 //{ 741 {
728 // dbg(0,"NO parent!!\n"); 742 dbg(0,"NO parent!!\n");
729 //} 743 }
730 // dbg(0,"############## attr=%s\n", attr_to_name(le->attr->type)); 744 dbg(0,"############## attr=%s\n", attr_to_name(le->attr->type));
745#endif
731 le->search=mapset_search_new(this_->ms, &le->parent->item, le->attr, le->partial); 746 le->search=mapset_search_new(this_->ms, &le->parent->item, le->attr, le->partial);
732 // ** DOC ** mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial) 747 // ** DOC ** mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial)
733 le->hash=g_hash_table_new(search_item_hash_hash, search_item_hash_equal); 748 le->hash=g_hash_table_new(search_item_hash_hash, search_item_hash_equal);
734 } 749 }
750
735 //dbg(0,"le->search=%p\n", le->search); 751 //dbg(0,"le->search=%p\n", le->search);
752
736 if (!this_->item) 753 if (!this_->item)
737 { 754 {
738 //dbg(0,"sssss 1"); 755 //dbg(0,"sssss 1");
739 this_->item=mapset_search_get_item(le->search); 756 this_->item=mapset_search_get_item(le->search);
740 //dbg(0,"sssss 1 %p\n",this_->item); 757 //dbg(0,"sssss 1 %p\n",this_->item);
741 } 758 }
759
742 if (this_->item) 760 if (this_->item)
743 { 761 {
744 void *p=NULL; 762 void *p=NULL;
745 //dbg(0,"id_hi=%d id_lo=%d\n", this_->item->id_hi, this_->item->id_lo); 763 //dbg(0,"id_hi=%d id_lo=%d\n", this_->item->id_hi, this_->item->id_lo);
746 if (this_->postal) 764 if (this_->postal)
836 // this crashes all the time -> so dont use! 854 // this crashes all the time -> so dont use!
837 // 855 //
838 this_->result.street->name=NULL; 856 this_->result.street->name=NULL;
839 } 857 }
840 //dbg(0,"case 3 XXXX 5\n"); 858 //dbg(0,"case 3 XXXX 5\n");
859 break;
841 } 860 }
861 // CASE END *********
862
863
842 if (p) 864 if (p)
843 { 865 {
844 if (search_add_result(le, p)) 866 if (search_add_result(le, p))
845 { 867 {
868 //** this_->result.id++;
846 this_->result.id++; 869 this_->result.id=0;
870 //dbg(0,"++++ return result\n");
847 return &this_->result; 871 return &this_->result;
848 } 872 }
849 else 873 else
850 { 874 {
851 search_list_result_destroy(level, p); 875 search_list_result_destroy(level, p);
876 // return &this_->result;
852 } 877 }
853 } 878 }
879 }
854 } else { 880 else
881 {
855 mapset_search_destroy(le->search); 882 mapset_search_destroy(le->search);
856 le->search=NULL; 883 le->search=NULL;
857 g_hash_table_destroy(le->hash); 884 g_hash_table_destroy(le->hash);
858 if (! level) 885 if (! level)
886 {
859 break; 887 break;
888 }
860 } 889 }
861 } 890 }
862 return NULL; 891 return NULL;
863} 892}
864 893
943 972
944 //dbg(0,"enter\n"); 973 //dbg(0,"enter\n");
945 974
946 while ((slr=search_list_get_result(sl))) 975 while ((slr=search_list_get_result(sl)))
947 { 976 {
977 if (offline_search_break_searching==1)
978 {
979 break;
980 }
981
948 // does the streetname of the housenumber match the street we want? 982 // does the streetname of the housenumber match the street we want?
949 if (slr != NULL) 983 if (slr != NULL)
950 { 984 {
951 if (slr->street != NULL) 985 if (slr->street != NULL)
952 if ((street_name != NULL)&&(slr->street->name != NULL)) 986 if ((street_name != NULL)&&(slr->street->name != NULL))
998 int count=0; 1032 int count=0;
999 struct coord_geo g; 1033 struct coord_geo g;
1000 struct coord c; 1034 struct coord c;
1001 struct attr attr2; 1035 struct attr attr2;
1002 1036
1037 struct item *save_item;
1038 int save_level;
1039 int save_last_result_valid;
1003 1040
1004 while ((slr=search_list_get_result(sl))) 1041 while ((slr=search_list_get_result(sl)))
1005 { 1042 {
1006 char *buffer; 1043 char *buffer;
1007 char *buffer2; 1044 char *buffer2;
1045
1046 if (offline_search_break_searching==1)
1047 {
1048 break;
1049 }
1008 1050
1009 if (slr->street) 1051 if (slr->street)
1010 { 1052 {
1011 // coords of result 1053 // coords of result
1012 c.x=slr->street->common.c->x; 1054 c.x=slr->street->common.c->x;
1033 android_return_search_result(jni,buffer); 1075 android_return_search_result(jni,buffer);
1034 #endif 1076 #endif
1035 count++; 1077 count++;
1036 1078
1037 buffer2=g_strdup_printf("%s", slr->street->name); 1079 buffer2=g_strdup_printf("%s", slr->street->name);
1080 //dbg(0,"b2:%s\n",buffer2);
1038 1081
1082
1083 save_item=sl->item;
1084 save_level=sl->level;
1085 save_last_result_valid=sl->last_result_valid;
1086
1087
1088#if 1
1089 // put words back to start!!
1090 tmp=phrases;
1039 while (tmp) 1091 while (tmp)
1040 { 1092 {
1041 //dbg(0,"s0=%s\n",tmp->data); 1093 //dbg(0,"s0=%s\n",tmp->data);
1042 if (tmp != exclude1 && tmp != exclude2 && tmp != exclude3) 1094 if (tmp != exclude1 && tmp != exclude2 && tmp != exclude3)
1043 { 1095 {
1049 1101
1050 result_list=search_address_housenumber_real(result_list, sl, buffer2, phrases, exclude1, exclude2, exclude3, partial, jni); 1102 result_list=search_address_housenumber_real(result_list, sl, buffer2, phrases, exclude1, exclude2, exclude3, partial, jni);
1051 } 1103 }
1052 tmp=g_list_next(tmp); 1104 tmp=g_list_next(tmp);
1053 } 1105 }
1106#endif
1107
1108 // restore again
1109 sl->item=save_item;
1110 sl->level=save_level;
1111 sl->last_result_valid=save_last_result_valid;
1112
1054 } 1113 }
1055 1114
1056 if (buffer2) 1115 if (buffer2)
1057 { 1116 {
1058 g_free(buffer2); 1117 g_free(buffer2);
1076 GList *tmp=phrases; 1135 GList *tmp=phrases;
1077 int count=0; 1136 int count=0;
1078 struct coord_geo g; 1137 struct coord_geo g;
1079 struct coord c; 1138 struct coord c;
1080 struct attr attr; 1139 struct attr attr;
1140 struct attr attrx;
1141 // struct search_list *sl2=search_list_new(sl->ms);
1142 struct item *save_item;
1143 int save_level;
1144 int save_last_result_valid;
1145 // int first=1;
1081 1146
1082 while ((slr=search_list_get_result(sl))) 1147 while ((slr=search_list_get_result(sl)))
1083 { 1148 {
1084 char *buffer; 1149 char *buffer;
1150
1151 if (offline_search_break_searching==1)
1152 {
1153 break;
1154 }
1155
1085 // coords of result 1156 // coords of result
1086 c.x=slr->town->common.c->x; 1157 c.x=slr->town->common.c->x;
1087 c.y=slr->town->common.c->y; 1158 c.y=slr->town->common.c->y;
1088 transform_to_geo(slr->town->common.c->pro, &c, &g); 1159 transform_to_geo(slr->town->common.c->pro, &c, &g);
1089 1160
1095 else 1166 else
1096 { 1167 {
1097 buffer=g_strdup_printf("TWN:H%dL%d:%f:%f:%.101s,%.7s %.101s",slr->town->common.item.id_hi,slr->town->common.item.id_lo,g.lat,g.lng,slr->country->name,slr->town->common.postal,slr->town->common.town_name); 1168 buffer=g_strdup_printf("TWN:H%dL%d:%f:%f:%.101s,%.7s %.101s",slr->town->common.item.id_hi,slr->town->common.item.id_lo,g.lat,g.lng,slr->country->name,slr->town->common.postal,slr->town->common.town_name);
1098 } 1169 }
1099 1170
1100 //dbg(0,"res=%s\n",buffer); 1171 //dbg(0,"**res=%s\n",buffer);
1101 1172
1102 // deactivated now * result_list=g_list_prepend(result_list,g_strdup(buffer)); 1173 // deactivated now * result_list=g_list_prepend(result_list,g_strdup(buffer));
1103#ifdef HAVE_API_ANDROID 1174#ifdef HAVE_API_ANDROID
1104 // return results to android as they come in ... 1175 // return results to android as they come in ...
1105 android_return_search_result(jni,buffer); 1176 android_return_search_result(jni,buffer);
1106#endif 1177#endif
1107 1178
1108 count++; 1179 count++;
1180 if (buffer)
1109 g_free(buffer); 1181 g_free(buffer);
1182
1183
1184 save_item=sl->item;
1185 save_level=sl->level;
1186 save_last_result_valid=sl->last_result_valid;
1187
1188 // put words back to start!!
1189 tmp=phrases;
1110 1190
1111 while (tmp) 1191 while (tmp)
1112 { 1192 {
1113 if (tmp != exclude1 && tmp != exclude2) 1193 if (tmp != exclude1 && tmp != exclude2)
1114 { 1194 {
1119 result_list=search_address__street(result_list, sl, phrases, exclude1, exclude2, tmp, partial, jni); 1199 result_list=search_address__street(result_list, sl, phrases, exclude1, exclude2, tmp, partial, jni);
1120 } 1200 }
1121 tmp=g_list_next(tmp); 1201 tmp=g_list_next(tmp);
1122 } 1202 }
1123 1203
1204 // restore again
1205 sl->item=save_item;
1206 sl->level=save_level;
1207 sl->last_result_valid=save_last_result_valid;
1124 } 1208 }
1125
1126 /*
1127 if (!count)
1128 {
1129 dbg(0,"return 1\n");
1130 return result_list;
1131 }
1132 */
1133
1134 1209
1135 //dbg(0,"return 2\n"); 1210 //dbg(0,"return 2\n");
1136 return result_list; 1211 return result_list;
1137} 1212}
1138 1213
1161 1236
1162 while (tmp) 1237 while (tmp)
1163 { 1238 {
1164 if (tmp != exclude) 1239 if (tmp != exclude)
1165 { 1240 {
1166 //dbg(0,"s=%s\n",tmp->data); 1241 //dbg(0,"Is=%s\n",tmp->data);
1167 attr.type=attr_town_or_district_name; 1242 attr.type=attr_town_or_district_name;
1168 attr.u.str=tmp->data; 1243 attr.u.str=tmp->data;
1169 search_list_search(sl, &attr, partial); 1244 search_list_search(sl, &attr, partial);
1170 result_list=search_address__town(result_list, sl, phrases, exclude, tmp, partial, jni); 1245 result_list=search_address__town(result_list, sl, phrases, exclude, tmp, partial, jni);
1171 } 1246 }
1247 //else
1248 //{
1249 //dbg(0,"Xs=%s\n",tmp->data);
1250 //}
1172 tmp=g_list_next(tmp); 1251 tmp=g_list_next(tmp);
1173 } 1252 }
1174 //dbg(0,"return 2"); 1253 //dbg(0,"return 2");
1175 return result_list; 1254 return result_list;
1176} 1255}
1436 1515
1437 1516
1438static int 1517static int
1439ascii_cmp_local(char *name, char *match, int partial) 1518ascii_cmp_local(char *name, char *match, int partial)
1440{ 1519{
1441 char *s=linguistics_casefold(name); 1520 char *s1=linguistics_casefold(name);
1521 char *s2=linguistics_casefold(match);
1442 int ret=linguistics_compare(s,match,partial); 1522 int ret=linguistics_compare(s1,s2,partial);
1443 g_free(s); 1523 g_free(s1);
1524 g_free(s2);
1444 return ret; 1525 return ret;
1445} 1526}
1446 1527
1447struct navit *global_navit; 1528struct navit *global_navit;
1448 1529
1693 attr.type=attr_country_all; 1774 attr.type=attr_country_all;
1694 tmp=phrases; 1775 tmp=phrases;
1695 phrases_first=phrases; 1776 phrases_first=phrases;
1696 sl=search_list_new(ms); 1777 sl=search_list_new(ms);
1697 1778
1698
1699// search_full_world(addr,partial,jni,search_country_flags,search_country_string);
1700
1701 dbg(0,"-- START --\n"); 1779 dbg(0,"-- START --\n");
1702
1703 // search in "attr_country_all" -> seems to be when item is in no country?? or not
1704 /*
1705 dbg(0,"-- country all start --\n");
1706 while (tmp)
1707 {
1708 dbg(0,"s=%s\n",tmp->data);
1709 attr.u.str=tmp->data;
1710 search_list_search(sl, &attr, partial);
1711 result_list=search_address__country(result_list, sl, phrases, tmp, partial, jni);
1712 tmp=g_list_next(tmp);
1713 }
1714 dbg(0,"-- country all end --\n");
1715 */
1716 1780
1717 // normal search stuff -------- START ---------- 1781 // normal search stuff -------- START ----------
1718 if (search_country_flags == 1) 1782 if (search_country_flags == 1)
1719 { 1783 {
1720 dbg(0,"-- country default start --\n"); 1784 dbg(0,"-- country default start --\n");
1721 while (phrases) 1785 //while (phrases)
1722 { 1786 //{
1723 // dbg(0,"s=%s\n",phrases->data); 1787 // dbg(0,"s=%s\n",phrases->data);
1724 // set default country 1788 // set default country
1725 search_list_search(sl, country_default(), 0); 1789 search_list_search(sl, country_default(), 0);
1726 ret=search_address__country(ret, sl, phrases, NULL, partial, jni); 1790 ret=search_address__country(ret, sl, phrases, NULL, partial, jni);
1727 phrases=g_list_next(phrases); 1791 // phrases=g_list_next(phrases);
1728 } 1792 //}
1729 dbg(0,"-- country default end --\n"); 1793 dbg(0,"-- country default end --\n");
1730 } 1794 }
1731 else if (search_country_flags == 2) 1795 else if (search_country_flags == 2)
1732 { 1796 {
1733 dbg(0,"-- country sel:%s start --\n",search_country_string); 1797 dbg(0,"-- country sel:%s start --\n",search_country_string);
1734 // set a country 1798 // set a country
1735 struct attr country; 1799 struct attr country;
1736 country.type=attr_country_iso2; 1800 country.type=attr_country_iso2;
1737 country.u.str=search_country_string; 1801 country.u.str=search_country_string;
1738 while (phrases) 1802 //while (phrases)
1739 { 1803 //{
1740 // dbg(0,"s=%s\n",phrases->data); 1804 // dbg(0,"s=%s\n",phrases->data);
1741 search_list_search(sl, &country, 0); 1805 search_list_search(sl, &country, 0);
1742 // set a country 1806 // set a country
1743 ret=search_address__country(ret, sl, phrases, NULL, partial, jni); 1807 ret=search_address__country(ret, sl, phrases, NULL, partial, jni);
1744 phrases=g_list_next(phrases); 1808 //phrases=g_list_next(phrases);
1745 } 1809 //}
1746 dbg(0,"-- country sel:%s end --\n",search_country_string); 1810 dbg(0,"-- country sel:%s end --\n",search_country_string);
1747 } 1811 }
1748 else // flags==3 1812 else // flags==3
1749 { 1813 {
1750 dbg(0,"-- country all start --\n"); 1814 dbg(0,"-- country all start --\n");
1755 for(j1=0;j1 < j2;j1++) 1819 for(j1=0;j1 < j2;j1++)
1756 { 1820 {
1757 if (all_country_list[j1].iso2 != NULL) 1821 if (all_country_list[j1].iso2 != NULL)
1758 { 1822 {
1759 phrases=phrases_first; 1823 phrases=phrases_first;
1760 while (phrases) 1824 //while (phrases)
1761 { 1825 //{
1762 // dbg(0,"s country=%s\n",all_country_list[j1].iso2); 1826 // dbg(0,"s country=%s\n",all_country_list[j1].iso2);
1763 // dbg(0,"s=%s\n",phrases->data); 1827 // dbg(0,"s=%s\n",phrases->data);
1764 country.type=attr_country_iso2; 1828 country.type=attr_country_iso2;
1765 country.u.str=all_country_list[j1].iso2; 1829 country.u.str=all_country_list[j1].iso2;
1766 search_list_search(sl, &country, 0); 1830 search_list_search(sl, &country, 0);
1767 ret=search_address__country(ret, sl, phrases, NULL, partial, jni); 1831 ret=search_address__country(ret, sl, phrases, NULL, partial, jni);
1768 phrases=g_list_next(phrases); 1832 //phrases=g_list_next(phrases);
1833 //}
1834
1835 if (offline_search_break_searching==1)
1836 {
1837 break;
1769 } 1838 }
1770 } 1839 }
1771 } 1840 }
1772 dbg(0,"-- country all end --\n"); 1841 dbg(0,"-- country all end --\n");
1773 } 1842 }

Legend:
Removed from v.14  
changed lines
  Added in v.15

   
Visit the ZANavi Wiki