Skip to content
New issue

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

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

Already on GitHub? # to your account

autocomplete for phpcr_odm_path #112

Closed
dbu opened this issue Jan 20, 2014 · 9 comments
Closed

autocomplete for phpcr_odm_path #112

dbu opened this issue Jan 20, 2014 · 9 comments

Comments

@dbu
Copy link
Member

dbu commented Jan 20, 2014

the phpcr_odm_path form type could use an autocomplete functionality to make it easier to type a correct path.

@Burgov
Copy link

Burgov commented Jan 20, 2014

what kind of autocomplete were you looking for? Select2?
Perhaps https://github.com/SamsonIT/AutocompleteBundle could be useful for this?

@dbu
Copy link
Member Author

dbu commented Jan 20, 2014

hm, indeed that bundle looks exactly like what we would need. it currently seems to depend on doctrine orm which for our case makes no sense. if i got it right, we could provide a controller that searches through a phpcr repository either in this bundle or in the AutocompleteBundle (but you seem to not provide an orm controller either, so maybe we rather have it here).

@Burgov
Copy link

Burgov commented Jan 20, 2014

hm you're right, I forgot about the fact that it's hard coded to ORM at the moment :) I think it shouldn't be too hard to add some flexibility though. It doesn't actually work with controllers, but instead throws a response to the client in one of the form listeners at exactly the right moment. This minimized custom effort on the client side.

The ResultFetcher class would need some tweaking for compatibility with other QB classes. It could then accept a list of handlers which would do the magic, so for instance and ORMResultFetcher and a PHPCR-ODM result fetcher could then be attached through a DIC tag handled by a CompilerPass...

If you're interested I'll investigate deeper

@dbu
Copy link
Member Author

dbu commented Jan 20, 2014

i think the query builder for phpcr-odm is not even that different. the question will be what to search on however. one thing to search on could be the node names or even the path, so that i type "/cms/content/ab" and get proposed the "/cms/content/about" document. phpcr ids are like filesystem paths. if we use the slashes, we would need to split things as phpcr does never query on a full path, but can do things like ISDESCENDANTOF("/cms/content") AND NAME LIKE "ab*".

how can the form listener handle this? do you dump all possible results and there is no livesearch? with phpcr this could be very expensive, as you would dump the whole database. but then, that would be like the entity_type and document_type form types, so i guess you do something different?

@dbu
Copy link
Member Author

dbu commented Jan 20, 2014

and thanks a lot for your motivation to look into these things, really appreciate it!

@Burgov
Copy link

Burgov commented Jan 20, 2014

No problem!

What the bundle does is it appends a where and a limit to a query builder you pass to it (or you can let it create the query builder for you, works just like the entity type in core symfony).

It searches for all words you're searching for split by /\s+/.

So for example you have a query builder like this:

$em->getRepository("FooBundle:Bar")->createQueryBuilder("bar")->innerJoin("bar.baz", "baz");

and you type "some words" into the select2 box, the final query builder will be something like:

$em->getRepository("FooBundle:Bar")->createQueryBuilder("bar")->innerJoin("bar.baz", "baz")
  ->where("bar.name LIKE %some% OR bar.name LIKE %words%")
  ->setMaxResults(10);

So it won't select the whole database.

This is done in that same ResultFetcher, though, so basically, if the result fetcher can be configured, so can do anything with the QueryBuilder you like

@Burgov
Copy link

Burgov commented Jan 20, 2014

I set up a very basic preview version here: https://github.com/Burgov/symfony-cmf-standard/tree/autocomplete

currently it only searches for the title. I haven't done much with PHPCR yet, so I'm not really sure how to search for paths for example.

You can just setup the project like normally with CMF-standard and load the fixtures. Then go to /test-autocomplete

What do you think of it?

@dbu
Copy link
Member Author

dbu commented Jan 21, 2014

that was fast! i will try to have a look, but i fear i won't be able to before going to the php benelux conference. but for sure when i am back!

@lsmith77
Copy link
Member

ping

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants