Update search api

This commit is contained in:
Victor Shcherb 2016-07-02 13:15:00 +02:00
parent 4845dd7fff
commit e2fecedffa
6 changed files with 112 additions and 47 deletions

1
OsmAnd-java/protobuf-src/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
protobuf

View file

@ -0,0 +1,3 @@
#!/bin/bash
# proto 2.4.1
protoc --java_out=OsmAnd-java/src --proto_path=$(pwd)/../resources/protos $(pwd)/../resources/protos/OBF.proto

View file

@ -1,5 +1,14 @@
package net.osmand.search.example.core;
public enum ObjectType {
CITY, VILLAGE, POSTCODE, STREET, HOUSE, POI_TYPE, POI, LOCATION, NAME_FILTER
CITY(true), VILLAGE(true), POSTCODE(true), STREET(true), HOUSE(true),
POI_TYPE(false), POI(true), LOCATION(true), FAVORITE(true),
RECENT_OBJ(true), WPT(true), NAME_FILTER(false);
private boolean hasLocation;
private ObjectType(boolean location) {
this.hasLocation = location;
}
public boolean hasLocation() {
return hasLocation;
}
}

View file

@ -10,53 +10,21 @@ import net.osmand.data.LatLon;
public class SearchPhrase {
public static class SearchWord {
public String word;
public ObjectType type;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((word == null) ? 0 : word.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SearchWord other = (SearchWord) obj;
if (type != other.type)
return false;
if (word == null) {
if (other.word != null)
return false;
} else if (!word.equals(other.word))
return false;
return true;
}
@Override
public String toString() {
return word;
}
private List<SearchWord> words = new ArrayList<>();
private LatLon originalPhraseLocation;
public SearchPhrase(LatLon location) {
this.originalPhraseLocation = location;
}
public List<SearchWord> words = new ArrayList<>();
public LatLon myLocationOrVisibleMap = new LatLon(0, 0);
public List<SearchWord> getWords() {
return words;
}
public List<SearchWord> excludefilterWords() {
List<SearchWord> w = new ArrayList<>();
for(SearchWord s : words) {
if(s.type != ObjectType.NAME_FILTER) {
if(s.getType() != ObjectType.NAME_FILTER) {
w.add(s);
}
}
@ -64,10 +32,19 @@ public class SearchPhrase {
}
public boolean isLastWord(ObjectType p) {
return true; // TODO
for(int i = words.size() - 1; i >= 0; i--) {
SearchWord sw = words.get(i);
if(sw.getType() == ObjectType.POI) {
return true;
} else if(sw.getType() != ObjectType.NAME_FILTER) {
return false;
}
}
return false;
}
public StringMatcher getNameStringMatcher() {
// TODO
return new CollatorStringMatcher("NameFitler", StringMatcherMode.CHECK_STARTS_FROM_SPACE);
}
@ -75,10 +52,17 @@ public class SearchPhrase {
return excludefilterWords().equals(p.excludefilterWords());
}
public String getStringRerpresentation() {
StringBuilder sb = new StringBuilder();
for(SearchWord s : words) {
sb.append(s).append(", ");
}
return sb.toString();
}
@Override
public String toString() {
String w = words.toString();
return w.substring(1, w.length() - 1);
return getStringRerpresentation();
}
public boolean isNoSelectedType() {
@ -86,12 +70,18 @@ public class SearchPhrase {
}
public boolean isEmpty() {
return false;
return words.isEmpty();
}
public LatLon getLastTokenLocation() {
for(int i = words.size() - 1; i >= 0; i--) {
SearchWord sw = words.get(i);
if(sw.getLocation() != null) {
return sw.getLocation();
}
}
// last token or myLocationOrVisibleMap if not selected
return myLocationOrVisibleMap;
return originalPhraseLocation;
}
}

View file

@ -0,0 +1,59 @@
package net.osmand.search.example.core;
import net.osmand.data.LatLon;
public class SearchWord {
private String word;
private ObjectType type;
private Object internalObject;
private LatLon location;
public ObjectType getType() {
return type;
}
public String getWord() {
return word;
}
public Object getInternalObject() {
return internalObject;
}
public LatLon getLocation() {
return location;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((word == null) ? 0 : word.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SearchWord other = (SearchWord) obj;
if (type != other.type)
return false;
if (word == null) {
if (other.word != null)
return false;
} else if (!word.equals(other.word))
return false;
return true;
}
@Override
public String toString() {
return word;
}
}

View file

@ -2,6 +2,9 @@
/.idea
*.iml
gradlew
gradle
gradlew.bat
# Gradle
.gradle
/local.properties