meteor-tabular icon indicating copy to clipboard operation
meteor-tabular copied to clipboard

Combine smart search with $and matching

Open foamrider opened this issue 9 years ago • 7 comments

Hi

As mention in issue #239:

Example log table:

Date  Level  Message
2016-01-01 warning something happened
2016-01-02  info  just some info

Searching for all warnings in 2016, typing: 2016 warning With smart search on, it will split the search term, search all columns using $or. The result is both lines, since both lines have 2016 OR warning in one of their fields. With smart search off, it will search for 2016 warning in a single column, meaning it will not return any result.

The desired option is, as @aldeed wrote in #239: "it would split and do $or within a single document property, but all terms would have to be present somewhere in the same document."

foamrider avatar Jan 09 '16 13:01 foamrider

+1

crapthings avatar Jan 17 '16 17:01 crapthings

+1 @drtomasso any solution or best workaround for "$AND" search ?

ouya99 avatar Feb 25 '16 18:02 ouya99

Could be something in this direction:

---
 client/pubSelector.js | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/client/pubSelector.js b/client/pubSelector.js
index 6a4cf9e..3e88cc2 100644
--- a/client/pubSelector.js
+++ b/client/pubSelector.js
@@ -53,6 +53,8 @@ getPubSelector = function getPubSelector(
     _.each(searchValue, function (searchTerm) {
       var m1 = {}, m2 = {};

+      searches[searchTerm] = searches[searchTerm] ? searches[searchTerm] : [];
+
       // String search
       m1[field.data] = { $regex: searchTerm };

@@ -61,13 +63,13 @@ getPubSelector = function getPubSelector(
         m1[field.data].$options = "i";
       }

-      searches.push(m1);
+      searches[searchTerm].push(m1);

       // Number search
       var numSearchString = Number(searchTerm);
       if (!isNaN(numSearchString)) {
         m2[field.data] = numSearchString;
-        searches.push(m2);
+        searches[searchTerm].push(m2);
       }
     });
   });
@@ -76,7 +78,7 @@ getPubSelector = function getPubSelector(
   if (selector) {
     result = {$and: [selector, {$or: searches}]};
   } else {
-    result = {$or: searches};
+    result = {$and: [{$or: searches['First']}, {$or: searches['Second']}]};
   }

   return result;
--

This makes an array of each keyword, but at the end it should be a loop, which I couldn't figure out at the moment, for each keyword.

The result is: $and requires a hit of every keyword, but each keyword(array) is separated with $or making it match any field with that keyword.

In this example, it only works if I search for "First Second", but maybe some of you get the idea and could take this thing furtherer.

foamrider avatar Mar 22 '16 22:03 foamrider

+1 for and filter

stinghz avatar Apr 27 '16 21:04 stinghz

I'm trying to implement this too? Any idea on how to do a global extend or something until this is committed?

anthonymanzo avatar Apr 28 '17 19:04 anthonymanzo

This works perfectly with Reactive Table (https://atmospherejs.com/aslagle/reactive-table) but I'd like to keep using aldeed:tabular for it's other great features. I would +1 this request too.

malsher avatar Jun 22 '17 00:06 malsher

Hi, does anyone have a solution or hack to get this working yet?

anthonymanzo avatar Mar 09 '18 18:03 anthonymanzo