Skip to content

Methods needed for moving from sphinxsearch to Manticore PHP API #60

Closed

Description

@mikedin

Hello!

I'm moving from sphinxsearch and can't find several features at php api for manticore. Try to make samples with sphinx 2.0 php code.

  1. SetGroupBy method for grouping results. as far as I understand, this feature is present in manticore and maybe this feature covers by facets, but this is not covers by documentation. Please, explain - how can I group results?
  2. Set weights for fields for using custom order and ranges via SetWeights. As I read in documentation, manticore has custom weights feature via SELECT OPTIONS in SQL, but I can't find this method in php api. Not as method, not as, I don't know, some options of connection or something like that. How can I set this?

And it's not critical but - can I get primary ids from resultset as array, without array iteration? If can, how called this method?

Activity

  1. sanikolaev commented on Aug 30, 2021

    @sanikolaev
    Collaborator

    SetGroupBy method for grouping results. as far as I understand, this feature is present in manticore and maybe this feature covers by facets, but this is not covers by documentation. Please, explain - how can I group results?

    Set weights for fields for using custom order and ranges via SetWeights. As I read in documentation, manticore has custom weights feature via SELECT OPTIONS in SQL, but I can't find this method in php api. Not as method, not as, I don't know, some options of connection or something like that. How can I set this?

    #42

    And it's not critical but - can I get primary ids from resultset as array, without array iteration? If can, how called this method?

    I don't think you can avoid iteration completely, but you can use
    https://github.com/manticoresoftware/manticoresearch-php/blob/master/docs/searchclass.md#setsource to avoid getting unneeded fields.

  2. mikedin commented on Aug 30, 2021

    @mikedin
    Author

    Thanks for answer. But I have some additions

    You offer facets for php api instead groupby, but it's not similar, right? How facets works? I don't see it in documentation, try to explain.

    1. select brand_id from products group by brand_id limit 5.
      mysql and sphinx api via SetGroupBy first select all brand_id, then returns first 5 of it.
      But facets return in another structure! Will it works with limits? Which dataset will it use? I mean, facets works with all index or with results of query only, as aggregation from query result?
    2. select product_id, brand_id from products group by brand_id
      mysql and sphinxapi returns product_id, one (first?) for each brand_id and it's useful case. facets does not return product_id, right?

    As I understand, custom weights I can use only via sql, not php api. Do you have a plan for this feature? #42 was opened more than year ago, have you this feature in php api roadmap or not?
    As example, I can say, that this feature is very useful for e-commerce applications, for me like for #42 customer.

    No, I mean just simple method for ResultSet like $result->getHitIds(); returned just array with doc_id or (as in your code) hit id

  3. sanikolaev commented on Aug 31, 2021

    @sanikolaev
    Collaborator

    Will it works with limits?

    Yes, it will, see argument 3 here https://github.com/manticoresoftware/manticoresearch-php/blob/master/docs/searchclass.md#facet

    Which dataset will it use?

    Please take this course https://play.manticoresearch.com/faceting to understand how FACET works in Manticore

    facets does not return product_id, right?

    Yes, that's correct, FACET returns just field value / count

    custom weights I can use only via sql, not php api

    Correct.

    Do you have a plan for this feature? #42 was opened more than year ago, have you this feature in php api roadmap or not?

    It's not in our nearest plans. PRs are welcome!

    this feature is very useful for e-commerce applications, for me like for #42 customer

    We do professional services http://manticoresearch.com/services. If it's mission critical for you - contact us.

    No, I mean just simple method for ResultSet like $result->getHitIds(); returned just array with doc_id or (as in your code) hit id

    Got it, also not in our nearest plans. PR for this would be also appreciated.

  4. marclaporte commented on Sep 10, 2026

    @marclaporte

    @mikedin I know it has been 5 years but I am doing some housecleaning here :-) What is latest status for you?

    Manticore has had multiple innovations and releases:
    https://github.com/manticoresoftware/manticoresearch/releases

  5. mikedin commented on Sep 10, 2026

    @mikedin
    Author

    @marclaporte You are right, I don't remember all details that I have 5 years ago, but I solved +- all my questions. Don't ask how, it was a long time ago.
    I've read ticket again now, and still think if you have setWights alternative in sql, it would be nice to have it in php too - make sql string with a lot of fields in different places (usual case when create search request) is ugly way. One PHP call is much more nice.
    But you can close ticket, anyway.

  6. sanikolaev commented on Sep 18, 2026

    @sanikolaev
    Collaborator

    Thanks for the update. Since your original migration has been completed and you confirmed that the issue can be closed, I'm closing it.

    For anyone finding this issue later, the current status is:

    Field weights are now supported directly by the PHP client:

    $results = $search
        ->option('field_weights', [
            'title' => 20,
            'description' => 1,
        ])
        ->get();

    (docs: https://github.com/manticoresoftware/manticoresearch-php/blob/master/docs/searchclass.md#option)

    Basic grouping and counts are available through facet() and the aggregation API:
    https://github.com/manticoresoftware/manticoresearch-php/blob/master/docs/searchclass.md#facet

    This is suitable for retrieving group values and document counts. For full SQL GROUP BY semantics, such as selecting a representative document from each group, use the SQL endpoint.

    ResultSet does not currently have a getHitIds() helper. IDs can be collected as follows:

    $ids = [];
    foreach ($results as $hit) $ids[] = $hit->getId();

    A dedicated ResultSet::getIds() method can be proposed separately if there is still demand for that. PRs are welcome.

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