Keyword Search Explained
Content: Keyword Search Explained
User Intent
"How does keyword/full-text search work in Graphlit?"
Operation
SDK Method:
queryContents()withsearchType: SearchKeywordGraphQL:
queryContentsqueryCommon Use Cases: Exact phrase matching, names, IDs, codes, fast lookups
How Keyword Search Works
Keyword search uses traditional full-text indexing with token-based matching. It's fast, precise, and ideal for exact phrases, names, and identifiers.
TypeScript (Canonical)
import { Graphlit } from 'graphlit-client';
import { ContentTypes, SearchTypes } from 'graphlit-client/dist/generated/graphql-types';
const graphlit = new Graphlit();
// Pure keyword search
const results = await graphlit.queryContents({
search: "Project Alpha status report",
searchType: SearchTypes.Keyword,
limit: 10
});
console.log(`Found ${results.contents.results.length} keyword matches`);
results.contents.results.forEach((content, index) => {
console.log(`\n${index + 1}. ${content.name}`);
console.log(` Relevance: ${content.relevance}`);
console.log(` Type: ${content.type}`);
});
// Search for exact phrase
const exactPhrase = await graphlit.queryContents({
search: '"quarterly earnings report"', // Quotes = exact phrase
searchType: SearchTypes.Keyword
});
// Search for ID or code
const byId = await graphlit.queryContents({
search: "PROJ-1234",
searchType: SearchTypes.Keyword
});
// Search for email address
const byEmail = await graphlit.queryContents({
search: "[email protected]",
searchType: SearchTypes.Keyword
});
// Search for specific name
const byName = await graphlit.queryContents({
search: "Kirk Marple",
searchType: SearchTypes.Keyword
});Keyword Search Features
1. Token-Based Matching
2. Exact Phrase Search
3. Boolean Operators (if supported)
4. Case-Insensitive
5. Stemming
When to Use Keyword Search
** Good For**:
Exact phrases ("Project Alpha v2.3")
Names ("Kirk Marple", "Graphlit")
Email addresses ("[email protected]")
IDs and codes ("PROJ-1234", "ORDER-5678")
URLs ("https://graphlit.com")
Specific terminology
Fast lookups
** Not Good For**:
Conceptual queries (use vector search)
Synonyms and paraphrases (use vector search)
Semantic similarity (use vector search)
"Find similar" queries (use vector search)
Performance Characteristics
BM25 Ranking
Algorithm: BM25 (Best Matching 25)
Standard information retrieval algorithm
Considers term frequency and document length
More sophisticated than simple TF-IDF
Relevance Score:
Keyword search (snake_case)
results = await graphlit.client.query_contents( search="Project Alpha", search_type=SearchTypes.Keyword, limit=10 )
for content in results.contents.results: print(f"{content.name} - Relevance: {content.relevance}")
Exact phrase
exact = await graphlit.client.query_contents( search='"quarterly report"', search_type=SearchTypes.Keyword )
Search by ID
by_id = await graphlit.client.query_contents( search="PROJ-1234", search_type=SearchTypes.Keyword )
Developer Hints
Exact Phrase vs Token Search
Special Characters
Combining with Filters
Variations
1. Basic Keyword Search
2. Exact Phrase Search
3. Search by ID
4. Search by Email
5. Search with Content Type Filter
6. Search in Specific Collection
7. Multi-Term Search
Common Issues & Solutions
Issue: No results for partial words Solution: Keyword search doesn't do prefix matching by default
Issue: Too many results Solution: Use exact phrase or add filters
Issue: Want semantic + keyword Solution: Use hybrid search (combines both)
Issue: Special characters breaking search Solution: Use quotes for exact phrase
Production Example
Last updated
Was this helpful?