Create intelligent search experiences using Infactory queries
Infactory enables you to build powerful, natural language search interfaces that allow users to find information in your data using ordinary questions. Unlike traditional search solutions, Infactory-powered search interfaces can interpret user intent, extract parameters, and return precise, contextual results.
Add search suggestions to help users formulate effective questions:
Copy
Ask AI
function SearchWithSuggestions() { const [query, setQuery] = useState(''); const [suggestions, setSuggestions] = useState([ "What were total sales last month?", "How many customers do we have in California?", "Show me top 10 products by revenue", "What's the average order value by customer segment?", "How many support tickets were opened yesterday?" ]); // Use a suggested question const useQuestion = (question) => { setQuery(question); // Optionally auto-submit the search }; return ( <div className="search-interface"> <form onSubmit={handleSearch} className="search-form"> <input type="text" value={query} onChange={(e) => setQuery(e.target.value)} placeholder="Ask a question about your data..." className="search-input" /> <button type="submit" className="search-button">Search</button> </form> {/* Suggestions */} {!results && !loading && ( <div className="search-suggestions"> <h3>Suggested questions:</h3> <ul className="suggestions-list"> {suggestions.map((suggestion, index) => ( <li key={index}> <button onClick={() => useQuestion(suggestion)} className="suggestion-btn" > {suggestion} </button> </li> ))} </ul> </div> )} {/* Results rendered here */} </div> );}
Improve the presentation of search results with visualizations and summaries:
Copy
Ask AI
function EnhancedResults({ results }) { if (!results || !results.data) return null; // Generate a natural language summary of the results function generateSummary() { const data = results.data; if (!Array.isArray(data)) { return `The result is ${JSON.stringify(data)}.`; } if (data.length === 0) { return "No data was found for your query."; } if (data.length === 1) { return `Found 1 result: ${JSON.stringify(data[0])}.`; } return `Found ${data.length} results. Here are the details:`; } // Determine if data can be visualized function canVisualize() { const data = results.data; return Array.isArray(data) && data.length > 1 && data.length <= 20 && Object.keys(data[0]).some(key => typeof data[0][key] === 'number'); } // Simple visualization for numeric data function renderVisualization() { if (!canVisualize()) return null; const data = results.data; const keys = Object.keys(data[0]); // Find a likely category field and numeric field const categoryKey = keys.find(key => typeof data[0][key] === 'string') || keys[0]; const numberKey = keys.find(key => typeof data[0][key] === 'number'); if (!numberKey) return null; // In a real implementation, you would use a charting library like Chart.js return ( <div className="visualization"> <h3>Data Visualization</h3> <div className="chart-placeholder"> {/* In a real app, replace with actual chart component */} <div className="mock-bar-chart"> {data.map((item, index) => ( <div key={index} className="mock-bar-item"> <div className="mock-bar-label">{item[categoryKey]}</div> <div className="mock-bar" style={{ width: `${Math.min(100, (item[numberKey] / Math.max(...data.map(d => d[numberKey]))) * 100)}%` }} ></div> <div className="mock-bar-value">{item[numberKey]}</div> </div> ))} </div> </div> </div> ); } return ( <div className="enhanced-results"> <div className="results-summary"> <h3>Summary</h3> <p>{generateSummary()}</p> </div> {renderVisualization()} <div className="detailed-results"> <h3>Detailed Results</h3> {/* Render the full results table or other appropriate format */} </div> <div className="results-metadata"> <h4>Query Information</h4> <ul> <li><strong>Query Used:</strong> {results.query_used}</li> <li><strong>Execution Time:</strong> {results.execution_time_ms}ms</li> <li><strong>Parameters:</strong> {JSON.stringify(results.parameters || {})}</li> </ul> </div> </div> );}
Suggest related searches based on current results:
Copy
Ask AI
function SearchWithRelatedQuestions({ results }) { // Generate related questions based on current results function generateRelatedQuestions() { if (!results || !results.data) return []; const relatedQuestions = []; // If we have query parameters, suggest alternative values if (results.parameters) { Object.entries(results.parameters).forEach(([key, value]) => { if (key === 'timeframe' && value) { // Suggest different timeframes if (value === 'last_month') { relatedQuestions.push(`Same question for last week`); relatedQuestions.push(`Same question for last quarter`); } else if (value === 'last_week') { relatedQuestions.push(`Same question for last month`); relatedQuestions.push(`Same question for yesterday`); } } if (key === 'limit' && value) { // Suggest different limits relatedQuestions.push(`Show me top ${value * 2} results`); } if (key === 'category' && value) { // Suggest comparing with other categories relatedQuestions.push(`Compare with other categories`); } }); } // Suggest trending or deeper analysis relatedQuestions.push(`Show trend over time`); relatedQuestions.push(`What's driving these results?`); return relatedQuestions; } const relatedQuestions = generateRelatedQuestions(); if (relatedQuestions.length === 0) return null; return ( <div className="related-searches"> <h3>Related Questions</h3> <ul className="related-questions-list"> {relatedQuestions.map((question, index) => ( <li key={index}> <button onClick={() => onSelectRelated(question)} className="related-question-btn"> {question} </button> </li> ))} </ul> </div> );}