Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken abstraction on search attributes #7

Open
rollsappletree opened this issue Nov 23, 2020 · 0 comments
Open

Broken abstraction on search attributes #7

rollsappletree opened this issue Nov 23, 2020 · 0 comments

Comments

@rollsappletree
Copy link

rollsappletree commented Nov 23, 2020

The Scout abstraction is broken: in fact when you use "Builder::search" method it is supposed to accept the string you want to search. Insted, to make this works correctly, you must add the Solr Key too.

Detailed description

It's not possible to search within some key. Or at least is impossible to do it without 'hacking' the way this driver works.
I'm using this Scout engine to use it against Solr. So far so good.
I implemented my own SearchableArray to be saved on Solr and everything works nice.
Then I tried to search within a key, but the search did not worked.

Debugging i was able to make it works: but i had to search for $key.':'.$searchString instead of $searchString alone.

Context

That's how my model is translated on Solr:

    /**
     * Get the indexable data array for the model.
     */
    public function toSearchableArray(): array
    {
        //return $this->toArray();
        return [
            'id' => $this->id,
            'terms' => \strip_tags(
                \sprintf(
                    '%s %s %s %s %s',
                    $this->name,
                    $this->description_title,
                    $this->description_text,
                    $this->box_title,
                    $this->box_text,
                )
            ),
            'tags' => $this->tags->pluck('name')->toArray(),
        ];
    }

That's the way Scout docs suggest to make search.
Eg: Search for word "Hello" into terms key:

$collectionTerms = Service::search('hello')->within('terms')->get();

This does not works. To make it works as expected you have to "hack" it this way:

$collectionTerms = Service::search('terms:hello')->get(); //->within('terms') part is not necessary anymore

or use where

$collectionTerms = Service::search()->where('terms', 'hello')->get;

Possible implementation

Would be nice if the "within" attribute would be used into search instead of using "where" (that is nice too)

Your environment

Include as many relevant details about the environment you experienced the bug in and how to reproduce it.

  • Version used PHP 7.4)
  • Operating system and version (Ubuntu 18.04)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant