DiamondDAO / chainverse-os

Tools for building collective knowledge applications
MIT License
0 stars 0 forks source link

Return user search results in a table #1

Closed liminal-dog closed 2 years ago

liminal-dog commented 2 years ago

Summary

Requirements

Wireframes

clemp commented 2 years ago

Queries to set up Neo4j fulltext search

Run on the Neo4j database to create index

CREATE FULLTEXT INDEX chainversePortalSearchIndex 
FOR (n:Note | Partnership | Entity | Proposal) 
ON EACH [n.text, n.name, n.body]

GraphQL queries to return results Query

query FuzzyChainversePortalSearch($searchString: String) {
  fuzzyChainversePortalSearch(searchString: $searchString) {
    ...on Note {
      __typename
      uuid
      text
    }
    ...on Partnership {
      __typename
      uuid
      text
    }
    ...on Response {
      __typename      
      uuid
      text
    }
    ...on Proposal {
      __typename
      id
      body
      entity {
        uuid
        name
      }
    }
  }
}

Variable

{
  "searchString": "Multicoin"
}

Type definition for this FuzzyChainversePortalSearch query included in this commit on the chainverse-frontend repo: https://github.com/DiamondDAO/chainverse-frontend/commit/5a45dcc55e5ab3a6133eef2f818a57dd7a0d5bab

And a Loom video of this returning results: https://www.loom.com/share/b53921cd951d4692a617d99aab41ac8f

liminal-dog commented 2 years ago

I am working on requirements for table search results now. One comment on the query constructed above -- I don't think we should return Result blocks as results, those should be internal only until we remove them.

clemp commented 2 years ago

Based on feedback during conversation with @liminal-dog yesterday I made updates to the search query and results.

Returning Entity nodes only

Path Expander Search

Modified GraphQL Type Definition

union SearchNodes = Note | Entity | Proposal

  type Query {
    fuzzyChainversePortalSearch(searchString: String, skip: Int, limit: Int): [SearchNodes] @cypher(
      statement: """
        CALL db.index.fulltext.queryNodes(
          'chainversePortalSearchIndex', $searchString+'~')
        YIELD node as searchResult, score 
        WHERE score > 0.9
        WITH searchResult
        CALL apoc.path.subgraphNodes(searchResult, {
          relationshipFilter: 'REFERENCES|HAS_PROPOSAL',
          labelFilter: '>Entity',
            minLevel: 1,
            maxLevel: 2
        })
        YIELD node as r
        RETURN r
        SKIP $skip LIMIT $limit
      """
    )
  }

type Entity {
    """
    TODO: Should this be restricted
    """
    uuid: ID! @id(autogenerate: true)
    name: String @unique #under assumption name for entities are unique
    id: String @unique
    minScore: Float
    network: Float
    onlyMembers: String
    symbol: String
    address: String @unique
    avatar: String
    about: String
    proposals: [Proposal] @relationship(type: "HAS_PROPOSAL", direction: OUT)
    notes: [Note] @relationship(type: "REFERENCES", direction: IN)
  }

Search Result Sample

Now this query

query FuzzyChainversePortalSearch($searchString: String, $skip: Int, $limit: Int) {
  fuzzyChainversePortalSearch(searchString: $searchString, skip: $skip, limit: $limit) {
    ... on Entity {
      uuid
      name
      notesAggregate {
        count
      }
      proposalsAggregate {
        count
      }
    }
  }
}

with this variable input

{
  "searchString": "investor",
  "skip": 0,
  "limit": 10
}

Produces a JSON structure like this

{
  "data": {
    "fuzzyChainversePortalSearch": [
      {
        "uuid": "1dfe665e-1e2e-4be7-8fb9-430bd36e40e0",
        "name": "Actor DAO",
        "notesAggregate": {
          "count": 0
        },
        "proposalsAggregate": {
          "count": 61
        }
      },
      {
        "uuid": "44126fbf-840f-44dc-80c5-c8d3755fb80f",
        "name": "PancakeSwap",
        "notesAggregate": {
          "count": 0
        },
        "proposalsAggregate": {
          "count": 587
        }
      },
      {
        "uuid": "dd4b09ef-cb03-4fec-add0-2b7ee247bd0c",
        "name": "CafeSwap.Finance",
        "notesAggregate": {
          "count": 0
        },
        "proposalsAggregate": {
          "count": 21
        }
      },

Notes

liminal-dog commented 2 years ago

We have a similar issue in Chainverse Portal should we close this ticket?

liminal-dog commented 2 years ago

moved to chainverse portal