SearchView { static StringBuilder buildQuery(StringBuilder builder, String field, String value) { if (value == null || value.isEmpty()) { return builder; } value = value.replaceAll("^[\\s\\*]+|[\\s\\*]+$", ""); value = value.replaceAll("['*]", "?"); if (!value.isEmpty() && !"*".equals(value)) { value = "'*" + value + "*'"; if (builder.length() > 0) { builder.append(' '); } builder.append(field).append('~').append(value); } return builder; } SearchView(RemoteStorage storage);   SearchView(RemoteStorage storage, int maxLimit); void setLocale(Locale locale); List<Item> findQuery(String title, String label, String identifier, String owner, String model, Collection<String> hasOwners); List<Item> findQuery(Query q, String status); List<Item> findPhrase(String phrase); List<Item> find(String... pids); List<Item> find(boolean onlyActive, String... pids); List<Item> findDeleted(String... pids); List<Item> find(List<String> pids); List<Item> find(List<String> pids, boolean onlyActive); List<Item> findSortedChildren(String parentPid); List<Item> findChildren(String pid); List<Item> findChildrenHierarchy(String pid); List<Item> findLastCreated(int offset, String model, String user, String sort); List<Item> findLastCreated(int offset, String model, String user, String organization, String username, int limit, String sort); List<Item> findAlphabetical(int offset, String model, String user, String organization, String userName, int limit, String sort); List<Item> findLastModified(int offset, String model, String user, String organization, String username, int limit, String sort); List<Item> countModels(String model, String user, String organization, String username); List<Item> findAllObjects(); List<Item> findReferrers(String pid); List<Item> findByModel(String modelId); List<Item> findByModel(int offset, String modelId); List<Item> findByModel(int offset, String modelId, String orderBy); List<Item> findByModels(String modelId1, String modelId2); List<Item> findByModels(int offset, String modelId1, String modelId2); List<Item> findByModels(int offset, String modelId1, String modelId2, String orderBy); boolean isDeviceInUse(String deviceId);  }
@Test public void testBuildQuery() { assertEquals("title~'*test*'", SearchView.buildQuery(new StringBuilder(), "title", "test").toString()); assertEquals("title~'*test*'", SearchView.buildQuery(new StringBuilder(), "title", " test ").toString()); assertEquals("title~'*test test*'", SearchView.buildQuery(new StringBuilder(), "title", " test test ").toString()); assertEquals("title~'*test?s test???*'", SearchView.buildQuery(new StringBuilder(), "title", "test's test???").toString()); assertEquals("", SearchView.buildQuery(new StringBuilder(), "title", "").toString()); assertEquals("", SearchView.buildQuery(new StringBuilder(), "title", "***").toString()); assertEquals("label~'*test1*' title~'*test2*'", SearchView.buildQuery( SearchView.buildQuery(new StringBuilder(), "label", "test1"), "title", "test2").toString()); }