Interface Search
- All Superinterfaces:
Folder
,HierarchyItem
Implement this interface on folders that support search. When search request is
received the Engine
calls search(String, SearchOptions, List, Long, Long)
method.
If this interface is found on folder items, your server will include DASL: <DAV:basicsearch> header and SEARCH token in Allow header in response to OPTIONS requests. The WebDAV clients that support DASL search, including IT Hit Ajax File Browser, may rely on this header and token to display search user interface.
-
Method Summary
Methods inherited from interface com.ithit.webdav.server.Folder
createFile, createFolder, getChildren
Methods inherited from interface com.ithit.webdav.server.HierarchyItem
copyTo, delete, getCreated, getModified, getName, getPath, getProperties, getPropertyNames, moveTo, updateProperties
-
Method Details
-
search
PageResults search(String searchString, SearchOptions options, List<Property> propNames, Long offset, Long nResults) Returns a list of items that correspond to search request.This method is called by the
Engine
when client application is sending search request. In your implementation you must return the list of items that correspond to the requested search phrase and search options.The search phrase may contain wildcards:
- To indicate one or more characters the '%' is passed in search string.
- To indicate exactly one character the '_' is passed in search string.
- To include '%', '_' and '\' characters in the search string they are escaped with '\' character.
Note that IT Hit Ajax File Browser is using '*' and '?' as wildcard characters. In case there chars are included in search phrase they are replaced with '%' and '_'.
- Parameters:
searchString
- A search phrase.options
- Search parameters.propNames
- List of properties to retrieve with the children. They will be queried by the engine later.offset
- The number of items to skip before returning the remaining items.nResults
- The number of items to return.- Returns:
- Instance of
PageResults
class that contains items on a requested page and total number of items in search results.
The code below is part of Collection Synchronization sample provided with the SDK.@Override public PageResults search(String searchString, SearchOptions options, List<Property> propNames, Long offset, Long nResults) { List<HierarchyItem> results = new LinkedList<>(); SearchFacade.Searcher searcher = getEngine().getSearchFacade().getSearcher(); if (searcher == null) { return new PageResults(results, (long) 0); } boolean snippet = propNames.stream().anyMatch(x -> SNIPPET.equalsIgnoreCase(x.getName())); Map<String, String> searchResult; try { String decodedPath = decode(getPath()); searchResult = searcher.search(searchString, options, decodedPath, snippet); for (Map.Entry<String, String> entry : searchResult.entrySet()) { try { HierarchyItem item = getEngine().getHierarchyItem(entry.getKey()); if (item != null) { if (snippet && item instanceof FileImpl) { ((FileImpl) item).setSnippet(entry.getValue()); } results.add(item); } } catch (Exception ex) { getEngine().getLogger().logError("Error during search.", ex); } } } catch (ServerException e) { getEngine().getLogger().logError("Error during search.", e); } return new PageResults((offset != null && nResults != null) ? results.stream().skip(offset).limit(nResults).collect(Collectors.toList()) : results, (long) results.size()); }
-