Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello!
I'm looking to implement Search API Autocomplete with Solr and it seems like a D8 port for the getAutocompleteSuggestions function in SearchAPISolrBackend.php wasn't finished or maybe it was working at one point but needs to be updated. Are any of the maintainers working on this currently and if so, do they have an ETA on when this might be ready in the dev branch? Thanks!
Comment | File | Size | Author |
---|---|---|---|
#23 | breaking_b.png | 25.62 KB | ressa |
#20 | 2790249_tests.patch | 35.91 KB | mkalkbrenner |
Comments
Comment #2
mkalkbrennerAutocomplete could be considered the child of the suggestor issue.
Comment #3
dawehnerAt least personally I never tried out search_api_autocomplete with the solr backend due to the requirements on my project.
Someone should at least give a try and adapt the solr backend with the changes we made in the search_api_DB backend. I think this should be not too much of an effort.
Comment #4
Punk_UnDeaDi'm alter search_api_solr plugin and implement getAutocompleteSuggestions
http://pastebin.com/YjMe0Mw9
but i have warning, because current getAutocompleteSuggestions method use argument type without right namespace
Comment #5
Hydra CreditAttribution: Hydra at erdfisch commentedNice, I jsut started debugging this and fixed the namespace issues. I took your code and put it into a patch for the SearchApiSolrBackend and it does not look that bad, thx for your work! Here the patch.
Comment #6
dawehnerComment #7
mkalkbrennerThe latest patch looks good. But at least it requires some tests.
But spellchecking / suggestions will be revised in general, because we don't leverage the power of this feature correctly. Nevertheless we can commit this patch as intermediate solution if some test coverage is added.
Comment #8
mkalkbrennerIn my first review I missed that search_api_autocomplete is not a included in search_api but a separate module.
We can't add such a dependency.
We need to discuss how to integrate with that module.
Comment #9
Punk_UnDeaDnamespaces not for dependencies, namespaces for right argument type in methods
without installed search_api_autocomplete all must work ok
without right namespaces mathod can't be called, because generate exception about wrong argument type
Comment #10
stBorchertInstead of adding a dependency into Search API Solr it would be best (IMHO) to use a bridge-module to integrate Search API Autocomplete.
The attached patch adds this bridge.
Comment #11
mkalkbrennerI talked to Thomas to get some background information before starting further discussions here.
Comment #12
ressa CreditAttribution: ressa as a volunteer commentedWith the combined effort of many people, the Search API Autocomplete recently got into a working state: #2700691: [search_api_autocomplete] Search API Autocomplete.
I recently tried the patch in #10, but couldn't quite make it work... Has somebody successfully made Search API, Search API Autocomplete and Search API Solr Search work together?
Comment #13
mkalkbrenner@ressa: Thanks for pointing me to #2700691: [search_api_autocomplete] Search API Autocomplete. I wasn't aware of this issue. And to be honest I think it's a bad practice to have these detailed information discussed there instead of within a meta issue in the search_api issue queue.
But it seems to make sense now to start working on the Solr part :-)
I think I won't accept the approach proposed in #10 because it will complicate the autocomplete support of search_api_multilingual.
Comment #14
dawehnerI agree with markus here, yes, its sad that its coupled with the class, but php totally allows us to do that, so we should not cripple ourselves. Searchapi has simply that design.
I also cannot agree more :)
Comment #15
ressa CreditAttribution: ressa as a volunteer commentedI agree that having a "Drupal 8 Contrib Porting Tracker" issue for a module separated from the modules' own issue queue is a problem for those looking for info on the status of a module. Perhaps it could be worth considering moving them into the modules' own issue queue? Many modules already have a "D8 version of this module?" issue, so it is the natural place to look for info on that, and track any progress.
Comment #16
mkalkbrennerI started by reviewing the existing implementation that doesn't work anymore. It's a strange implementation that uses search queries in combinations with facets.
I asked myself, why we didn't use one of the built-in features. Candidates are:
From my point of view, suggest_suffix should be solved using terms and suggest_words using suggester.
But then I realized and remembered that all of these advanced cool Solr features work per Index aka Core. And Search API has this concept of creating multiple virtual indexes in one Solr core. That's simply incompatible and caused the weird implementation we found in the code :-(
After a short discussion I decided to not skip these advanced features. The opposite is true and I plan to leverage them more and more to really make a difference regarding features, performance and scaleability compared to the DB backend.
Therefore we need to avoid that multiple Search API indexes are stored in one Solr Core.
I added a first patch that prevents the user from assigning multiple indexes to one core via the user interface and brings dramatically easier implementation of suggest_suffix.
It works on Solr 6 having comparable results to the DB backend. But Solr 5 and 4 have at least "some" suggestions which might lead to "no results" unless we extend their schema as well.
So this first patch is just a start and it is still work in progress. But it would be great to get some feedback already.
Comment #17
ressa CreditAttribution: ressa at Ardea commentedGreat start for a first patch, it works - and even with Search API Autocomplete :-)
For others who want to test it, here is a quick way of getting it up and running on a fresh install:
Download Search API Solr Search and required modules
Patch Search API Solr Search and enable module
Update schema.xml and restart
Search API Solr fulltext search View available at http://example.com/solr-search/content
Optional: Add Search API Autocomplete
Flush caches and activate, at
admin/config/search/search-api/index/default_solr_index/autocomplete
Like I wrote, the Search API Autocomplete Search works, the node number count seems to be off, though.
NOTE: I first tried downloading the modules with drush, but I got a Solarium error and WSOD:
After running
composer install
, only two Composer packages are installed:The
composer require "drupal/search_api_solr 1.x-dev"
command, which give you a working installation, updates a lot of packages:Comment #18
mkalkbrennerNow I added spell suggestions to the autocomplete box, but just for Solr 6.x.
And I improved the check for multiple enabled indexes on the same "server".
Comment #19
ressa CreditAttribution: ressa at Ardea commentedWorks beautifully, I now get suggestions on miss-spelled words - thanks!
Quick way of getting it all up and running, for testing:
Comment #20
mkalkbrennerThis patch is now the candidate for a final review. Changes compared to #18:
Comment #21
ressa CreditAttribution: ressa at Ardea commentedGreat work, the patch works fine - thanks!
The issue I had with the number count was because I was re-using a Solr index, which had old records in it. Once I made a new core, the suggestion count was perfect.
Comment #22
rdworianyn CreditAttribution: rdworianyn commentedI have tested the patch in #20 with the current -dev and Solr 6.x. The autocomplete is working for me, but there is a bit of unexpected behavior. This could be in my setup, but for example: a title field with value: "Breaking Bad" will either autocomplete "breaking" or "bad" but not the field value as a whole.
Comment #23
ressa CreditAttribution: ressa at Ardea commentedI can confirm this behavior:
Comment #24
mkalkbrennerThe DB backend doesn't suggest that in a reliable way, too. The DB backend just randomly picks words. So we're kind of compatible here.
Nevertheless Solr perfectly supports this kind of "phrase" auto completion using it's suggester component. Unfortunately there's no way to configure that component in a common way. A dedicated suggester needs to be configured per field in solrconfig.xml. But due to the fact that the number of fields is increased dynamically by Search API it's impossible to configure suggesters upfront. On the other hand, defining one especially for your use-case is simple. But it will require a small piece of custom code to get the data from it.
And suggesters need to be maintained. That means that you need a cron job to periodically "build" them. They are not real-time.
Search API Solr Multilingual contains a generator for the solrconfig.xml. We could use this one to create the required configuration every time you configured a search page that includes autocomplete. But that is out of scope for this issue here and requires a new feature request.
BTW I'll rename "suggest_words" to "suggest_corrections" and reserve "suggest_words" for the potentially upcoming new feature.
Comment #26
mkalkbrennerI slightly modified the patches again and committed them since the tests are passing on Solr 4,5 and 6.
But I opened a follow up: #2831842: Prepare usage of Solr's suggester component for autocomplete suggestions and re-enable multiple "indexes" per Solr Core later
Comment #27
ressa CreditAttribution: ressa at Ardea commentedI have just tested the latest dev-release of the module, and it's so nice to have Search API, Search API Autocomplete and Search API Solr Search (DEV) work together out-of-the-box - thank you @mkalkbrenner!
Comment #28
colincalnan CreditAttribution: colincalnan commented@ressa can you outline which versions of the modules you have that are working out of the box?
Comment #29
ressa CreditAttribution: ressa at Ardea commentedSure, these are the modules:
EDIT: You can also just take the commands from #2790249-19: Search API Autocomplete support, leaving out the two lines of patching. That should get you up and running.