Skip to main content

Hoppysearch Search JavaScript Client

Project description

hoppysearch

hoppysearch - Python client for hoppysearch

Requirements.

Python 2.7 and 3.4+

Installation & Usage

pip install

Install it via:

pip install hoppysearch

Then import the package:

from hoppysearch import HoppySearch, ApiException

Getting Started

Please follow the installation procedure and then run the following:

Initial configuration:

from hoppysearch import HoppySearch, ApiException
index_id = YOUR_INDEX_ID
api_key = YOUR_API_KEY
hoppysearch = HoppySearch(index_id, api_key )

index

Please add the below code after Initial configuration to index your data.

documents = [
    {
        "Id": 101872,
        "ProductId": "B000DZH1D6",
        "UserId": "A1HKBX2L0DV258",
        "ProfileName": "Dena Leasure",
        "HelpfulnessNumerator": 0,
        "HelpfulnessDenominator": 0,
        "Score": 5,
        "Time": 1259625600,
        "Summary": "Gluten free cookies",
        "Text": "These are the best cookies I have found that are gluten free.  I love them!"
    }
]

optionals = {
    "configType": "create",
    "diag": "true"
}

try:
    response = hoppysearch.index(documents, optionals)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

The second argument of hoppysearch.index is not mandatory. You can skip it fully or you can skip any key value according to your requirement.

# skip second argument
documents = [
    {
        "Id": 101872,
        "ProductId": "B000DZH1D6",
        "UserId": "A1HKBX2L0DV258",
        "ProfileName": "Dena Leasure",
        "HelpfulnessNumerator": 0,
        "HelpfulnessDenominator": 0,
        "Score": 5,
        "Time": 1259625600,
        "Summary": "Gluten free cookies",
        "Text": "These are the best cookies I have found that are gluten free.  I love them!"
    }
]

try:
    response = hoppysearch.index(documents)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)
# skip some key of second argument
documents = [
    {
        "Id": 101872,
        "ProductId": "B000DZH1D6",
        "UserId": "A1HKBX2L0DV258",
        "ProfileName": "Dena Leasure",
        "HelpfulnessNumerator": 0,
        "HelpfulnessDenominator": 0,
        "Score": 5,
        "Time": 1259625600,
        "Summary": "Gluten free cookies",
        "Text": "These are the best cookies I have found that are gluten free.  I love them!"
    }
]

optionals = {
    "diag": "true"
}

try:
    response = hoppysearch.index(documents)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

You can pass file object or file path to upload data to index.

# filepath
documents = "C:/Users/Pragyan/Desktop/books.json"

try:
    response = hoppysearch.index(documents)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)
# fileobj
documents = open("C:/Users/Pragyan/Desktop/books.json", "r")

try:
    response = hoppysearch.index(documents)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

search

First add the configuration as mentioned above and then add below code to search.

query = "cookies"
optionals = {
    "searchableKeyList": "Summary, Text",
    "diag": "true",
    "showStats": "true",
    "pageSize": 10,
    "pageIndex": 0
}

try:
    response = hoppysearch.search(query, optionals)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

The second argument of hoppysearch.search is not mandatory. You can skip it fully or you can skip any key value according to your requirement.

# skip second argument
query = "cookies"
try:
    response = hoppysearch.search(query)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)
# skip some key of second argument
query = "cookies"
optionals = {
    "searchableKeyList": "Summary, Text",
    "pageSize": 10,
    "pageIndex": 0
}

try:
    response = hoppysearch.search(query)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

luceneSearch

First add the configuration as mentioned above and then add below code to perform search in advaced way.

luceneQuery = "Text: cookies"
optionals = {
    "defaultKeyNameToBeSearch": "Summary",
    "analyzerClass": "org.apache.lucene.analysis.standard.StandardAnalyzer",
    "diag": True,
    "showStats": True,
    "pageSize": 10,
    "pageIndex": 0
}

try:
    response = hoppysearch.lucene_search(luceneQuery, optionals)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

The second argument of hoppysearch.lucene_search is not mandatory. You can skip it fully or you can skip any key value according to your requirement.

# skip second argument
luceneQuery = "Text: cookies"
try:
    response = hoppysearch.lucene_search(luceneQuery)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)
# skip some key of second argument
luceneQuery = "Text: cookies"
optionals = {
    "defaultKeyNameToBeSearch": "Summary",
    "pageSize": 10,
    "pageIndex": 0
}

try:
    response = hoppysearch.lucene_search(luceneQuery, optionals)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

delete

First add the configuration as mentioned above and then add below code to delete specific data from index.

hs_guid = "15b522d8-1545-4dc9-9160-0b512f7d6997"
optionals = {
    "diag": True,
    "showStats": True
}

try:
    response = hoppysearch.delete(hs_guid, optionals)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

The second argument of hoppysearch.delete is not mandatory. You can skip it fully or you can skip any key value according to your requirement.

# skip second argument
hs_guid = "15b522d8-1545-4dc9-9160-0b512f7d6997"
try:
    response = hoppysearch.delete(hs_guid)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)
# skip some key of second argument
hs_guid = "15b522d8-1545-4dc9-9160-0b512f7d6997"
optionals = {
    "diag": True
}

try:
    response = hoppysearch.delete(hs_guid, optionals)
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

stats

First add the configuration as mentioned above and then add below code to get stats.

try:
    response = hoppysearch.stats()
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

clearIndex

First add the configuration as mentioned above and then add below code to clear all data from your index.

try:
    response = hoppysearch.clear_index()
    print(response)
except ApiException as e:
    print("Exception: %s\n" % e)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hoppysearch-0.0.11.tar.gz (19.5 kB view hashes)

Uploaded Source

Built Distribution

hoppysearch-0.0.11-py3-none-any.whl (19.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page