What is the current best way to exclude some nodes based on their nid? The only information i could find was this #1361072: Using SOLR - Exclude some results based on nids. Is this approach still the best solution?

Also i tried to include the nid in the indexed fields, but wasnt able to use them as a filter value in my search result view.

Thank you very much!

Comments

gmclelland’s picture

With 7.x-1.5 release you can add a contextual filter to the view - nid. WHEN THE FILTER VALUE IS NOT AVAILABLE - Provide a default value - Content Id from url. Then choose "More" at the bottom and choose "exclude."

I use that when I want to exclude the current node from being displayed in related views on the page. I'm not sure if that is your use case.

Hope that helps

drunken monkey’s picture

Also i tried to include the nid in the indexed fields, but wasnt able to use them as a filter value in my search result view.

I don't know how that could happen. You checked "Indexed" for the "Node ID" field and then, when editing a view for that index, you don't get an "Indexed Node: Node ID" filter (and contextual filter)? Have you tried clearing the cache after changing the field settings?
Please explain your steps and what happened.

For excluding certain nodes, you can of course just use "is not" filters on the node ID – or follow gmclelland's advice, if you need these nodes to be dynamic.

Jason Dean’s picture

I had exactly the same requirement. After adding Node ID field for indexing and rebuilding the index, Views didn't offer it as a filter.

Thanks to #2, I remembered to clear cache and there it was :) Thanks!

drunken monkey’s picture

Title: Exclude nodes based on nid » Fix stale Views cache when indexed fields change
Version: 7.x-1.4 » 7.x-1.x-dev
Category: support » bug
Status: Active » Needs review
StatusFileSize
new975 bytes

Actually, you shouldn't have to manually clear the cache, it seems that's an oversight in the code.

With the attached patch, this should now work properly and manually clearing the cache should no longer be necessary.
Please test!

drunken monkey’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.