|
Revision 1677, 2.8 kB
(checked in by augur, 4 years ago)
|
Initial revision
|
- Property svn:eol-style set to
native
- Property svn:executable set to
*
- Property svn:keywords set to
Author Date Id Revision
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
import sys |
|---|
| 23 |
import time |
|---|
| 24 |
from swish import * |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
class swishtest: |
|---|
| 28 |
|
|---|
| 29 |
def __init__(self, argv): |
|---|
| 30 |
if argv[1:]: |
|---|
| 31 |
query=" ".join(argv[1:]) |
|---|
| 32 |
self.search(query) |
|---|
| 33 |
else: |
|---|
| 34 |
print('test.py <search query>') |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
def search(self, query): |
|---|
| 38 |
file = "index.swish-e" |
|---|
| 39 |
|
|---|
| 40 |
handle = SwishInit(file) |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
if SwishError(handle): |
|---|
| 44 |
print( 'err: ' + SwishErrorString(handle) + ': Could not open the index file \'' + file + '\'' ) |
|---|
| 45 |
print('.') |
|---|
| 46 |
sys.exit(1) |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
search = New_Search_Object(handle, query) |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
before=time.time() |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
results = SwishExecute(search, query) |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
taken=time.time() - before |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
print('# Search words: ' + query ) |
|---|
| 62 |
print("# Number of hits: " + str(SwishHits(results)) ) |
|---|
| 63 |
print("# Search time: "+str(taken) + " seconds") |
|---|
| 64 |
if SwishHits(results) == 0: print('err: no results') |
|---|
| 65 |
while 1: |
|---|
| 66 |
|
|---|
| 67 |
result=SwishNextResult(results) |
|---|
| 68 |
if not result: break |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
print( SwishResultPropertyStr(result, "swishrank") +" "+ \ |
|---|
| 72 |
SwishResultPropertyStr(result, "swishdocpath") + ": \"" + \ |
|---|
| 73 |
SwishResultPropertyStr(result, "swishtitle") + "\" " + \ |
|---|
| 74 |
SwishResultPropertyStr(result, "swishdocsize") \ |
|---|
| 75 |
) |
|---|
| 76 |
|
|---|
| 77 |
print('.') |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
Free_Results_Object(results) |
|---|
| 81 |
|
|---|
| 82 |
SwishClose(handle) |
|---|
| 83 |
|
|---|
| 84 |
def main(): |
|---|
| 85 |
swishtest(sys.argv) |
|---|
| 86 |
|
|---|
| 87 |
if __name__ == '__main__': |
|---|
| 88 |
main() |
|---|