#community-help

Optimizing JSON Data Import and Search with PHP Library

TLDR Arumugam experienced slow search results and data import time with json and PHP library. Kishore Nallan advised trying import and provided guidance on integrating the function into a PHP application. The issue was resolved as the search results are now displayed faster.

Powered by Struct AI
32
20mo
Solved
Join the chat
Jan 16, 2022 (20 months ago)
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
05:23 AM
I have tried php library with json sample data(10k), it takes more time to show search results... Do we need to get data from json on every search ??
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
05:28 AM
👋 Do you mean that the search takes time or the import?
Jan 17, 2022 (20 months ago)
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
04:23 AM
Create collection from jsonl file takes more time
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:10 PM
Are you running Typesense locally or on a server? How long does it take to import the 10K documents?
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
05:34 PM
Running locally using postman... takes 1 min.. attached image FYI
05:37
Arumugam
05:37 PM
Jan 19, 2022 (20 months ago)
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
06:15 AM
Hello
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
07:12 AM
Arumugam I'm afraid I don't follow you still.

Can you add some logging to your code to see which exact call takes a long time? The code snippet above contains both document creation and search operations.
07:13
Kishore Nallan
07:13 AM
Also, instead of looping and indexing each document, use Import: https://typesense.org/docs/0.22.1/api/documents.html#index-multiple-documents
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
08:24 AM
Tried with import, now search result showing with in 600ms
08:24
Arumugam
08:24 AM
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:25 AM
What's is the time taken value in the json response?
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
08:26 AM
Sorry for my question.. I have downloaded PHP library and access like this http://localhost/typesense-php-master/examples/collection_operations.php?query=Harry with the help of docker
08:27
Arumugam
08:27 AM
In the documentation end point showing like GET ${TYPESENSE_HOST}/collections/:collection/documents/search
08:27
Arumugam
08:27 AM
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:27 AM
In the response Typesense will return the time it took internally for the search. Can you post that?
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
08:32 AM
[found] => 1
    [hits] => Array
        (
            [0] => Array
                (
                    [document] => Array
                        (
                            [authors] => Array
                                (
                                    [0] => J.K. Rowling
                                    [1] =>  Mary GrandPré
                                )

                            [authors_facet] => Array
                                (
                                    [0] => J.K. Rowling
                                    [1] =>  Mary GrandPré
                                )

                            [average_rating] => 4.44
                            [id] => 2
                            [image_url] => https://images.gr-assets.com/books/1474154022m/3.jpg
                            [publication_year] => 1997
                            [publication_year_facet] => 1997
                            [ratings_count] => 4602479
                            [title] => Harrywww Potter and the Philosopher's Stone
                        )

                    [highlights] => Array
                        (
                            [0] => Array
                                (
                                    [field] => title
                                    [matched_tokens] => Array
                                        (
                                            [0] => Harrywww
                                        )

                                    [snippet] => <mark>Harrywww</mark> Potter and the Philosopher's Stone
                                )

                        )

                    [text_match] => 33514496
                )

        )

    [out_of] => 9979
    [page] => 1
    [request_params] => Array
        (
            [collection_name] => books
            [per_page] => 10
            [q] => Harrywww
        )

    [search_cutoff] => 
    [search_time_ms] => 0
)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:32 AM
Search time ms is 0 as per Typesense.
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
08:34
Arumugam
08:34 AM
I want to integrate with my php application
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:37 AM
I'm sorry, but I still don't understand what problem you are facing here.
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
08:39 AM
As per my understanding, need to keep required information in jsonl file right
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:41 AM
I think it is best if you can post the full code snippet as a Github gist, and describe what problem you are facing fully.
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
08:44 AM
I'm not facing problem, now search result showing quickly
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:45 AM
👍
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
08:45 AM
I want to integrate search function in my PHP application, just asking your guidance
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:45 AM
You will integrate just as you integrate with any other data store or database.
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
08:48 AM
Do you have any reference to use mysql database instead of jsonl
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:49 AM
We don't integrate directly with the database. You have to either write to Typesense at the same time you write to the DB in the application.

Or dump data from your DB periodically, convert to JSONL and index them into Typesense
Arumugam
Photo of md5-fc655f9994cdc8c6eab4294b2e1528a0
Arumugam
08:50 AM
Okay, Thank you so much
08:50
Arumugam
08:50 AM
Sorry for my small questions
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:50 AM
No worries 👍