Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/config/GlobalConfiguration.java |
— | — | @@ -121,7 +121,9 @@ |
122 | 122 | |
123 | 123 | /** All the lang codes we encountered, used for "smart interwiki" */ |
124 | 124 | protected HashSet<String> smartInterwikiCodes = new HashSet<String>(); |
125 | | - protected boolean useSmartInterwiki = false; |
| 125 | + protected boolean useSmartInterwiki = false; |
| 126 | + protected int maxSearchLimit; |
| 127 | + protected int maxSearchOffset; |
126 | 128 | |
127 | 129 | /** Wether to report warnings and info */ |
128 | 130 | protected static boolean verbose = true; |
— | — | @@ -431,6 +433,8 @@ |
432 | 434 | this.additionalRank = getArrayProperty("AdditionalRank.suffix"); |
433 | 435 | this.useSmartInterwiki = globalProperties.getProperty("Database.smartInterwiki","false").equalsIgnoreCase("true"); |
434 | 436 | this.commonsWiki = globalProperties.getProperty("Commons.wiki"); |
| 437 | + this.maxSearchOffset = Integer.parseInt(globalProperties.getProperty("Search.maxoffset", "100000")); |
| 438 | + this.maxSearchLimit = Integer.parseInt(globalProperties.getProperty("Search.maxlimit", "1000")); |
435 | 439 | // try reading intialisesettings |
436 | 440 | String initset = globalProperties.getProperty("WMF.InitialiseSettings"); |
437 | 441 | if(initset != null) |
— | — | @@ -1564,6 +1568,16 @@ |
1565 | 1569 | } |
1566 | 1570 | return hosts; |
1567 | 1571 | } |
| 1572 | + |
| 1573 | + public int getMaxSearchLimit() { |
| 1574 | + return maxSearchLimit; |
| 1575 | + } |
| 1576 | + |
| 1577 | + |
| 1578 | + public int getMaxSearchOffset() { |
| 1579 | + return maxSearchOffset; |
| 1580 | + } |
| 1581 | + |
1568 | 1582 | |
1569 | 1583 | |
1570 | 1584 | } |
\ No newline at end of file |
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearchEngine.java |
— | — | @@ -69,9 +69,9 @@ |
70 | 70 | public class SearchEngine { |
71 | 71 | static org.apache.log4j.Logger log = Logger.getLogger(SearchEngine.class); |
72 | 72 | |
73 | | - protected final int MAXLINES = 1000; |
74 | | - protected final int MAXPREFIX = 50; |
75 | | - protected final int MAXOFFSET = 100000; |
| 73 | + protected static int maxlimit = 1000; |
| 74 | + protected static int maxoffset = 100000; |
| 75 | + protected final int MAXPREFIX = 50; |
76 | 76 | protected static GlobalConfiguration global = null; |
77 | 77 | protected static Configuration config = null; |
78 | 78 | protected static SearcherCache cache = null; |
— | — | @@ -84,8 +84,11 @@ |
85 | 85 | public SearchEngine(){ |
86 | 86 | if(config == null) |
87 | 87 | config = Configuration.open(); |
88 | | - if(global == null) |
| 88 | + if(global == null){ |
89 | 89 | global = GlobalConfiguration.getInstance(); |
| 90 | + maxlimit = global.getMaxSearchLimit(); |
| 91 | + maxoffset = global.getMaxSearchOffset(); |
| 92 | + } |
90 | 93 | if(cache == null) |
91 | 94 | cache = SearcherCache.getInstance(); |
92 | 95 | if(udpLogger == null) |
— | — | @@ -104,11 +107,11 @@ |
105 | 108 | if (query.containsKey("offset")) |
106 | 109 | offset = Math.max(Integer.parseInt((String)query.get("offset")), 0); |
107 | 110 | if (query.containsKey("limit")) |
108 | | - limit = Math.min(Integer.parseInt((String)query.get("limit")), MAXLINES); |
| 111 | + limit = Math.min(Integer.parseInt((String)query.get("limit")), maxlimit); |
109 | 112 | if (query.containsKey("iwoffset")) |
110 | 113 | iwoffset = Math.max(Integer.parseInt((String)query.get("iwoffset")), 0); |
111 | 114 | if (query.containsKey("iwlimit")) |
112 | | - iwlimit = Math.min(Integer.parseInt((String)query.get("iwlimit")), MAXLINES); |
| 115 | + iwlimit = Math.min(Integer.parseInt((String)query.get("iwlimit")), maxlimit); |
113 | 116 | if (query.containsKey("case") && global.exactCaseIndex(iid.getDBname()) && ((String)query.get("case")).equalsIgnoreCase("exact")) |
114 | 117 | exactCase = true; |
115 | 118 | if(query.containsKey("searchonly")) |
— | — | @@ -147,11 +150,11 @@ |
148 | 151 | if (query.containsKey("offset")) |
149 | 152 | offset = Math.max(Integer.parseInt((String)query.get("offset")), 0); |
150 | 153 | if (query.containsKey("limit")) |
151 | | - limit = Math.min(Integer.parseInt((String)query.get("limit")), MAXLINES); |
| 154 | + limit = Math.min(Integer.parseInt((String)query.get("limit")), maxlimit); |
152 | 155 | if (query.containsKey("iwoffset")) |
153 | 156 | iwoffset = Math.max(Integer.parseInt((String)query.get("iwoffset")), 0); |
154 | 157 | if (query.containsKey("iwlimit")) |
155 | | - iwlimit = Math.min(Integer.parseInt((String)query.get("iwlimit")), MAXLINES); |
| 158 | + iwlimit = Math.min(Integer.parseInt((String)query.get("iwlimit")), maxlimit); |
156 | 159 | if (query.containsKey("case") && global.exactCaseIndex(iid.getDBname()) && ((String)query.get("case")).equalsIgnoreCase("exact")) |
157 | 160 | exactCase = true; |
158 | 161 | if(query.containsKey("searchall")) |
— | — | @@ -181,7 +184,7 @@ |
182 | 185 | if (query.containsKey("offset")) |
183 | 186 | offset = Math.max(Integer.parseInt((String)query.get("offset")), 0); |
184 | 187 | if (query.containsKey("limit")) |
185 | | - limit = Math.min(Integer.parseInt((String)query.get("limit")), MAXLINES); |
| 188 | + limit = Math.min(Integer.parseInt((String)query.get("limit")), maxlimit); |
186 | 189 | return searchRelated(iid, searchterm, offset, limit); |
187 | 190 | } else if(what.equals("similar")){ |
188 | 191 | NamespaceFilter nsf = null; |
— | — | @@ -194,7 +197,7 @@ |
195 | 198 | else |
196 | 199 | nsf = iid.getDefaultNamespace(); |
197 | 200 | if (query.containsKey("limit")) |
198 | | - limit = Math.min(Integer.parseInt((String)query.get("limit")), MAXLINES); |
| 201 | + limit = Math.min(Integer.parseInt((String)query.get("limit")), maxlimit); |
199 | 202 | return searchSimilar(iid,searchterm,nsf,dist,limit); |
200 | 203 | } else if(what.equals("suggest")){ |
201 | 204 | NamespaceFilter nsf = null; |
— | — | @@ -920,13 +923,13 @@ |
921 | 924 | res.setNumHits(numhits); |
922 | 925 | logRequest(iid,"search",searchterm, q, numhits, searchStart, s); |
923 | 926 | |
924 | | - int size = min(limit+offset,MAXOFFSET,numhits) - offset; |
| 927 | + int size = min(limit+offset,maxoffset,numhits) - offset; |
925 | 928 | if( size < 0 ) |
926 | 929 | size = 0; |
927 | 930 | int[] docids = new int[size]; |
928 | 931 | float[] scores = new float[size]; |
929 | 932 | // fetch documents |
930 | | - for(int i=offset, j=0 ; i<limit+offset && i<MAXOFFSET && i<numhits; i++, j++){ |
| 933 | + for(int i=offset, j=0 ; i<limit+offset && i<maxoffset && i<numhits; i++, j++){ |
931 | 934 | docids[j] = hits.scoreDocs[i].doc; |
932 | 935 | scores[j] = hits.scoreDocs[i].score; |
933 | 936 | } |
— | — | @@ -956,11 +959,11 @@ |
957 | 960 | res.setNumHits(numhits); |
958 | 961 | logRequest(iid,"search",searchterm, q, numhits, searchStart, s); |
959 | 962 | |
960 | | - int size = min(limit+offset,MAXOFFSET,numhits) - offset; |
| 963 | + int size = min(limit+offset,maxoffset,numhits) - offset; |
961 | 964 | int[] docids = new int[size]; |
962 | 965 | float[] scores = new float[size]; |
963 | 966 | // fetch documents |
964 | | - for(int i=offset, j=0 ; i<limit+offset && i<MAXOFFSET && i<numhits; i++, j++){ |
| 967 | + for(int i=offset, j=0 ; i<limit+offset && i<maxoffset && i<numhits; i++, j++){ |
965 | 968 | docids[j] = hits.scoreDocs[i].doc; |
966 | 969 | scores[j] = hits.scoreDocs[i].score; |
967 | 970 | } |