forked from searx/searx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request searx#2271 from kvch/open-semantic-search-engine
Open Semantic Search Engine
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
Open Semantic Search | ||
@website https://www.opensemanticsearch.org/ | ||
@provide-api yes (https://www.opensemanticsearch.org/dev) | ||
@using-api yes | ||
@results JSON | ||
@stable yes | ||
@parse url, title, content, publishedDate | ||
""" | ||
from dateutil import parser | ||
from json import loads | ||
from urllib.parse import quote | ||
|
||
base_url = 'http://localhost:8983/solr/opensemanticsearch/' | ||
search_string = 'query?q={query}' | ||
|
||
|
||
def request(query, params): | ||
search_path = search_string.format( | ||
query=quote(query), | ||
) | ||
params['url'] = base_url + search_path | ||
return params | ||
|
||
|
||
def response(resp): | ||
results = [] | ||
data = loads(resp.text) | ||
docs = data.get('response', {}).get('docs', []) | ||
|
||
for current in docs: | ||
item = {} | ||
item['url'] = current['id'] | ||
item['title'] = current['title_txt_txt_en'] | ||
if current.get('content_txt'): | ||
item['content'] = current['content_txt'][0] | ||
item['publishedDate'] = parser.parse(current['file_modified_dt']) | ||
results.append(item) | ||
|
||
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters