ArthurChen189 commited on
Commit
85aa854
1 Parent(s): 4c54fb1

add corpus

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import time
2
  import json
3
- from pyserini.search.lucene import LuceneImpactSearcher
4
  import streamlit as st
5
  from pathlib import Path
6
  import sys
@@ -53,6 +53,8 @@ encoder, index = encoder_index_map[encoder][runtime_index], encoder_index_map[en
53
  searcher = LuceneImpactSearcher(
54
  f'indexes/{index}', f'{encoder}', encoder_type=f'{runtime}')
55
 
 
 
56
  col1, col2 = st.columns([9, 1])
57
  with col1:
58
  search_query = st.text_input(label="search query", placeholder="Search")
@@ -72,11 +74,10 @@ if search_query or button_clicked:
72
  for i, result in enumerate(search_results[:10]):
73
  result_score = result.score
74
  result_id = result.docid
75
- if result.raw:
76
- contents = json.loads(result.raw)
77
- contents = contents['contents'] if 'contents' in contents else contents['content']
78
- else:
79
- contents = ''
80
 
81
  output = f'<div class="row"> <b>Rank</b>: {i+1} | <b>Document ID</b>: {result_id} | <b>Score</b>:{result_score:.2f}</div>'
82
 
 
1
  import time
2
  import json
3
+ from pyserini.search.lucene import LuceneImpactSearcher, LuceneSearcher
4
  import streamlit as st
5
  from pathlib import Path
6
  import sys
 
53
  searcher = LuceneImpactSearcher(
54
  f'indexes/{index}', f'{encoder}', encoder_type=f'{runtime}')
55
 
56
+ corpus = LuceneSearcher(f'indexes/index-unicoil')
57
+
58
  col1, col2 = st.columns([9, 1])
59
  with col1:
60
  search_query = st.text_input(label="search query", placeholder="Search")
 
74
  for i, result in enumerate(search_results[:10]):
75
  result_score = result.score
76
  result_id = result.docid
77
+ contents = json.loads(result.raw)
78
+ contents = contents['contents'] if 'contents' in contents else contents['content']
79
+ if contents == "":
80
+ contents = json.loads(corpus.doc(result_id).raw())['contents']
 
81
 
82
  output = f'<div class="row"> <b>Rank</b>: {i+1} | <b>Document ID</b>: {result_id} | <b>Score</b>:{result_score:.2f}</div>'
83