Wondering if you can suggest a solution or guide me where to start in integrating Domain Access module with Search API? I'd like to be able to restrict the search results in Views by domain.
Wondering if you can suggest a solution or guide me where to start in integrating Domain Access module with Search API? I'd like to be able to restrict the search results in Views by domain.
Comments
Comment #1
drunken monkeyDepends on what the Domain Access provides? New Field API field types? New entities?
In any case, integrating with the Entity API is what you'll have to do to use that data with the Search API.
Comment #2
ximo commentedI needed the same functionality (except I'm not using Views), and got it sort of working..
It only indexes the source domain of nodes, I couldn't get multivalue for all domains to work. I tried setting the type to
list<integer>, but that would only get rewritten tointegerinsearch_api_extract_fields()and stored as a single value.@drunken monkey, any advice as to how I can get multivalue working? I'd like to index all the values of
$node->domains, which is an array of domain IDs. I would also need to account for "Send to all affiliates", which is represented by-1.I wouldn't know how to expose the filter to Views though.
Edit:
Meh, I crossposted when simplifying the code to use $node->domain_source instead of $node->domains. The
smb_solr_entity_property_get_domain()function drunken monkey mentions below is this custom getter:Comment #3
drunken monkeySo the domain is no Field API field?
Having
'type' => 'list<integer>'should work when you return an array fromcustom_entity_property_get_domain().Also in
custom_entity_property_get_domain()you can just check for-1and return an array with all domain IDs in that case.Comment #4
leewillis77 commentedHi, we've just come across this issue as well. Our final solution (For reference) was this:
NOTE: this DOESN'T deal with the -1 issue since that's not something we're using on this site. However if you wanted to account for it, I'd suggest filtering for the -1 in the search_api_query_alter since returning all domains at time of index means that content won't appear for domains created after the content is indexed. That would more closely reflect the behaviour of domain access' -1 functionality.
Comment #5
mikeskull commentedI have just done this a second ago but it wouldnt work until I added 2 extra args to my getter callback, see custom_get_domain_info() below, added $type and $info.
Also this works fine with Views 3 and the "post to all affiliates" options being checked on a node.
So in terms of what else I did on top of this it was add the code above to a custom module, once done you can add the field to the index via search API's index edit page, clear the index and re index. My search view just has a filter of the search fulltext, showing the title and the extract (with highlighting turned on via the Search API server advanced settings, *hint* tick them all theres a hidden checkbox).
Job done, if anyone gets any issues post them here ill try and help out if I can.
Comment #6
leewillis77 commentedInteresting. The example getters I can find all have varying numbers of parameters, it seems though that the "default" getter is entity_property_verbatim_get which accepts:
entity_property_verbatim_get($data, array $options, $name, $type, $info)ref: http://drupalcontrib.org/api/drupal/contributions%21entity%21includes%21...
So - looks like your version is preferred.
Comment #7
mikeskull commentedthere used to be:
http://drupalcontrib.org/api/drupal/contributions!entity!includes!entity...
which took the 3 you were passing in, these have calls at the bottom of entity.property.inc for backward compatibility, I assume theres been some mix up here.
example:
Comment #8
Anonymous (not verified) commentedI also use solution #5 and it works. Just make sure to index the field.
Maybe this could be part of the Workflow tab? If that makes sense.
Cheers.
Comment #9
agileadamI cleaned up a few things in #5 and it's working like a charm. Thank you!
Comment #10
Nuno Ricardo Da Silva commentedHi,
I'm facing the same problem. Can you please tell in wich file should i put the code inb the #5 solution?
Thanks in advence.
BR.
Comment #11
tancYour custom module. Any time you see code which invokes a hook, like hook_search_api_query_alter you need to replace the word hook with your module name. So in the examples above the module is named 'custom' so all the hook functions are prefixed with custom.
Comment #12
leewillis77 commentedYour best bet is to create a module for this code - it's the cleanest solution, and then re-usable on other projects if you need it.
Comment #13
Tim Jones Toronto commentedTested code in #5 using a custom module.
1. In Search API, selected ‘Domain Access Information’ in 'select fields to index'.
2. When performing ‘Index now’, I get the following error:
An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: /batch?render=overlay&id=82&op=do StatusText: OK ResponseText: Fatal error: Call to undefined function custom_get_domain_info() in /usr/share/nginx/www/testsearch/sites/all/modules/entity/includes/entity.wrapper.inc on line 444Thanks.
If we could get this working, could it be included as part of the Search API module with a check Domain Access module exists to add the extra field Domain Access Information'? This would be useful.
Comment #14
leewillis77 commentedSounds like you've changed the function names, but not updated the value of 'getter callback' in custom_entity_property_info_alter().
Comment #15
Tim Jones Toronto commentedThanks Lee, the module is now called 'xyz' (i did 'custom' named module before, but have since double checked, and renamed it to be sure). With the new module name, I get the similar error:
'Call to undefined function xyz_get_domain_info() in /usr/share/nginx/www/TESTSITE/sites/all/modules/entity/includes/entity.wrapper.inc on line 444'
The code, from what I can see, is the same as #5? :
Comment #16
leewillis77 commentedYou'll need to clear your cache - drupal will still be using the getter_callback you had defined previously, and not finding it.
Comment #17
Tim Jones Toronto commentedYes, I had cleared the cache and restarted all server services, but still got the error as before.
Someone else had a similar error situation here: http://drupal.org/node/1324832 when using the 'getter callback' for new data types.
Their solution was to include the reference to the include in the custom module.info files[] section, but I haven’t had any joy so far.
Will keep testing and thanks for your time and help too Lee.
Tim.
Comment #18
leewillis77 commentedCan you post your full module code somewhere we can take a look?
Comment #19
cyberschorschThe error is simple to explain. There is a missing } after the first function.
Correct Code:
Comment #20
Tim Jones Toronto commented@Cyberschorsch Thanks!!
The missing } had slipped to the bottom of the code :)
Comment #21
ktrev commentedHi,
I just used your code
But in the views I am getting the error undefined function custom_get_domain_info()
Please help
Comment #22
leewillis77 commentedIf you've renamed the functions to fit with your module definition, then you need to make sure you've renamed the callback:
'getter callback' => 'custom_get_domain_info',
Comment #23
drunken monkeyI think this is fixed? Otherwise, please re-open!
Comment #25
rp7 commentedFYI
People who are still looking for this, would like to point you to https://drupal.org/sandbox/raf/2244229. Offers configurable filters by domain (on indexing time, as well as query time), as well as a domain facet. Planning to have it released as a full module as soon as it's polished & Views integration has been improved.
Comment #26
geek-merlinAlso crosslinking this *very* simple sandbox:
https://www.drupal.org/sandbox/svendecabooter/2010206
Comment #27
lesleyfernandes commented@RaF7 and @axel.rutz, do you have plans to release your modules as full? Thank you.
Comment #28
crtlf commentedIs there any way to make it work for Drupal 8.x ?
Comment #29
nachosalvador commentedHello #28
Hello,
I solved filter by current domain in Drupal 8 using this way:
I hope it can help you.
Comment #30
init90Hi, guys. I try to use the solution with Elasticsearch backend, but during reindex I have got next errors:
Maybe someone have ideas how to fix the problem?
Comment #31
init90To fix my problem I have stored domain ids as text. Looks like it's not optimal solution but it works.
Comment #32
flabel commented@#29
If you use this solution remember to set domain access field type to full_text.