comparison src/global/Site.java @ 53:56accc959f8c

remove SORT_BY_VALUE
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Jul 2021 20:19:14 -0600
parents abe0694e9849
children
comparison
equal deleted inserted replaced
52:7df8ec497281 53:56accc959f8c
59 public static final String TWEAKS_FLD = "tweaks"; 59 public static final String TWEAKS_FLD = "tweaks";
60 public static final String HAS_TWEAKS_FLD = "has_tweaks"; 60 public static final String HAS_TWEAKS_FLD = "has_tweaks";
61 public static final String FILE_COUNT_FLD = "file_count"; 61 public static final String FILE_COUNT_FLD = "file_count";
62 public static final String FILE_NODE_RATIO_FLD = "file_node_ratio"; 62 public static final String FILE_NODE_RATIO_FLD = "file_node_ratio";
63 public static final String MONTHLY_VIEWS_FLD = "monthly_views"; 63 public static final String MONTHLY_VIEWS_FLD = "monthly_views";
64 public static final String VALUE_FLD = "value";
65 64
66 public static final Sort SORT_BY_ACTIVITY = new Sort(new SortField(ACTIVITY_FLD, SortField.INT, true)); 65 public static final Sort SORT_BY_ACTIVITY = new Sort(new SortField(ACTIVITY_FLD, SortField.INT, true));
67 public static final Sort SORT_BY_FILE_NODE_RATIO = new Sort(new SortField(FILE_NODE_RATIO_FLD, SortField.INT, true)); 66 public static final Sort SORT_BY_FILE_NODE_RATIO = new Sort(new SortField(FILE_NODE_RATIO_FLD, SortField.INT, true));
68 public static final Sort SORT_BY_VALUE = new Sort(
69 new SortField(VALUE_FLD, SortField.INT, true),
70 new SortField(NODE_COUNT_FLD, SortField.INT, true)
71 );
72 67
73 public static final Analyzer analyzer = new SnowballAnalyzer(Version.LUCENE_CURRENT,"English"); 68 public static final Analyzer analyzer = new SnowballAnalyzer(Version.LUCENE_CURRENT,"English");
74 private static final FSDirectory dir1; 69 private static final FSDirectory dir1;
75 private static final FSDirectory dir2; 70 private static final FSDirectory dir2;
76 private static volatile Thread thread = null; 71 private static volatile Thread thread = null;
87 } 82 }
88 83
89 public static FSDirectory dir() { 84 public static FSDirectory dir() {
90 return dir2; 85 return dir2;
91 } 86 }
92 /* 87
93 static synchronized void clear()
94 throws IOException
95 {
96 new IndexWriter(dir,analyzer,true,IndexWriter.MaxFieldLength.LIMITED).close();
97 }
98 */
99 public static boolean isReindexing() { 88 public static boolean isReindexing() {
100 return thread != null && thread.isAlive(); 89 return thread != null && thread.isAlive();
101 } 90 }
102 91
103 public static void startReindexing(){ 92 public static void startReindexing(){
141 } 130 }
142 } finally { 131 } finally {
143 indexWriter.close(); 132 indexWriter.close();
144 } 133 }
145 } 134 }
146 /* 135
147 public static synchronized void removeBySubject(String subject)
148 throws IOException
149 {
150 Term term = new Term( SUBJECT_FLD, subject );
151 IndexWriter indexWriter = new IndexWriter(dir2,analyzer,IndexWriter.MaxFieldLength.LIMITED);
152 indexWriter.deleteDocuments(term);
153 indexWriter.close();
154 }
155 */
156 private static synchronized void reindex1(Server server,IndexWriter indexWriter) 136 private static synchronized void reindex1(Server server,IndexWriter indexWriter)
157 throws SQLException, IOException 137 throws SQLException, IOException
158 { 138 {
159 logger.info("reindex "+server.name); 139 logger.info("reindex "+server.name);
160 status = "reindexing "+server.name; 140 status = "reindexing "+server.name;
254 } finally { 234 } finally {
255 con.close(); 235 con.close();
256 } 236 }
257 } 237 }
258 238
259 private static final Pattern ptn = Pattern.compile("([^,]+),(\\d+|\"[0-9,]+\")");
260
261 private static Map<String,Integer> domainMap()
262 throws IOException
263 {
264 Map<String,Integer> map = new HashMap<String,Integer>();
265 File siteFile = new File("data/sites.csv");
266 if( !siteFile.exists() )
267 return map;
268 BufferedReader in = new BufferedReader(new FileReader(siteFile));
269 String line = in.readLine();
270 try {
271 while (!ptn.matcher(line).matches())
272 line = in.readLine();
273 while (true) {
274 if (line == null)
275 break;
276 if (line.length() > 0) {
277 if( line.startsWith(",") )
278 break;
279 Matcher m = ptn.matcher(line);
280 if (!m.matches())
281 throw new RuntimeException(line);
282 String domain = m.group(1);
283 String amt = m.group(2);
284 amt = amt.replaceAll("[,\"]", "");
285 int sessions = Integer.parseInt(amt);
286 map.put(domain, sessions);
287 }
288 line = in.readLine();
289 }
290 in.close();
291 } catch (RuntimeException e) {
292 logger.error("Error in line: " + line, e);
293 throw e;
294 }
295 return map;
296 }
297
298 private static void reindex2() 239 private static void reindex2()
299 throws IOException 240 throws IOException
300 { 241 {
301 Map<String,Integer> domainMap = domainMap();
302 IndexReader reader = IndexReader.open(dir1); 242 IndexReader reader = IndexReader.open(dir1);
303 IndexWriter indexWriter = new IndexWriter(dir2,analyzer,true,IndexWriter.MaxFieldLength.LIMITED); 243 IndexWriter indexWriter = new IndexWriter(dir2,analyzer,true,IndexWriter.MaxFieldLength.LIMITED);
304 try { 244 try {
305 int n = reader.numDocs(); 245 int n = reader.numDocs();
306 if( n != reader.maxDoc() ) 246 if( n != reader.maxDoc() )
340 int fileNodeRatio = fileCount*1000/nodeCount; 280 int fileNodeRatio = fileCount*1000/nodeCount;
341 doc.add( new NumericField(FILE_NODE_RATIO_FLD,Field.Store.NO,true).setIntValue(fileNodeRatio) ); 281 doc.add( new NumericField(FILE_NODE_RATIO_FLD,Field.Store.NO,true).setIntValue(fileNodeRatio) );
342 } 282 }
343 int monthlyViews = ((NumericField)data.getFieldable(MONTHLY_VIEWS_FLD)).getNumericValue().intValue(); 283 int monthlyViews = ((NumericField)data.getFieldable(MONTHLY_VIEWS_FLD)).getNumericValue().intValue();
344 doc.add( new NumericField(MONTHLY_VIEWS_FLD,Field.Store.YES,true).setIntValue(monthlyViews) ); 284 doc.add( new NumericField(MONTHLY_VIEWS_FLD,Field.Store.YES,true).setIntValue(monthlyViews) );
345 Integer sessions = domainMap.get(domain);
346 if( sessions == null )
347 sessions = 0;
348 doc.add( new NumericField(VALUE_FLD,Field.Store.YES,true).setIntValue(sessions) );
349 indexWriter.addDocument(doc); 285 indexWriter.addDocument(doc);
350 } 286 }
351 } finally { 287 } finally {
352 indexWriter.close(); 288 indexWriter.close();
353 reader.close(); 289 reader.close();
440 public int monthlyViews() { 376 public int monthlyViews() {
441 NumericField fld = (NumericField)doc.getFieldable(MONTHLY_VIEWS_FLD); 377 NumericField fld = (NumericField)doc.getFieldable(MONTHLY_VIEWS_FLD);
442 return fld.getNumericValue().intValue(); 378 return fld.getNumericValue().intValue();
443 } 379 }
444 380
445 public int value() {
446 NumericField fld = (NumericField)doc.getFieldable(VALUE_FLD);
447 return fld.getNumericValue().intValue();
448 }
449
450 } 381 }