Nhogs / popoto

Visual query builder for Neo4j graph database
http://popotojs.com
GNU General Public License v3.0
498 stars 70 forks source link

using filterNodeValueQuery #59

Closed sag3ll0 closed 4 years ago

sag3ll0 commented 4 years ago

Hello and thanks for great project. How i must use filterNodeValueQuery function ? I need filter for node and want use statement "Profile.name CONTAINS 'leg'" i do next

"filterNodeValueQuery": function (node, initialQuery) {
  initialQuery.whereElements.push("Profile.name CONTAINS 'leg'");
  return initialQuery;
},

but its not work, i see that initialQuery.statement without my where. and in wiki i dont find information about it.

Popotojs commented 4 years ago

Actually only the statement parameter returned in the function is used for generated queries.

So you can either update directly initialQuery.statement with anythig you want but in this case you'll have to do a string replacement, to keep to other parts of the query, which is not easy to do.

Or regenerate the full statement with the updated whereElements like this:

"filterNodeValueQuery": function (node, initialQuery) {
  initialQuery.whereElements.push("Profile.name CONTAINS 'leg'");
  initialQuery.statement = "MATCH " + queryMatchElements.join(", ") + ((queryWhereElements.length > 0) ? " WHERE " + queryWhereElements.join(" AND ") : "") + " RETURN " + queryReturnElements.join(", ") + " " + queryEndElements.join(" ");

  return initialQuery;
},

This is not a very clean solution, it was introduced to allow this kind of customization. You'll probably have to update filterNodeCountQuery and filterNodeRelationQuery accordingly to avoid inconsistent data.

Another possibility is to use predefined constraints: https://github.com/Nhogs/popoto/wiki/Node-configuration#get-predefined-constraints

Or use a prefilter query using popoto.query.prefilter which is applied everywhere in query execution assuming Profile if the root of your query you can do something like this:

popoto.query.prefilter = "MATCH (profile:Profile) WHERE profile.name CONTAINS 'leg' WITH profile ";
sag3ll0 commented 4 years ago

I understand and do next declare global var filterClause = []; and wrote

        "getPredefinedConstraints": () => {
          return this.filterClause;
        },

on button click (for example) i do next:

  filterName(e) {
    this.filterClause = ["profile.name CONTAINS 'leg'"];
    popoto.tools.reset();
  }

its will reset all graph and show profiles according contains. If don't raise popoto.tools.reset(); and click on profile node it will return needed rocords, but count is not change (for example 500 instead 10).