Search in sources :

Example 11 with SearchPhrase

use of net.osmand.search.core.SearchPhrase in project Osmand by osmandapp.

the class QuickSearchListAdapter method updateDistanceDirection.

private void updateDistanceDirection(View view, QuickSearchListItem listItem) {
    TextView distanceText = (TextView) view.findViewById(R.id.distance);
    ImageView direction = (ImageView) view.findViewById(R.id.direction);
    SearchPhrase phrase = listItem.getSearchResult().requiredSearchPhrase;
    LatLon loc = location;
    if (phrase != null && useMapCenter) {
        LatLon ol = phrase.getSettings().getOriginalLocation();
        if (ol != null) {
            loc = ol;
        }
    }
    updateLocationView(useMapCenter, loc, heading, direction, distanceText, listItem.getSearchResult().location.getLatitude(), listItem.getSearchResult().location.getLongitude(), screenOrientation, app, activity);
}
Also used : LatLon(net.osmand.data.LatLon) TextView(android.widget.TextView) ImageView(android.widget.ImageView) SearchPhrase(net.osmand.search.core.SearchPhrase)

Example 12 with SearchPhrase

use of net.osmand.search.core.SearchPhrase in project Osmand by osmandapp.

the class SearchUICore method shallowSearch.

public <T extends SearchCoreAPI> SearchResultCollection shallowSearch(Class<T> cl, String text, final ResultMatcher<SearchResult> matcher) throws IOException {
    T api = getApiByClass(cl);
    if (api != null) {
        if (debugMode) {
            LOG.info("Start shallow search <" + phrase + "> API=<" + api + ">");
        }
        SearchPhrase sphrase = this.phrase.generateNewPhrase(text, searchSettings);
        preparePhrase(sphrase);
        AtomicInteger ai = new AtomicInteger();
        SearchResultMatcher rm = new SearchResultMatcher(matcher, sphrase, ai.get(), ai, totalLimit);
        api.search(sphrase, rm);
        SearchResultCollection collection = new SearchResultCollection(sphrase);
        collection.addSearchResults(rm.getRequestResults(), true, true);
        if (debugMode) {
            LOG.info("Finish shallow search <" + sphrase + "> Results=" + rm.getRequestResults().size());
        }
        return collection;
    }
    return null;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SearchPhrase(net.osmand.search.core.SearchPhrase)

Example 13 with SearchPhrase

use of net.osmand.search.core.SearchPhrase in project Osmand by osmandapp.

the class LocationSearchTest method search.

private void search(String string, LatLon latLon) throws IOException {
    SearchResultMatcher srm = new SearchUICore.SearchResultMatcher(null, null, 0, null, 100);
    new SearchCoreFactory.SearchLocationAndUrlAPI().search(new SearchPhrase(null, OsmAndCollator.primaryCollator()).generateNewPhrase(string, null), srm);
    Assert.assertEquals(1, srm.getRequestResults().size());
    Assert.assertEquals(latLon, srm.getRequestResults().get(0).location);
}
Also used : SearchResultMatcher(net.osmand.search.SearchUICore.SearchResultMatcher) SearchCoreFactory(net.osmand.search.core.SearchCoreFactory) SearchPhrase(net.osmand.search.core.SearchPhrase)

Example 14 with SearchPhrase

use of net.osmand.search.core.SearchPhrase in project Osmand by osmandapp.

the class SearchCoreUITest method testDuplicates.

@Test
public void testDuplicates() throws IOException {
    SearchSettings ss = new SearchSettings((SearchSettings) null);
    ss = ss.setOriginalLocation(new LatLon(0, 0));
    SearchPhrase phrase = new SearchPhrase(ss, OsmAndCollator.primaryCollator());
    SearchResultCollection cll = new SearchUICore.SearchResultCollection(phrase);
    List<SearchResult> rs = new ArrayList<>();
    SearchResult a1 = searchResult(rs, phrase, "a", 100);
    SearchResult b2 = searchResult(rs, phrase, "b", 200);
    SearchResult b1 = searchResult(rs, phrase, "b", 100);
    /*SearchResult a3 = */
    searchResult(rs, phrase, "a", 100);
    cll.addSearchResults(rs, true, true);
    Assert.assertEquals(3, cll.getCurrentSearchResults().size());
    Assert.assertSame(a1, cll.getCurrentSearchResults().get(0));
    Assert.assertSame(b1, cll.getCurrentSearchResults().get(1));
    Assert.assertSame(b2, cll.getCurrentSearchResults().get(2));
}
Also used : LatLon(net.osmand.data.LatLon) ArrayList(java.util.ArrayList) SearchSettings(net.osmand.search.core.SearchSettings) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) SearchResult(net.osmand.search.core.SearchResult) SearchPhrase(net.osmand.search.core.SearchPhrase) Test(org.junit.Test)

Example 15 with SearchPhrase

use of net.osmand.search.core.SearchPhrase in project Osmand by osmandapp.

the class SearchCoreUITest method testNoResort.

@Test
public void testNoResort() throws IOException {
    SearchSettings ss = new SearchSettings((SearchSettings) null);
    ss = ss.setOriginalLocation(new LatLon(0, 0));
    SearchPhrase phrase = new SearchPhrase(ss, OsmAndCollator.primaryCollator());
    SearchResultCollection cll = new SearchUICore.SearchResultCollection(phrase);
    List<SearchResult> rs = new ArrayList<>();
    SearchResult a1 = searchResult(rs, phrase, "a", 100);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    SearchResult b2 = searchResult(rs, phrase, "b", 200);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    SearchResult b1 = searchResult(rs, phrase, "b", 100);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    /*SearchResult a3 = */
    searchResult(rs, phrase, "a", 100);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    Assert.assertEquals(3, cll.getCurrentSearchResults().size());
    Assert.assertSame(a1, cll.getCurrentSearchResults().get(0));
    Assert.assertSame(b2, cll.getCurrentSearchResults().get(1));
    Assert.assertSame(b1, cll.getCurrentSearchResults().get(2));
}
Also used : LatLon(net.osmand.data.LatLon) ArrayList(java.util.ArrayList) SearchSettings(net.osmand.search.core.SearchSettings) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) SearchResult(net.osmand.search.core.SearchResult) SearchPhrase(net.osmand.search.core.SearchPhrase) Test(org.junit.Test)

Aggregations

SearchPhrase (net.osmand.search.core.SearchPhrase)18 SearchResult (net.osmand.search.core.SearchResult)12 LatLon (net.osmand.data.LatLon)9 SpannableString (android.text.SpannableString)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 ArrayList (java.util.ArrayList)6 SearchResultCollection (net.osmand.search.SearchUICore.SearchResultCollection)6 SearchSettings (net.osmand.search.core.SearchSettings)6 Bundle (android.os.Bundle)4 View (android.view.View)4 OnClickListener (android.view.View.OnClickListener)3 List (java.util.List)3 AbstractPoiType (net.osmand.osm.AbstractPoiType)3 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)3 QuickSearchListItem (net.osmand.plus.search.listitems.QuickSearchListItem)3 SearchUICore (net.osmand.search.SearchUICore)3 SuppressLint (android.annotation.SuppressLint)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2