Blog, search and node records doesn't filtered with language switcher. It avoids duplicate entries on pages. I made patch for blog and node modules, but search still have duplicates.

CommentFileSizeAuthor
#42 _filtering_D6.patch14.91 KBAndrew Answer
#42 _settings_php.txt514 bytesAndrew Answer
#39 _settings_php.txt514 bytesAndrew Answer
#39 _filtering_D6.patch14.71 KBAndrew Answer
#40 _filtering_D6.patch14.71 KBAndrew Answer
#40 _settings_php.txt514 bytesAndrew Answer
#26 blog_module_filtering_D6.patch1.06 KBAndrew Answer
#26 blog_pages_inc_filtering_D6.patch3.53 KBAndrew Answer
#26 node_module_filtering_D6.patch1.39 KBAndrew Answer
#26 search_pages_inc_filtering_D6.patch568 bytesAndrew Answer
#26 search-results_tpl_php_filtering_D6.patch397 bytesAndrew Answer
#26 tracker_pages_inc_filtering_D6.patch2.68 KBAndrew Answer
#35 bootstrap_inc_filtering_D6.patch695 bytesAndrew Answer
#35 robots_txt_filtering_D6.patch570 bytesAndrew Answer
#35 filtering_D6.patch15.59 KBAndrew Answer
#34 blog_module_filtering_D6.patch1.06 KBAndrew Answer
#34 blog_pages_inc_filtering_D6.patch3.54 KBAndrew Answer
#34 locale_module_filtering_D6.patch1.85 KBAndrew Answer
#34 node_module_filtering_D6.patch1.4 KBAndrew Answer
#34 search_pages_inc_filtering_D6.patch573 bytesAndrew Answer
#34 search-results_tpl_php_filtering_D6.patch402 bytesAndrew Answer
#34 tracker_pages_inc_filtering_D6.patch2.68 KBAndrew Answer
#34 translation_module_filtering_D6.patch819 bytesAndrew Answer
#34 filtering_D6.patch13.98 KBAndrew Answer
#31 filtering.patch12.1 KBAndrew Answer
#29 filtering.patch12.13 KBAndrew Answer
#27 blog_module_filtering.patch1.06 KBAndrew Answer
#27 blog_pages_inc_filtering.patch3.53 KBAndrew Answer
#27 node_module_filtering.patch1.39 KBAndrew Answer
#27 search_pages_inc_filtering.patch568 bytesAndrew Answer
#27 search-results_tpl_php_filtering.patch397 bytesAndrew Answer
#27 tracker_pages_inc_filtering.patch2.68 KBAndrew Answer
#21 blog.module.patch458 bytesAndrew Answer
#21 blog.pages_.inc_.patch2.08 KBAndrew Answer
#21 node.module.patch505 bytesAndrew Answer
#21 search-result.tpl_.php_.patch60 bytesAndrew Answer
#21 tracker.pages_.inc_.patch1.57 KBAndrew Answer
#21 multilang.sh_.txt308 bytesAndrew Answer
#22 patches.tgz1.14 KBAndrew Answer
#20 search-result.tpl_.php_.patch60 bytesAndrew Answer
#19 blog.module.patch458 bytesAndrew Answer
#19 blog.pages_.inc_.patch2.08 KBAndrew Answer
#19 node.module.patch505 bytesAndrew Answer
#13 blog.module.patch458 bytesAndrew Answer
#13 blog.pages_.inc_.patch2.08 KBAndrew Answer
#13 node.module.patch505 bytesAndrew Answer
#5 node.module.patch504 bytesAndrew Answer
#5 blog.module.patch458 bytesAndrew Answer
#5 blog.pages_.inc_.patch2.08 KBAndrew Answer
#3 blog.pages_.inc_.patch2.08 KBAndrew Answer
node.module.patch506 bytesAndrew Answer
blog.pages_.inc_.patch487 bytesAndrew Answer
blog.module.patch427 bytesAndrew Answer
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Roxpace’s picture

Thanks, this is most welcome, strange that not many else has reflected this huge problem,

Jose Reyero’s picture

Title: Records doesn't filtered with language switcher » Add language filter to search form
Category: bug » feature
Status: Needs review » Needs work

These patches work. However, by applying them I'm sure some other feature request like 'Seach in all languages' will pop up, which btw makes a lot of sense, as searches are text based thus search terms have some language by themselves.

So about the search form, I think we should try to add a language field to the search form that defaults to current language and that would be it.

Feedback/suggestions welcomed, and patches more welcomed yet :-)

Andrew Answer’s picture

FileSize
2.08 KB

Added new version patch for blogs. Now 1) blogs with urls like blog\1 filtered too 2) RSS feeds language-specific too.

asw20pilot’s picture

Thanks a lot for the node patch! I applied it and it seems to work fine.
I wonder how a bug like that (duplicate stories on the front page!) was allowed to pass through testing of drupal version 6.

Andrew Answer’s picture

FileSize
2.08 KB
458 bytes
504 bytes

Drupal 6.2 is out, so this is a new patches for core modules.

Roxpace’s picture

Are these patches working with D6.3 and is it now a part of the beta release of this module ?

qbicdesign’s picture

i have this patch installed in 6.3 and seems ok so far
in fact i just grabbed my patched files from 6.2 and overwrote the 6.3 original files - probably not recommended but seems to work ok.
I only did that cos i hate the drupal's patching method, which is not exactly simple.

Roxpace’s picture

Yes, but what can you do when the Drupal core development team doesn't solve things that is important fast enough even with contributions from the community, a lot of patches are waiting to get added and never does.

nedjo’s picture

Yes, this should be done as a new 'language' search operand, but this is very difficult to do.

The issue is that it's not enough to add checkboxes to the search form and then read them in and turn that into hook_db_rewrite_sql() clauses. Full core search support requires that all search criteria be treated as operands that can be contained in the url of the search. So in this case we would need e.g. "language:en,fr" in the search string.

See #69595: Node search operands should be extsnsible and moved out of node.module for some of the problems involved in trying to add custom search operands to Drupal's core search. If we want to keep operand support, the approaches open to us are (in the order of what seems best):

* Solve #69595: Node search operands should be extsnsible and moved out of node.module
* Hard-code a new "language" operand into core's search, alongside the existing hard-coded operands
* Write an API contrib module for handling custom search operands
* Add a ton of code to i18n to handle custom search operands.

If we limit ourselves to what would amount to a partially broken search, we could just:

* Add checkboxes and check for the $_REQUEST and rewrite search sql without adding operand support.

Jose Reyero’s picture

Merging the thread in #316147: Multilingual Search for Multilanguage site
We should also add some content selection options specific for search if we find the way to add some fields to the search form.

hass’s picture

+

azoho’s picture

subscribing

Andrew Answer’s picture

FileSize
505 bytes
2.08 KB
458 bytes

Drupal 6.11 is out, so this is a new patches for core modules. Seems like nobody build multilingual sites without huge 18n module. I prefer little patch, and think what this language filter should be even integrated into core, because this is not break any functionality, only apply multilanguage feature in more logical way.

Andrew Answer’s picture

Status: Needs work » Needs review
hass’s picture

Please provide unified patches, http://drupal.org/patch/create

Jose Reyero’s picture

Status: Needs review » Active

Again, we are not including core patches as part of i18n module. So this is still open till we find a module-only approach that needs no core patching.

boran’s picture

But this patch does not change the search form, or the resulting listing?
The idea is to allow search for items in the current language, or all languages?

eloiguell’s picture

In search form I had filter the duplicates in other languages when $url contents "node/" in module/search/search-result.tpl.php
It works for me.

<?php
 if(!ereg('node/',$url))
 {
?>
<dt class="title">
  <a href="<?php print $url; ?>"><?php print $title; ?></a>
</dt>
<dd>
  <?php if ($snippet) : ?>
    <p class="search-snippet"><?php print $snippet; ?></p>
  <?php endif; ?>
  <?php if ($info) : ?>
  <p class="search-info"><?php print $info; ?></p>
  <?php endif; ?>
</dd>
<?
 }
?>
Andrew Answer’s picture

FileSize
505 bytes
2.08 KB
458 bytes

Of course patch Drupal core is not very "right" solution, but it simple and works for me for years ) I fix only several SQL queries and get all what I need.
So, version 6.16 patched too.

Patching is easy under Linux, use "patch [file] [file].patch" command.

User eloiguell provide nice filter for search; but it's work ONLY if "pathauto" module set, so other-language results will have node/ URLs, but current-language results will be with content/ URLs, and we can use that filter. Other case, filter clear all search results (I think, not test without pathauto module).

I made patch from his code.

Andrew Answer’s picture

Here patch for search (use pathauto!).

Andrew Answer’s picture

Drupal 6.19 is out, so I update my site & patches too. One additional patch for "tracker" module added; it filter recent posts by language. So, when you apply the patches, you get two-language site with ability to translate some blog posts, site pages, book pages and other content, but FILTERED by language switcher anywhere: in tracker, search, blog, blog list and node list. Note: you should use "pathauto" module to enable search filtering, elsewhere DO NOT PATCH search.

You can see patched version in action at http://dev.answe.ru as RU and http://andrew.answer.name as EN site.

Andrew Answer’s picture

I pack patches to archive to avoid renaming.

Andrew Answer’s picture

Fabianx’s picture

@Andrew Answer:

That is nice, but could you use unified diffs? (diff -u)

They are much easier to read ...

Andrew Answer’s picture

Title: Add language filter to search form » Add language filter to Drupal core
Project: Internationalization » Drupal core
Version: 6.x-1.x-dev » 6.x-dev
Component: Code » language system
Status: Active » Needs review
Andrew Answer’s picture

I decide to change issue description, because it now core fork more than only search results filter. By default, locale module + content translation allow good UI to translate nodes and create bilingual sites. But, because any user show nodes on all languages, this waste all functionality. I expect another behavior by default, and without i18n or any other additional module(s).

Here is the set of patches, which (I hope) can be tested automatically. When these patches applied to multilanguage site, it allow to filter blog and node entries, search results, recent posts list, RSS feeds by current site language.

I also need to check how these patches work with disabled content translation, or only with one language, or with 3 and more languages.

And, yes, don't forget to enable pathauto module to filtering search!

Andrew Answer’s picture

Here patches without D6 suffix because I don't know how add patches to test queue. So I test it :)

Status: Needs review » Needs work

The last submitted patch, tracker_pages_inc_filtering.patch, failed testing.

Andrew Answer’s picture

Status: Needs work » Needs review
FileSize
12.13 KB

Hope this way will work.

Status: Needs review » Needs work

The last submitted patch, filtering.patch, failed testing.

Andrew Answer’s picture

Status: Needs work » Needs review
FileSize
12.1 KB

What's wrong? Anyone can help?

Status: Needs review » Needs work

The last submitted patch, filtering.patch, failed testing.

Andrew Answer’s picture

Ouch! As I see here http://drupal.org/node/894166 testbot work ONLY with D7 patches!!!
But WHY don't filter issue patches for testbot by Version field??? It confused me and other developers.

Andrew Answer’s picture

I finally patch Drupal 6.19 core modules to disable link to itself on any page in language switcher. Also, if no translation was provided, no link will be in language switcher. This is behavior I expect from language switcher by default.
I made one patch from CVS and others from Drupal tar.
You can check how it work on http://dev.answe.ru and http://en.answe.ru

Andrew Answer’s picture

Also, here some patches for pathauto-enabled users (human-readable URLs is a MUST for any site). What problem fixed here? When we use aliases for nodes, old URLs leaved in site structure, can be opened and indexed. This cause "duplicate content" SEO bug and confuse users too.
Next functions filter node/ URLs to show 404 page instead, and prevent search engines to index node/ URLs by patching robots.txt. filtering_D6 is a cumulative patch.

plach’s picture

Drupal 6 and 7 are feature frozen. This can only be addressed in D8.

boran’s picture

Status: Needs review » Needs work

I wonder if these patches could be integrated into a distribution like Pressflow (https://launchpad.net/pressflow), where they actually make core changes and ensure these work across drupal updates.?

egon.ojamaa’s picture

Repy to #34 Posted by Andrew Answer on December 7, 2010 at 8:06pm

I made a better fix for this issue.
No core hack.. just a module.
http://drupal.org/node/995500

Andrew Answer’s picture

FileSize
14.71 KB
514 bytes

Find what URL like /node/blog/add cause 404 error. I fix it, and finally remove custom_url_rewrite_inbound from bootstrap.inc. I suggest to include this function into settings.php by hand. Install: patch with easy command "patch -p0 <_filtering_D6.patch" from Drupal root. Uninstall: patch with "patch -p0 -R <_filtering_D6.patch" (of course you shouldn't change affected core modules).

Andrew Answer’s picture

FileSize
514 bytes
14.71 KB

Find what URL like /node/blog/add cause 404 error. I fix it, and finally remove custom_url_rewrite_inbound from bootstrap.inc. I suggest to include this function into settings.php by hand. Patch here.

terotik’s picture

Super!! I spent too long time to find a non-patch solution to this, before giving this a try. Thank you, much appreciated.
One problem: this removes 'active' class from the language list.

Andrew Answer’s picture

FileSize
514 bytes
14.91 KB

Drupal 6.20 is out, so there is a new patch.

nedjo’s picture

Version: 6.x-dev » 8.x-dev

Any such patch would be for Drupal 8.

Andrew Answer’s picture

If this patch for 8.x then it need to be rewritten to support new codebase. Same time this patch fully work for D6.20 and I think what this relation should be leaved. What do you suggest to do for it?

Dret’s picture

Sorry but egon.ojamaa's module ( http://drupal.org/node/995500 ) works very fine in Drupal 6.19 but break translation system in 6.20.

Waiting for an update!

egon.ojamaa’s picture

Fixed my module.. happy using
http://drupal.org/node/995500

Fabianx’s picture

Hi,

This absolute is a needs work.

Sorry @ Andrew Answer: While I see your need for those changes the approach taken to patch core is wrong, because all that you do can be done in a custom module.

Every query you changed has db_rewrite_sql and that for a reason.

So that modules can alter the behavior. So if you want to change all those queries, please use code like this:

  function mymodule_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
    global $language;

    switch ($primary_field) {
      case 'nid':
              // this query deals with node objects
              $return = array();
              if ($primary_table != 'n') {
                $return['join'] = "LEFT JOIN {node} n ON $primary_table.nid = n.nid";
              }
              // FORCE SITE LANGUAGE
              $return['where'] = 'n.language="' . $language->language .  '"';
              return $return;
        break;
    }
  }

This essentially does the same as your code, but without patching.

As for the language switcher:

@Egon: I looked at your module and while your approach is working, you don't need to add a new language switcher block.

You can just implement (to change the language switcher):


function mymodule_translation_link_alter(&$links, $path) {

  global $language;

  foreach($links as $lang => $link) {
    if ($language->language == $lang) {
      // Andrew solution:
      unset($links[$lang]["href"]);
      // Egon solution
      unset($links[$lang]);
    }
  }
}

This can be written even shorter as:


function mymodule_translation_link_alter(&$links, $path) {

  global $language;

  if (isset($links[$language->language]) {
    // Andrew solution:
    unset($links[$language->language]["href"]);

     // Egon solution
     unset($links[$language->language]);
  }
}

I have not yet understood the problem with the tnid - though. So I leave you one item for patching now :-).

I hope this helps solve these issues without having to patch core.

Best Wishes,

Fabian

plach’s picture

klonos’s picture

...coming from #316147: Multilingual Search for Multilanguage site which was closed as a duplicate of this one here.

Can we please have an updated issue summary with status and available patches/solutions for drupal 6, 7 & 8? I am looking for a solution to D7 multilingual site search. Anything available for testing?

sami_20031’s picture

Status: Needs work » Needs review

blog.module.patch queued for re-testing.

foripepe’s picture

In Drupal 7 there isn't hook_db_rewrite_sql() any more. But you can use hook_query_alter().

Example (needs review):

/**
 * Implements hook_query_alter().
 */
function hook_query_alter(QueryAlterableInterface $query) {
  global $language;

  // Rewrite the sql query to exclude languages.
  if ($query->hasTag('node_access') && $query->hasTag('pager')) {
    $tables = $query->getTables();
    foreach ($tables as $table) {
      if ($table['table'] == 'search_index') {
        $query->condition('n.language', $language->language);
      }
    }
  }
}

Status: Needs review » Needs work
Issue tags: -language, -i18n, -multilanguage, -simple, -switcher

The last submitted patch, _filtering_D6.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

I think this is outdated. I have been testing multilingual functionality on Drupal 9 and Drupal 10 for some time for the Bug Smash Initiative. I haven't experienced the problem in the Issue Summary.