perlperl-modulexapian

Get specific data form Xapian database with Perl


I'm writing a perl script to retrieve search results from a Xapian database.

I uses the Search::Xapian module and tried the basic Xapian Query Example. This basic program allow to make a query and get a array of results sorted by relevancy. My problem is that the get_data() method return the whole datas from the document (url, filname, abstract, author, ...) mixed together as a string.

I searched in the CPAN module for a method to get each data one by one but I didn't find it.

Is it possible to get the filename, url, author, ... one by one to put them in a specific variable ?


Solution

  • You've not posted the code to produce this, or details of your setup. See the simplesearch.pl example, rather than print it out, assign what you want to a variable:

    # Display the results.
    printf "%i results found.\n", $mset->get_matches_estimated();
    printf "Results 1-%i:\n", $mset->size();
    
    foreach my $m ($mset->items()) {
        printf "%i: %i%% docid=%i [%s]\n", $m->get_rank() + 1, $m->get_percent(), $m->get_docid(), $m->get_document()->get_data();
    }