r58090 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58089‎ | r58090 | r58091 >
Date:16:51, 24 October 2009
Author:rainman
Status:deferred
Tags:
Comment:
Make maxoffset and maxlimit for queries configurable, instead of keeping them hardcoded
Modified paths:
  • /branches/lucene-search-2.1/src/org/wikimedia/lsearch/config/GlobalConfiguration.java (modified) (history)
  • /branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearchEngine.java (modified) (history)

Diff [purge]

Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/config/GlobalConfiguration.java
@@ -121,7 +121,9 @@
122122
123123 /** All the lang codes we encountered, used for "smart interwiki" */
124124 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;
126128
127129 /** Wether to report warnings and info */
128130 protected static boolean verbose = true;
@@ -431,6 +433,8 @@
432434 this.additionalRank = getArrayProperty("AdditionalRank.suffix");
433435 this.useSmartInterwiki = globalProperties.getProperty("Database.smartInterwiki","false").equalsIgnoreCase("true");
434436 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"));
435439 // try reading intialisesettings
436440 String initset = globalProperties.getProperty("WMF.InitialiseSettings");
437441 if(initset != null)
@@ -1564,6 +1568,16 @@
15651569 }
15661570 return hosts;
15671571 }
 1572+
 1573+ public int getMaxSearchLimit() {
 1574+ return maxSearchLimit;
 1575+ }
 1576+
 1577+
 1578+ public int getMaxSearchOffset() {
 1579+ return maxSearchOffset;
 1580+ }
 1581+
15681582
15691583
15701584 }
\ No newline at end of file
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/search/SearchEngine.java
@@ -69,9 +69,9 @@
7070 public class SearchEngine {
7171 static org.apache.log4j.Logger log = Logger.getLogger(SearchEngine.class);
7272
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;
7676 protected static GlobalConfiguration global = null;
7777 protected static Configuration config = null;
7878 protected static SearcherCache cache = null;
@@ -84,8 +84,11 @@
8585 public SearchEngine(){
8686 if(config == null)
8787 config = Configuration.open();
88 - if(global == null)
 88+ if(global == null){
8989 global = GlobalConfiguration.getInstance();
 90+ maxlimit = global.getMaxSearchLimit();
 91+ maxoffset = global.getMaxSearchOffset();
 92+ }
9093 if(cache == null)
9194 cache = SearcherCache.getInstance();
9295 if(udpLogger == null)
@@ -104,11 +107,11 @@
105108 if (query.containsKey("offset"))
106109 offset = Math.max(Integer.parseInt((String)query.get("offset")), 0);
107110 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);
109112 if (query.containsKey("iwoffset"))
110113 iwoffset = Math.max(Integer.parseInt((String)query.get("iwoffset")), 0);
111114 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);
113116 if (query.containsKey("case") && global.exactCaseIndex(iid.getDBname()) && ((String)query.get("case")).equalsIgnoreCase("exact"))
114117 exactCase = true;
115118 if(query.containsKey("searchonly"))
@@ -147,11 +150,11 @@
148151 if (query.containsKey("offset"))
149152 offset = Math.max(Integer.parseInt((String)query.get("offset")), 0);
150153 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);
152155 if (query.containsKey("iwoffset"))
153156 iwoffset = Math.max(Integer.parseInt((String)query.get("iwoffset")), 0);
154157 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);
156159 if (query.containsKey("case") && global.exactCaseIndex(iid.getDBname()) && ((String)query.get("case")).equalsIgnoreCase("exact"))
157160 exactCase = true;
158161 if(query.containsKey("searchall"))
@@ -181,7 +184,7 @@
182185 if (query.containsKey("offset"))
183186 offset = Math.max(Integer.parseInt((String)query.get("offset")), 0);
184187 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);
186189 return searchRelated(iid, searchterm, offset, limit);
187190 } else if(what.equals("similar")){
188191 NamespaceFilter nsf = null;
@@ -194,7 +197,7 @@
195198 else
196199 nsf = iid.getDefaultNamespace();
197200 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);
199202 return searchSimilar(iid,searchterm,nsf,dist,limit);
200203 } else if(what.equals("suggest")){
201204 NamespaceFilter nsf = null;
@@ -920,13 +923,13 @@
921924 res.setNumHits(numhits);
922925 logRequest(iid,"search",searchterm, q, numhits, searchStart, s);
923926
924 - int size = min(limit+offset,MAXOFFSET,numhits) - offset;
 927+ int size = min(limit+offset,maxoffset,numhits) - offset;
925928 if( size < 0 )
926929 size = 0;
927930 int[] docids = new int[size];
928931 float[] scores = new float[size];
929932 // 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++){
931934 docids[j] = hits.scoreDocs[i].doc;
932935 scores[j] = hits.scoreDocs[i].score;
933936 }
@@ -956,11 +959,11 @@
957960 res.setNumHits(numhits);
958961 logRequest(iid,"search",searchterm, q, numhits, searchStart, s);
959962
960 - int size = min(limit+offset,MAXOFFSET,numhits) - offset;
 963+ int size = min(limit+offset,maxoffset,numhits) - offset;
961964 int[] docids = new int[size];
962965 float[] scores = new float[size];
963966 // 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++){
965968 docids[j] = hits.scoreDocs[i].doc;
966969 scores[j] = hits.scoreDocs[i].score;
967970 }

Status & tagging log