Skip to content

Commit

Permalink
Improve the query string of fetching linked nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
yjcyxky committed Mar 14, 2024
1 parent 4fba06b commit 847ed94
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
22 changes: 20 additions & 2 deletions src/model/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ use crate::model::kge::{
EmbeddingMetadata, DEFAULT_MODEL_NAME,
};
use crate::model::util::{match_color, title_case, ValidationError};
use crate::query_builder::sql_builder::ComposeQuery;
use crate::query_builder::sql_builder::{ComposeQuery, ComposeQueryItem, QueryItem, Value};
use lazy_static::lazy_static;
use log::{debug, error};
use neo4rs::{Node as NeoNode, Relation as NeoRelation};
use poem_openapi::Object;
use polars::lazy::dsl::Operator;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -1871,10 +1872,27 @@ impl Graph {
"biomedgps_relation".to_string()
};

let score_condition = QueryItem::new("score".to_string(), Value::Null, "is not".to_string());
let query = match query {
Some(ComposeQuery::QueryItem(item)) => {
let mut query = ComposeQueryItem::new("and");
query.add_item(ComposeQuery::QueryItem(item.clone()));
query.add_item(ComposeQuery::QueryItem(score_condition));
Some(ComposeQuery::ComposeQueryItem(query))
}
Some(ComposeQuery::ComposeQueryItem(item)) => {
let mut query = ComposeQueryItem::new("and");
query.add_item(ComposeQuery::ComposeQueryItem(item.clone()));
query.add_item(ComposeQuery::QueryItem(score_condition));
Some(ComposeQuery::ComposeQueryItem(query))
}
None => Some(ComposeQuery::QueryItem(score_condition)),
};

match RecordResponse::<Relation>::get_records(
pool,
table_name.as_str(),
query,
&query,
page,
page_size,
order_by,
Expand Down
4 changes: 2 additions & 2 deletions src/query_builder/sql_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct QueryItem {
impl QueryItem {
pub fn new(field: String, value: Value, operator: String) -> Self {
let allowed_operators = vec![
"=", "!=", "like", "not like", "ilike", "in", "not in", "<>", "<", ">", "<=", ">=",
"=", "!=", "like", "not like", "ilike", "in", "not in", "<>", "<", ">", "<=", ">=", "is", "is not"
];
if !allowed_operators.contains(&operator.as_str()) {
panic!("Invalid operator: {}", operator);
Expand Down Expand Up @@ -56,7 +56,7 @@ impl QueryItem {
}
}
Value::Null => {
if !vec!["=", "!="].contains(&operator.as_str()) {
if !vec!["is", "is not"].contains(&operator.as_str()) {
panic!("Invalid operator: {}", operator);
}
}
Expand Down
6 changes: 6 additions & 0 deletions studio/src/pages/ModelConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ const ModelConfig: React.FC = (props) => {
form.resetFields();
setParams({});
setGraphData({ nodes: [], edges: [] });
cleanTable()
}

const cleanTable = () => {
setEdgeDataSources([]);
setNodeDataSources([]);
}
Expand Down Expand Up @@ -803,6 +807,8 @@ const ModelConfig: React.FC = (props) => {

// Placeholder function for submitting the form
const handleSubmit = () => {
// We need to clean the table before we submit the form, otherwise, the table will show the previous result.
cleanTable();
setLoading(true);
form
.validateFields()
Expand Down

0 comments on commit 847ed94

Please sign in to comment.