• Hi, I am looking to encode the search query before passing to typesense. Is this possible?

    Here is the idea:
    Default:
    User type string (search) –> search query is sent to typesense –> typesense return result –> display on frontend

    Idea:
    User type string (search) –> (hook here) search query is sent to a vector encoder –> the vector is sent to typesense –> typesense return result –> display on frontend

    Is there a hook or filter to implement this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor digamberpradhan

    (@digamberpradhan)

    Hi @webcreativemaster ,
    Yes, there is a hook that allows you to apply changes to the data before it is entered.
    The filter you are looking for is

    apply_filters( 'cm_typesense_data_before_entry', $formatted_data, $raw_data, $object_id, $schema_name );

    There is an example of it in the documentation as well here

    Thread Starter webcreativemaster

    (@webcreativemaster)

    Hi @digamberpradhan I thought that this filter is for the schema before it is pushed to typesense server? It applies to typed Search Queries as well?

    Plugin Contributor digamberpradhan

    (@digamberpradhan)

    Hi @webcreativemaster this filter is to modify / process the data/document before it is added to the collection.
    It only applies to the indexing process – not when you’re searching for documents.

    Plugin Contributor digamberpradhan

    (@digamberpradhan)

    $typesense_api_instance = \Codemanas\Typesense\Main\TypesenseAPI::getInstance();
    //$post = $post_object, 
    $post_id = '123';
    $post = get_post($post_id);
    $document = $typesense_api_instance->formatDocumentForEntry($post, $post_id, $post->post_type);
    $typesense_api_instance->upsertDocument($post->post_type,$document);

    You can use the code above, wherever you are going to trigger the code, you will need to get the post object – then format the data and add it to the collection.

    I hope this helps.

    Thread Starter webcreativemaster

    (@webcreativemaster)

    Hi

    Thanks! This works for the post thumbnail!

    But the search query is still hanging. So there is no way I can intervene the process between User Search Query —> Typesense?

    https://ibb.co/WkPnQFY

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hook to modify search query before passing to typesense’ is closed to new replies.