Skip to content

Commit

Permalink
Merge pull request #78 from oramasearch/feature/orm-2152
Browse files Browse the repository at this point in the history
Feature/orm 2152 - UI-components: supporting multi-index search
  • Loading branch information
rjborba authored Jan 27, 2025
2 parents 34ef1ac + a7e6b88 commit eeae2f0
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 35 deletions.
20 changes: 20 additions & 0 deletions apps/storybook/stories/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,24 @@ demoIndexes.oramaWithCustomIcons = {
},
}

demoIndexes.multipleIndexes = {
open: true,
resultMap: {
description: (doc) => {
return doc.description || doc.content
},
section: (doc) => {
return doc.genres?.[0] || doc.section
},
},
index: [
{
api_key: 'hdRgZI3j8Z38pImkqYWbAw7SwnrJk8Nt',
endpoint: 'https://cloud.orama.run/v1/indexes/videogames-nb9lk0',
},
{ api_key: 'LerNlbp6379jVKaPs4wt2nZT4MJZbU1J', endpoint: 'https://cloud.orama.run/v1/indexes/docs-orama-b3f5xd' },
],
suggestions: ['How to get started?'],
}

export default demoIndexes
8 changes: 4 additions & 4 deletions packages/ui-stencil/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export namespace Components {
"chatMarkdownLinkTarget"?: ChatMarkdownLinkTarget;
"chatMarkdownLinkTitle"?: ChatMarkdownLinkTitle;
"clientInstance"?: OramaClient | AnyOrama;
"index"?: CloudIndexConfig;
"index"?: CloudIndexConfig | CloudIndexConfig[];
"linksRel"?: string;
"linksTarget"?: string;
"placeholder"?: string;
Expand Down Expand Up @@ -188,7 +188,7 @@ export namespace Components {
/**
* Orama Index configuration note: It will be overrided by clientInstance property
*/
"index"?: CloudIndexConfig;
"index"?: CloudIndexConfig | CloudIndexConfig[];
/**
* This component can behave either as Modal or a Embed component. For Modal, a new absolute panel will be displayed on top. For Embed, Orama Search Box will be displayed as a inline component.
*/
Expand Down Expand Up @@ -694,7 +694,7 @@ declare namespace LocalJSX {
"chatMarkdownLinkTarget"?: ChatMarkdownLinkTarget;
"chatMarkdownLinkTitle"?: ChatMarkdownLinkTitle;
"clientInstance"?: OramaClient | AnyOrama;
"index"?: CloudIndexConfig;
"index"?: CloudIndexConfig | CloudIndexConfig[];
"linksRel"?: string;
"linksTarget"?: string;
/**
Expand Down Expand Up @@ -834,7 +834,7 @@ declare namespace LocalJSX {
/**
* Orama Index configuration note: It will be overrided by clientInstance property
*/
"index"?: CloudIndexConfig;
"index"?: CloudIndexConfig | CloudIndexConfig[];
/**
* This component can behave either as Modal or a Embed component. For Modal, a new absolute panel will be displayed on top. For Embed, Orama Search Box will be displayed as a inline component.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Component, Host, h, Prop, Watch, State, Element, type EventEmitter, Event } from '@stencil/core'
import { chatContext } from '@/context/chatContext'
import { ChatService } from '@/services/ChatService'
import { generateRandomID, initOramaClient, validateCloudIndexConfig } from '@/utils/utils'
import {
generateRandomID,
initOramaClient,
validateCloudIndexConfig as validateCloudIndexOrInstance,
} from '@/utils/utils'
import type {
ChatMarkdownLinkHref,
ChatMarkdownLinkTarget,
Expand All @@ -14,7 +18,7 @@ import type {
} from '@/types'
import type { OramaClient } from '@oramacloud/client'
import '@phosphor-icons/webcomponents/dist/icons/PhArrowClockwise.mjs'
import type { AnyOrama, Orama } from "@orama/orama"
import type { AnyOrama, Orama } from '@orama/orama'

@Component({
tag: 'orama-chat-box',
Expand All @@ -23,7 +27,7 @@ import type { AnyOrama, Orama } from "@orama/orama"
})
export class ChatBox {
@Element() el: HTMLElement
@Prop() index?: CloudIndexConfig
@Prop() index?: CloudIndexConfig | CloudIndexConfig[]
@Prop() clientInstance?: OramaClient | AnyOrama
@Prop() sourceBaseUrl?: string
@Prop() linksTarget?: string
Expand Down Expand Up @@ -65,7 +69,7 @@ export class ChatBox {
}

startChatService() {
validateCloudIndexConfig(this.el, this.index, this.clientInstance)
validateCloudIndexOrInstance(this.el, this.index, this.clientInstance)
const oramaClient = this.clientInstance || initOramaClient(this.index)

chatContext.chatService = new ChatService(oramaClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
| `chatMarkdownLinkTarget` | -- | | `({ text, href }: { text: string; href: string; }) => string` | `undefined` |
| `chatMarkdownLinkTitle` | -- | | `({ text, href }: { text: string; href: string; }) => string` | `undefined` |
| `clientInstance` | -- | | `FunctionComponents<any> & Internals<any, AnyIndexStore, AnyDocumentStore, AnySorterStore> & ArrayCallbackComponents<any> & OramaID & { plugins: OramaPlugin<unknown>[]; } \| OramaClient<true>` | `undefined` |
| `index` | -- | | `{ api_key: string; endpoint: string; }` | `undefined` |
| `index` | -- | | `CloudIndexConfig[] \| { api_key: string; endpoint: string; }` | `undefined` |
| `linksRel` | `links-rel` | | `string` | `undefined` |
| `linksTarget` | `links-target` | | `string` | `undefined` |
| `placeholder` | `placeholder` | | `string` | `undefined` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class SearchBox {
*
* note: It will be overrided by clientInstance property
*/
@Prop() index?: CloudIndexConfig
@Prop() index?: CloudIndexConfig | CloudIndexConfig[]
/**
* Orama Instance
*/
Expand Down
Loading

0 comments on commit eeae2f0

Please sign in to comment.