-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonicha.py
More file actions
22 lines (18 loc) · 755 Bytes
/
Copy pathonicha.py
File metadata and controls
22 lines (18 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from elasticsearch import Elasticsearch
import spacy
# Initialize Elasticsearch
es = Elasticsearch()
# Example document indexing
def index_document(index_name, document):
es.index(index=index_name, body=document)
# Example query using spaCy
def query_technical_terms(index_name, query_text):
nlp = spacy.load("en_core_web_sm")
tokens = nlp(query_text)
query = " ".join([token.lemma_ for token in tokens if not token.is_stop])
results = es.search(index=index_name, body={"query": {"match": {"content": query}}})
return results
# Example usage
index_document("technical_docs", {"content": "Example technical document content"})
results = query_technical_terms("technical_docs", "How to install Python on Windows")
print(results)