001/** 002 * Copyright (c) 2025-2026, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.gnu.org/licenses/lgpl-3.0.txt 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package dev.tinyflow.core.node; 017 018import com.agentsflex.core.chain.Chain; 019import com.agentsflex.core.chain.node.BaseNode; 020import com.agentsflex.core.document.Document; 021import com.agentsflex.core.util.Maps; 022import dev.tinyflow.core.searchengine.SearchEngine; 023 024import java.util.List; 025import java.util.Map; 026 027public class SearchEngineNode extends BaseNode { 028 029 private SearchEngine searchEngine; 030 private int queryCount; 031 032 public SearchEngine getSearchEngine() { 033 return searchEngine; 034 } 035 036 public void setSearchEngine(SearchEngine searchEngine) { 037 this.searchEngine = searchEngine; 038 } 039 040 public int getQueryCount() { 041 return queryCount; 042 } 043 044 public void setQueryCount(int queryCount) { 045 this.queryCount = queryCount; 046 } 047 048 @Override 049 protected Map<String, Object> execute(Chain chain) { 050 Map<String, Object> argsMap = getParameters(chain); 051 052 String query = (String) argsMap.get("query"); 053 List<Document> result = searchEngine.search(query, 10); 054 055 return Maps.of("documents", result); 056 } 057 058 @Override 059 public String toString() { 060 return "SearchEngineNode{" + 061 "searchEngine=" + searchEngine + 062 ", queryCount=" + queryCount + 063 ", description='" + description + '\'' + 064 ", parameters=" + parameters + 065 ", outputDefs=" + outputDefs + 066 ", id='" + id + '\'' + 067 ", name='" + name + '\'' + 068 ", async=" + async + 069 ", inwardEdges=" + inwardEdges + 070 ", outwardEdges=" + outwardEdges + 071 ", condition=" + condition + 072 ", memory=" + memory + 073 ", nodeStatus=" + nodeStatus + 074 '}'; 075 } 076}