Docs/contacts-search

From Apertis
Jump to: navigation, search

Contacts search

This allows to search for fields of contacts, and to get the results of the search sorted by full name if desired.

Source

See query, simple-query, and search-view in the fuzzy branch here.

Basic explanation

  • Query contains basic definitions (constants, etc.)
  • SimpleQuery contains the search definitions (the query token and fields to match)
  • SearchView provides the means to retrieve the search results (using the query defined in SimpleQuery)
    • individuals returns a Map with the unsorted map of <Individual.id, Individual> returned by the search
    • sorted_individuals returns a sorted List of Individuals
    • For a paged, sorted list, call get_sorted_page(int page_size, int page_num)


Folks-inspect option

A basic search option has been added to folks-inspect. It will search the name fields of contacts and output the matching contacts.

Usage:

folks-inspect search [string]


Example

Here is a basic example, extracted from folks-inspect tool

 using Folks;
 using Gee;
 using GLib;
 private class Folks.Inspect.Commands.Search : Folks.Inspect.Command
 {
   public Search (Client client)
     {
       base (client);
     }
 
   public override async void run (string? command_string)
     {
       if (command_string == null)
         {
           /* A search string is required */
           Utils.print_line ("Please enter a search string");
         }
       else
         {
           var query = new SimpleQuery (
             command_string, Query.MATCH_FIELDS_NAMES);
           var search_view = new SearchView (this.client.aggregator, query);
           try
           {
             yield search_view.prepare ();
           }
           catch (GLib.Error e)
           {
             GLib.warning ("Error when calling prepare: %s\n", e.message);
           }     
           foreach (var individual in search_view.individuals.values)
             Utils.print_individual (individual, true);
         }
     }
 }