Skip to content

Get the number of results (from `get_matches_estimated() #5

Closed

Description

@jdcaballerov
  • shouldn't we get a generator on reader.search() ? Do the libzim returns a list as-is? It's frequent to have thousands of results on large ZIM files.

I did the same as node-libzim getting 10 results and passing back a string vector. File.h returns Search class unique pointers.

 std::unique_ptr<Search> search(const std::string& query, int start, int end) const;
 std::unique_ptr<Search> suggestions(const std::string& query, int start, int end) const;

Ah ok I see. that's unfortunate. I didn't realized you hardcoded that. We should definitely be able to set those. But we'd need the number of results (from get_matches_estimated()) as well. How do you plan to address that?

Activity

  1. jdcaballerov commented on Apr 10, 2020

    @jdcaballerov
    ContributorAuthor

    @rgaudin Can you clarify How's the API use of get_matches_estimated() to close this feature ??

    I can already use the iterator from Cython for both search and suggestions (File.h)

    The first number is the result of get_matches_estimated()

     def file_search(self, query, start=0, end=10):
            cdef unique_ptr[zim.Search] search = self.c_file.search(query.encode('UTF-8'),start, end) 
            cdef zim.search_iterator it = dereference(search).begin()
        
            print(dereference(search).get_matches_estimated()) 
    
            while it != dereference(search).end():
                yield it.get_url().decode('UTF-8')
                preincrement(it)

    UTF-8 not decoded here but already fixed.

    Screen Shot 2020-04-10 at 16 34 28

  2. rgaudin commented on Apr 13, 2020

    @rgaudin
    Member

    Thanks for this.

    • Why is it named file_search() and not search() ? Do you intend to keep both versions?
    • I can't see how we can practically avoid having two methods to get the results count… do you?

    Otherwise, we'd need better names like get_search_results_count() and get_suggestions_results_count()

  3. jdcaballerov commented on Apr 13, 2020

    @jdcaballerov
    ContributorAuthor

    I have file_search since I haven't deleted the old search version waiting for your approval. The other works from C++ sending string vectors of 10, this one runs in Cython using the libzim search object directly.

    If you agree then I'll only keep this and delete the C++ search code from the wrapper and add the counts as separate.

  4. jdcaballerov commented on Apr 13, 2020

    @jdcaballerov
    ContributorAuthor

    Done 054e763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions