diff --git a/spi.quicksearch/apichanges.xml b/spi.quicksearch/apichanges.xml new file mode 100644 --- /dev/null +++ b/spi.quicksearch/apichanges.xml @@ -0,0 +1,165 @@ + + + + + + + + + + + + + Quick Search API + + + + + + + + + Add methods for working with results limit + + + + + +

+ Some search providers can perform some optimizations if + they know what is the limit on number of search results + in advance. So there is new method + SearchRequest.getMaxResults to retrieve the current limit, + and method SearchResponse.setMoreResults to explicitly + inform that there are more results not added to the + SearchResponse. +

+
+ + + +
+
+ + + + + Change History for the Quick Search API + + + + + + +

Introduction

+ +

This document lists changes made to the Quick Search API.

+ + +
+ + +
+

@FOOTER@

+ +
+ +
diff --git a/spi.quicksearch/manifest.mf b/spi.quicksearch/manifest.mf --- a/spi.quicksearch/manifest.mf +++ b/spi.quicksearch/manifest.mf @@ -2,5 +2,5 @@ OpenIDE-Module: org.netbeans.spi.quicksearch OpenIDE-Module-Layer: org/netbeans/modules/quicksearch/resources/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/spi/quicksearch/Bundle.properties -OpenIDE-Module-Specification-Version: 1.23 +OpenIDE-Module-Specification-Version: 1.24 diff --git a/spi.quicksearch/nbproject/project.properties b/spi.quicksearch/nbproject/project.properties --- a/spi.quicksearch/nbproject/project.properties +++ b/spi.quicksearch/nbproject/project.properties @@ -2,5 +2,6 @@ javac.source=1.6 javac.compilerargs=-Xlint -Xlint:-serial javadoc.arch=${basedir}/arch.xml +javadoc.apichanges=${basedir}/apichanges.xml test.config.stableBTD.includes=**/*Test.class diff --git a/spi.quicksearch/src/org/netbeans/modules/quicksearch/Accessor.java b/spi.quicksearch/src/org/netbeans/modules/quicksearch/Accessor.java --- a/spi.quicksearch/src/org/netbeans/modules/quicksearch/Accessor.java +++ b/spi.quicksearch/src/org/netbeans/modules/quicksearch/Accessor.java @@ -71,7 +71,7 @@ // assert DEFAULT != null : "The DEFAULT field must be initialized"; } - public abstract SearchRequest createRequest (String text, List stroke); + public abstract SearchRequest createRequest (String text, List stroke, int maxResults); public abstract SearchResponse createResponse (CategoryResult catResult, SearchRequest sRequest); diff --git a/spi.quicksearch/src/org/netbeans/modules/quicksearch/CategoryResult.java b/spi.quicksearch/src/org/netbeans/modules/quicksearch/CategoryResult.java --- a/spi.quicksearch/src/org/netbeans/modules/quicksearch/CategoryResult.java +++ b/spi.quicksearch/src/org/netbeans/modules/quicksearch/CategoryResult.java @@ -47,7 +47,9 @@ import java.util.List; import javax.swing.SwingUtilities; import org.netbeans.modules.quicksearch.ResultsModel.ItemResult; +import org.netbeans.spi.quicksearch.SearchRequest; import org.openide.util.NbBundle; +import sun.awt.FontConfiguration; /** * Thread safe model of provider results of asociated category. @@ -175,4 +177,15 @@ } + /** + * Inform that there are more results to add, but they won't be added + * because of exceeded limit on number of items. + * + * @see SearchRequest#getMaxResults(). + */ + public void setMoreResults() { + if (!allResults) { + moreResults = true; + } + } } diff --git a/spi.quicksearch/src/org/netbeans/modules/quicksearch/CommandEvaluator.java b/spi.quicksearch/src/org/netbeans/modules/quicksearch/CommandEvaluator.java --- a/spi.quicksearch/src/org/netbeans/modules/quicksearch/CommandEvaluator.java +++ b/spi.quicksearch/src/org/netbeans/modules/quicksearch/CommandEvaluator.java @@ -98,11 +98,12 @@ public static org.openide.util.Task evaluate (String command, ResultsModel model) { List l = new ArrayList(); String[] commands = parseCommand(command); - SearchRequest sRequest = Accessor.DEFAULT.createRequest(commands[1], null); List tasks = new ArrayList(); List provCats = new ArrayList(); boolean allResults = getProviderCategories(commands, provCats); + SearchRequest sRequest = Accessor.DEFAULT.createRequest(commands[1], null, + (allResults ? CategoryResult.ALL_MAX_RESULTS : CategoryResult.MAX_RESULTS)); for (ProviderModel.Category curCat : provCats) { CategoryResult catResult = new CategoryResult(curCat, allResults); diff --git a/spi.quicksearch/src/org/netbeans/spi/quicksearch/AccessorImpl.java b/spi.quicksearch/src/org/netbeans/spi/quicksearch/AccessorImpl.java --- a/spi.quicksearch/src/org/netbeans/spi/quicksearch/AccessorImpl.java +++ b/spi.quicksearch/src/org/netbeans/spi/quicksearch/AccessorImpl.java @@ -58,8 +58,8 @@ class AccessorImpl extends Accessor { @Override - public SearchRequest createRequest (String text, List stroke) { - return new SearchRequest(text, stroke); + public SearchRequest createRequest (String text, List stroke, int maxResults) { + return new SearchRequest(text, stroke, maxResults); } @Override diff --git a/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchRequest.java b/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchRequest.java --- a/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchRequest.java +++ b/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchRequest.java @@ -63,14 +63,16 @@ } /** Text to search for */ - private String text; + private final String text; + private final int maxResults; /** Shortcut to search for */ - private List stroke; + private final List stroke; - SearchRequest (String text, List stroke) { + SearchRequest (String text, List stroke, int maxResults) { this.text = text; this.stroke = stroke; + this.maxResults = maxResults; } /** @@ -93,4 +95,18 @@ return stroke; } + /** + * Get maximal number of results that can be displayed under current + * circumstances. You can use this information to optimize you search. But + * remember that it is sometimes important to know whether there are more + * results than the current limit L. So either add L+1 results, or call + * method {@link SearchResponse#setMoreResults()}. + * + * @return The current limit on number of displayable results. + * @see SearchResponse#setMoreResults() + * @since spi.quicksearch/1.24 + */ + public int getMaxResults() { + return maxResults; + } } diff --git a/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchResponse.java b/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchResponse.java --- a/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchResponse.java +++ b/spi.quicksearch/src/org/netbeans/spi/quicksearch/SearchResponse.java @@ -57,8 +57,8 @@ */ public final class SearchResponse { - private CategoryResult catResult; - private SearchRequest sRequest; + private final CategoryResult catResult; + private final SearchRequest sRequest; /** Package private creation, made available to other packages via * Accessor pattern. @@ -123,4 +123,14 @@ htmlDisplayName, shortcut, displayHint)); } + /** + * Inform that there are more results to add, but they won't be added + * because of exceeded limit on number of items. + * + * @see SearchRequest#getMaxResults(). + * @since spi.quicksearch/1.24 + */ + public void setMoreResults() { + catResult.setMoreResults(); + } } diff --git a/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ResultsModelTest.java b/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ResultsModelTest.java --- a/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ResultsModelTest.java +++ b/spi.quicksearch/test/unit/src/org/netbeans/modules/quicksearch/ResultsModelTest.java @@ -131,7 +131,7 @@ assertHTML("leave my keys alone!", "leave my keys alone!", "key"); } private void assertHTML(String displayed, String provided, String searched) { - assertEquals(displayed, new ResultsModel.ItemResult(null, Accessor.DEFAULT.createRequest(searched, null), null, provided).getDisplayName()); + assertEquals(displayed, new ResultsModel.ItemResult(null, Accessor.DEFAULT.createRequest(searched, null, 7), null, provided).getDisplayName()); } }