Setting a field search variable after main entries variable changes values Kind of hard to explain but here's an example:

{{entries.all()|length}} {# outputs 88 #}

{% set hasTopic = entries.search('dataTable_topic:*').all() %}
{{entries|length}} {# outputs 7 #}


How can I keep entries the same below the search variable.
This is because of the way Element queries are in Craft 3.

In Craft 2, each time you called a setter method (search() here) it would clone your ElementCriteriaModel, use that value on the clone and return the cloned object leaving the original alone.

In Craft 3, when you call a setter method, it gets set on the current element query.

So if I understood correctly, you should use clone (docs):

{% set entries = craft.entries().section('yourSection') %}
{{entries.all()|length}}

{% set hasTopic = clone(entries).search('dataTable_topic:*').all() %}
{{entries|length}} | {{ hasTopic|length }}