Skip to content

Commit

Permalink
Merge pull request #97 from testsigmahq/dev
Browse files Browse the repository at this point in the history
[Fixed] -> Search results repeating issue on typesense search (#96)
  • Loading branch information
Santhosh-testsigma authored Aug 6, 2024
2 parents f47bba8 + 7db5b76 commit e146a96
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
28 changes: 28 additions & 0 deletions scripts/indexr.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ async function indexData() {
apiKey: process.env.TYPESENSE_API_KEY,
});

let collectionExists = false;
try {
await client.collections(process.env.TYPESENSE_COLLECTION).retrieve();
collectionExists = true;
} catch (error) {
if (error.httpStatus !== 404) {
throw error;
}
}

if (collectionExists) {
await client.collections(process.env.TYPESENSE_COLLECTION).delete();
console.log(`Collection ${process.env.TYPESENSE_COLLECTION} deleted successfully.`);
}

await client.collections().create({
name: process.env.TYPESENSE_COLLECTION,
fields: [
{ name: 'objectID', type: 'string' },
{ name: 'title', type: 'string' },
{ name: 'search_keyword', type: 'string' },
{ name: 'slug', type: 'string' },
{ name: 'excerpt', type: 'string' },
{ name: 'headings', type: 'string[]', facet: false }
]
});
console.log(`Collection ${process.env.TYPESENSE_COLLECTION} created successfully.`);

const response = await request('http://localhost:8001/___graphql', pageQuery);
console.log('response', response);
const data = await response;
Expand Down
8 changes: 5 additions & 3 deletions src/components/SearchHits.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
@import '_variables.scss';

ais-highlight-0000000000 {
color: $grey_90;
background-color: $yellow_20;
color: $white;
background-color: #00b2bd;
padding: 0 6px;
border-radius: 4px;
}

.input-empty {
Expand All @@ -28,7 +30,7 @@ ais-highlight-0000000000 {
text-decoration: none;
}
p {
margin: 6px 0;
margin: 6px 0 !important;
font-size: 14px;
line-height: 20px;
overflow-wrap: break-word;
Expand Down
10 changes: 6 additions & 4 deletions src/components/SearchInputBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SearchInputBox extends React.Component {
searchQuery: ''
};

this.debouncedSearch = debounce(this.handleSearch, 300);
this.debouncedSearch = debounce(this.handleSearch, 500);
}

onClickOut = (event) => {
Expand All @@ -80,9 +80,11 @@ class SearchInputBox extends React.Component {
hasInput: query.length > 2,
});

this.setState({ searchQuery: '' }, () => {
this.debouncedSearch(query);
});
if (this.state.searchQuery !== query) {
this.setState({ searchQuery: '' }, () => {
this.debouncedSearch(query);
});
}
}

handleSearch = (query) => {
Expand Down
1 change: 0 additions & 1 deletion src/components/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class Layout extends React.Component {
const navElement = document.querySelector(
`.contextual-links a.dynamic-link__internal[href*="#${entry.target.id}"]`,
)
console.log(entry);
if (entry.isIntersecting) {
if (navElement && !navElement.classList.contains('border-red-100')) {
document.querySelectorAll('.contextual-links__link a.border-red-100.border-b-2').forEach(previousActive => {
Expand Down

0 comments on commit e146a96

Please sign in to comment.