Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions elastic_search_corpus.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from elasticsearch import Elasticsearch, helpers
import json

# Connect to Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200, 'scheme': 'http'}])
es = Elasticsearch(
hosts=["https://elastic.hpc-crc.duckdns.org"], # Replace with your Elasticsearch host
http_auth=("juan.grados", ""),
verify_certs=False # Do not verify SSL certificates
)

# Define the index name
index_name = "crypto_module"
Expand All @@ -15,20 +18,20 @@
mapping = {
"mappings": {
"properties": {
"function_name": {"type": "text", "analyzer": "english"},
"docstring": {"type": "text", "analyzer": "english"},
"function_name": {"type": "text", "analyzer": "whitespace"},
"docstring": {"type": "text", "analyzer": "standard"},
"sections": {
"type": "object",
"properties": {
"summary": {"type": "text", "analyzer": "english"},
"parameters": {"type": "text", "analyzer": "english"},
"returns": {"type": "text", "analyzer": "english"},
"explanation": {"type": "text", "analyzer": "english"},
"related_functions": {"type": "text", "analyzer": "english"},
"examples": {"type": "text", "analyzer": "english"},
"notes": {"type": "text", "analyzer": "english"},
"references": {"type": "text", "analyzer": "english"},
"see_also": {"type": "text", "analyzer": "english"}
"summary": {"type": "text", "analyzer": "standard"},
"parameters": {"type": "text", "analyzer": "standard"},
"returns": {"type": "text", "analyzer": "standard"},
"explanation": {"type": "text", "analyzer": "standard"},
"related_functions": {"type": "text", "analyzer": "whitespace"},
"examples": {"type": "text", "analyzer": "standard"},
"notes": {"type": "text", "analyzer": "standard"},
"references": {"type": "text", "analyzer": "whitespace"},
"see_also": {"type": "text", "analyzer": "standard"}
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from elasticsearch import Elasticsearch

# Connect to Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200, 'scheme':'http'}])
es = Elasticsearch(
hosts=["https://elastic.hpc-crc.duckdns.org"], # Replace with your Elasticsearch host
http_auth=("juan.grados", ""),
verify_certs=False # Do not verify SSL certificates
)

# Define the index name
index_name = "crypto_module"
Expand All @@ -10,8 +14,8 @@
query = {
"query": {
"multi_match": {
"query": "How to use RSA with SymPy",
"fields": ["function_name^5", "sections.summary"]
"query": "How to use Diffie Hellman with SymPy",
"fields": ["function_name^5", "sections.summary", "docstring"]
}
}
}
Expand All @@ -27,9 +31,9 @@


# Print out the results
#for hit in response['hits']['hits']:
# print(f"Function Name: {hit['_source']['function_name']}")
# print(f"Summary: {hit['_source']['sections'].get('summary', 'No summary available')}")
# print(f'Score : {hit["_score"]}')
# print(f'Source : {hit["_source"]}')
# print("----")
for hit in response['hits']['hits']:
print(f"Function Name: {hit['_source']['function_name']}")
print(f"Summary: {hit['_source']['sections'].get('summary', 'No summary available')}")
print(f'Score : {hit["_score"]}')
print(f'Source : {hit["_source"]}')
print("----")