static SuggestedItem findClosestSuggestedItem(List<SuggestedItem> r, String query) {
        for (SuggestedItem curItem : r) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine(String.format("item's searchUrl:%s;query=%s", curItem.item.getSearchUrl(), query));
            }
            if (curItem.item.getSearchUrl().contains(Util.rawEncode(query))) {
                return curItem;
            }
        }

        // couldn't find an item with the query in the url so just
        // return the first one
        return r.get(0);
    }
@Test
    public void findClosestSuggestedItem() {
        final String query = "foobar 123";
        final String searchName = "sameDisplayName";

        SearchItem searchItemHit = new SearchItem() {
            @Override
            public SearchIndex getSearchIndex() {
                    return null;
            }

            @Override
            public String getSearchName() {
                return searchName;
            }

            @Override
            public String getSearchUrl() {
                return "/job/" + Util.rawEncode(query) + "/";
            }
        };

        SearchItem searchItemNoHit = new SearchItem() {
            @Override
            public SearchIndex getSearchIndex() {
                    return null;
            }

            @Override
            public String getSearchName() {
                return searchName;
            }

            @Override
            public String getSearchUrl() {
                return "/job/someotherJob/";
            }
        };

        SuggestedItem suggestedHit = new SuggestedItem(searchItemHit);
        SuggestedItem suggestedNoHit = new SuggestedItem(searchItemNoHit);
        ArrayList<SuggestedItem> list = new ArrayList<>();
        list.add(suggestedNoHit);
        list.add(suggestedHit); // make sure the hit is the second item

        SuggestedItem found = Search.findClosestSuggestedItem(list, query);
        assertEquals(searchItemHit, found.item);

        SuggestedItem found2 = Search.findClosestSuggestedItem(list, "abcd");
        assertEquals(searchItemNoHit, found2.item);
    }