Omar ID EL MOUMEN commited on
Commit
ae9ea80
·
1 Parent(s): 366638d

Add indexed specifications and integration

Browse files
Files changed (3) hide show
  1. app.py +54 -1
  2. indexed_specifications.json +3 -0
  3. static/script.js +1 -0
app.py CHANGED
@@ -304,8 +304,29 @@ class TsgDocFinder:
304
  class SpecDocFinder:
305
  def __init__(self):
306
  self.chars = "0123456789abcdefghijklmnopqrstuvwxyz"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
 
308
  def search_document(self, doc_id, release = None):
 
 
 
309
  series = doc_id.split(".")[0]
310
  while len(series) < 2:
311
  series = "0" + series
@@ -345,6 +366,38 @@ async def main_menu():
345
  return FileResponse(os.path.join("templates", "index.html"))
346
 
347
  @app.post("/search-spec", response_model=KeywordResponse)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  def search_spec(request: KeywordRequest):
349
  chars = "0123456789abcdefghijklmnopqrstuvwxyz"
350
  start_time = time.time()
@@ -438,7 +491,7 @@ def find_document(request: DocRequest):
438
  doc_id=request.doc_id,
439
  url=result,
440
  search_time=time.time() - start_time,
441
- scope=get_scope(request.doc_id, version)
442
  )
443
  else:
444
  raise HTTPException(status_code=404, detail=result)
 
304
  class SpecDocFinder:
305
  def __init__(self):
306
  self.chars = "0123456789abcdefghijklmnopqrstuvwxyz"
307
+ self.indexer_file = "indexed_specifications.json"
308
+ self.indexer_specs, self.indexer_scopes, self.last_indexer_date = self.load_indexer()
309
+
310
+ def load_indexer(self):
311
+ """Load existing index if available"""
312
+ if os.path.exists(self.indexer_file):
313
+ with open(self.indexer_file, "r", encoding="utf-8") as f:
314
+ x = json.load(f)
315
+ return x["specs"], x["scopes"], x["last_indexed_date"]
316
+ return {}, {}, None
317
+
318
+ def save_indexer(self):
319
+ """Save the updated index"""
320
+ self.last_indexer_date = today.strftime("%d/%m/%Y-%H:%M:%S")
321
+ with open(self.indexer_file, "w", encoding="utf-8") as f:
322
+ today = datetime.today()
323
+ output = {"specs": self.indexer_specs, "scopes": self.indexer_scopes, "last_indexed_date": self.last_indexer_date}
324
+ json.dump(output, f, indent=4, ensure_ascii=False)
325
 
326
  def search_document(self, doc_id, release = None):
327
+ for key in self.indexer_specs.keys():
328
+ if str(doc_id) in key:
329
+ return self.indexer_specs[key]['url']
330
  series = doc_id.split(".")[0]
331
  while len(series) < 2:
332
  series = "0" + series
 
366
  return FileResponse(os.path.join("templates", "index.html"))
367
 
368
  @app.post("/search-spec", response_model=KeywordResponse)
369
+ def search_spec_v2(request: KeywordRequest):
370
+ start_time = time.time()
371
+ kws = [_.lower() for _ in request.keywords.split(" ")]
372
+ results = []
373
+
374
+ for string, spec in finder_spec.indexer_specs.items():
375
+ if request.mode == "and":
376
+ if not all(kw in string.lower() for kw in kws):
377
+ continue
378
+ elif request.mode == "or":
379
+ if not any(kw in string.lower() for kw in kws):
380
+ continue
381
+ release = request.release
382
+ working_group = request.wg
383
+ spec_type = request.spec_type
384
+
385
+ if spec.get('version', None) is None or (release is not None and spec["version"].split(".")[0] != str(release)):
386
+ continue
387
+ if spec.get('working_group', None) is None or (working_group is not None and spec["working_group"] != working_group):
388
+ continue
389
+ if spec_type is not None and spec["type"] != spec_type:
390
+ continue
391
+
392
+ results.append(spec)
393
+ if len(results) > 0:
394
+ return KeywordResponse(
395
+ results=results,
396
+ search_time=time.time() - start_time
397
+ )
398
+ else:
399
+ raise HTTPException(status_code=404, detail="Specifications not found")
400
+
401
  def search_spec(request: KeywordRequest):
402
  chars = "0123456789abcdefghijklmnopqrstuvwxyz"
403
  start_time = time.time()
 
491
  doc_id=request.doc_id,
492
  url=result,
493
  search_time=time.time() - start_time,
494
+ scope=finder.indexer_scopes[request.doc_id] if request.doc_id in finder.indexer_scopes else get_scope(request.doc_id, version)
495
  )
496
  else:
497
  raise HTTPException(status_code=404, detail=result)
indexed_specifications.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8758708d306204eb8531717e9119a292d3b997d17f469191a573882329f933c
3
+ size 41158533
static/script.js CHANGED
@@ -225,6 +225,7 @@ function displayKeywordResults(data) {
225
  <p>Version: ${spec.version}</p>
226
  <p>WG: ${spec.working_group}</p>
227
  <p>URL: <a target="_blank" href="${spec.url}">${spec.url}</a></p>
 
228
  </div>
229
  `;
230
  resultsList.appendChild(resultItem);
 
225
  <p>Version: ${spec.version}</p>
226
  <p>WG: ${spec.working_group}</p>
227
  <p>URL: <a target="_blank" href="${spec.url}">${spec.url}</a></p>
228
+ <p>Scope: ${spec.scope}</p>
229
  </div>
230
  `;
231
  resultsList.appendChild(resultItem);