Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service_type and doc_type #14

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
89 changes: 57 additions & 32 deletions sphinx_opensearch/sphinxsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def get_parser():
help='Option deletes old index with the same name and creates new '
'one.'
)
parser.add_argument(
'--doc-type',
metavar='<doc_type>',
help='Document type of the imported documents e.g. umn, api-ref... '
)
parser.add_argument(
'--doc-url',
metavar='<doc_url>',
Expand Down Expand Up @@ -97,6 +102,11 @@ def get_parser():
metavar='<password>',
help='Password for the connection.'
)
parser.add_argument(
'--service-type',
metavar='<service_type>',
help='Service type of corresponding service.'
)
parser.add_argument(
'--variant',
metavar='<variant>',
Expand Down Expand Up @@ -163,9 +173,9 @@ def get_file_structure(path):
return file_structure


def create_index_data(client, path, file_structure,
index, post_count, variant, base_url,
doc_url, category):
def create_index_data(base_url, category, client, doc_url, doc_type,
file_structure, index, path, post_count, service_type,
variant):
json_list = []
responses = []
file_structure_length = len(file_structure)
Expand All @@ -177,9 +187,11 @@ def create_index_data(client, path, file_structure,
file = open(file_path,)
data = json.load(file)
data['base_url'] = base_url
data['doc_url'] = doc_url
data['category'] = category
data["body"] = BeautifulSoup(data["body"], "lxml").text
data['category'] = category
data['doc_url'] = doc_url
data['doc_type'] = doc_type
data['service_type'] = service_type
file.close()
except Exception as e:
sys.exit("\nERROR:\n" + str(e))
Expand Down Expand Up @@ -229,37 +241,50 @@ def main():

base_url = add_end_slash(args.base_url)

doc_url = ''
doc_type = ''
service_type = ''
if args.doc_url:
doc_url = add_end_slash(args.doc_url)
doc_url = remove_start_slash(doc_url)

response = create_index_data(
client=client,
path=path,
file_structure=file_structure,
index=args.index,
post_count=args.post_count,
variant=args.variant,
base_url=base_url,
doc_url=doc_url,
category=args.category
)

else:
response = create_index_data(
client=client,
path=path,
file_structure=file_structure,
index=args.index,
post_count=args.post_count,
variant=args.variant,
base_url=base_url,
doc_url='',
category=args.category
)

print(str(response['uploaded_files']) + ' new files successfully imported'
' to index ' + args.index)
if not args.doc_type:
try:
doc_type_list = doc_url.split("/")
doc_type = doc_type_list[1]
except:
doc_type = ''

if not args.service_type:
try:
service_type_list = doc_url.split("/")
service_type = doc_type_list[0]
except:
service_type = ''

if args.doc_type:
doc_type = args.doc_type

if args.service_type:
service_type = args.service_type

response = create_index_data(
base_url=base_url,
category=args.category,
client=client,
doc_type=doc_type,
doc_url=doc_url,
file_structure=file_structure,
index=args.index,
path=path,
post_count=args.post_count,
service_type=service_type,
variant=args.variant
)

logging.info(str(response['uploaded_files'])
+ ' new files successfully imported to index '
+ args.index)


if __name__ == "__main__":
Expand Down