-
Notifications
You must be signed in to change notification settings - Fork 24
/
demo_search.py
40 lines (32 loc) · 1.15 KB
/
demo_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
def main():
import sys
if len(sys.argv)!=2:
print("only accept one query.")
return
search(sys.argv[1])
def search(query):
from py4j.java_gateway import JavaGateway, GatewayParameters
from py4j.java_gateway import java_import
from py4j.protocol import Py4JNetworkError
try:
gateway = JavaGateway(gateway_parameters=GatewayParameters(port=28834))
java_import(gateway.jvm,'net.sourceforge.docfetcher.gui.Application')
Application = gateway.jvm.net.sourceforge.docfetcher.gui.Application
indexPanel=Application.indexPanel
indexRegistry = indexPanel.getIndexRegistry()
from py4j.protocol import Py4JJavaError
try:
searcher = indexRegistry.getSearcher()
if searcher is None:
return
results=searcher.search(query)
except Py4JJavaError as e:
print(e)
return
for doc in results:
print(doc.getFilename()+'\t'+doc.getPath().toString())
except Py4JNetworkError as e:
print("cannot connect to JVM.")
if __name__ == "__main__":
main()