diff --git a/elastic_search_corpus.py b/elastic_search_corpus.py index 8cbed0e..83d70e6 100644 --- a/elastic_search_corpus.py +++ b/elastic_search_corpus.py @@ -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" @@ -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"} } } } diff --git a/query.py b/query.py index a601a7a..106a84e 100644 --- a/query.py +++ b/query.py @@ -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" @@ -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"] } } } @@ -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("----")