public interface Search extends Folder
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.
Modifier and Type | Method and Description |
---|---|
PageResults |
search(String searchString,
SearchOptions options,
List<Property> propNames,
Long offset,
Long nResults)
Returns a list of items that correspond to search request.
|
createFile, createFolder, getChildren
copyTo, delete, getCreated, getModified, getName, getPath, getProperties, getPropertyNames, moveTo, updateProperties
PageResults search(String searchString, SearchOptions options, List<Property> propNames, Long offset, Long nResults)
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:
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 '_'.
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.PageResults
class that contains items on a requested page and total number of items in search results.
@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()); }
Copyright © ITHit. All Rights Reserved.