PHP - How to set up wildcard and fuzzy searches in Sphinx w / RT indexes


I am trying to research sphinx rt indices for use in a future project and have some questions about them.

  • Is there a way to do a wildcard search on sphinx rt indices?
  • How can I request rt index with sphinx api client for php?

The only way that I found - use mysql_connect()and mysql_query()with sphinxQL.

+3
source share
2 answers

I asked this question on the sphinxsearch forum and got this answer:

Hello.

barryhunter simply answered the search for wildcards for RT indices:

=== cut ===

1.Is there any way to make wildcard search in sphinx rt indexes?

I do not believe, therefore - not yet implemented. Check the Tracker error if you do not add it as a function request.

2.How can I query rt index with sphinx client api for php?

, Sphinx API RT- ( )

( RT / ( ), . , sphinx API, sphinxQL, )

=== ===

+1

1.) , enable_star min_infix_len define_index:

    class Post...
        define_index do
         ...

         set_property :enable_star => true
         set_property :min_infix_len => 1 
    end

, config/sphinx.yml:

 production:
     enable_star: true
     min_infix_len: 1

, , Sphinx Sphinx, , , , Sphinx. Sphinx , :

    RAILS_ENV=xxx
    rake ts:stop
    rake ts:conf
    rake ts:in
    rake ts:start

Sphinx Sphinx :

    $ vim config/production.sphinx.conf

, :

    ...
    index post_core
    {
        ...
        min_infix_len = 1
        enable_star = true
    }
    ...

:

    Post.search('xxx', :star => true)

, , :

class SearchController...
    def index
    @query = params[:query]
    options = {
         :page => params[:page], :per_page => params[:per_page], :star => true,
         :field_weights => { :title => 20, :tags => 10, :body => 5 }
    }
    @posts = Post.search(@query, options)
end

. , .

, , heres front-end php :

     <% @posts.each do |post| %>
     content goes here...
     <% end %>

2.) rt- sphinx api php:

    include('include/sphinxapi.php');

    $_longitude = '42.358431';
    $_latitude = '-71.059773';

    $search = new SphinxClient();
    $search->SetServer('[SERVER IP REMOVED]', 9312);
    $search->SetConnectTimeout(1);
    $search->SetArrayResult(true);
    $search->SetMatchMode(SPH_MATCH_ALL);
    $search->SetGeoAnchor('venue_latitude', 'venue_longitude', (float)deg2rad($_latitude), (float)deg2rad($_longitude));
    $search->SetSelect('*');
    $search->SetLimits(0, 100);
    $result = $search->Query('b', 'rt_deals');

    # results, print_r($result):

    Array
    (
            [error] =>
            [warning] =>
            [status] => 0
            [fields] => Array
            (
                    [0] => deal_types
            )
            [attrs] => Array
            (
                    [venue_id] => 1
                    [venue_latitude] => 5
                    [venue_longitude] => 5
                    [dt_start] => 2
                    [dt_end] => 2
                    [@geodist] => 5
            )
            [matches] => Array
            (
                    [0] => Array
                            (
                            [id] => 45
                            [weight] => 1
                            [attrs] => Array
                            (
                            [venue_id] => 42
                            [venue_latitude] => 0.73878991603851
                            [venue_longitude] => -1.2425578832626
                            [dt_start] => 0
                            [dt_end] => 0
                            [@geodist] => 15278498
                            )
                            )
                    [1] => Array
                            (
                            [id] => 46
                            [weight] => 1
                            [attrs] => Array
                            (
                            [venue_id] => 41
                            [venue_latitude] => 0.73908978700638
                            [venue_longitude] => -1.2415384054184
                            [dt_start] => 0
                            [dt_end] => 0
                            [@geodist] => 15278115
                            )
                            )
            )
            [total] => 2
            [total_found] => 2
            [time] => 0.000
            [words] => Array
            (
                    [b] => Array
                            (
                            [docs] => 2
                            [hits] => 2
                            )
            )
    )

GeoSpatial Search, Sphinx Search w/Php God-Object.com

0

All Articles