Skip to content

Commit 7db5b76

Browse files
[Fixed] -> Search results repeating issue on typesense search (#96)
1 parent 5978706 commit 7db5b76

4 files changed

Lines changed: 39 additions & 8 deletions

File tree

scripts/indexr.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ async function indexData() {
6464
apiKey: process.env.TYPESENSE_API_KEY,
6565
});
6666

67+
let collectionExists = false;
68+
try {
69+
await client.collections(process.env.TYPESENSE_COLLECTION).retrieve();
70+
collectionExists = true;
71+
} catch (error) {
72+
if (error.httpStatus !== 404) {
73+
throw error;
74+
}
75+
}
76+
77+
if (collectionExists) {
78+
await client.collections(process.env.TYPESENSE_COLLECTION).delete();
79+
console.log(`Collection ${process.env.TYPESENSE_COLLECTION} deleted successfully.`);
80+
}
81+
82+
await client.collections().create({
83+
name: process.env.TYPESENSE_COLLECTION,
84+
fields: [
85+
{ name: 'objectID', type: 'string' },
86+
{ name: 'title', type: 'string' },
87+
{ name: 'search_keyword', type: 'string' },
88+
{ name: 'slug', type: 'string' },
89+
{ name: 'excerpt', type: 'string' },
90+
{ name: 'headings', type: 'string[]', facet: false }
91+
]
92+
});
93+
console.log(`Collection ${process.env.TYPESENSE_COLLECTION} created successfully.`);
94+
6795
const response = await request('http://localhost:8001/___graphql', pageQuery);
6896
console.log('response', response);
6997
const data = await response;

src/components/SearchHits.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
@import '_variables.scss';
22

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

810
.input-empty {
@@ -28,7 +30,7 @@ ais-highlight-0000000000 {
2830
text-decoration: none;
2931
}
3032
p {
31-
margin: 6px 0;
33+
margin: 6px 0 !important;
3234
font-size: 14px;
3335
line-height: 20px;
3436
overflow-wrap: break-word;

src/components/SearchInputBox.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class SearchInputBox extends React.Component {
6262
searchQuery: ''
6363
};
6464

65-
this.debouncedSearch = debounce(this.handleSearch, 300);
65+
this.debouncedSearch = debounce(this.handleSearch, 500);
6666
}
6767

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

83-
this.setState({ searchQuery: '' }, () => {
84-
this.debouncedSearch(query);
85-
});
83+
if (this.state.searchQuery !== query) {
84+
this.setState({ searchQuery: '' }, () => {
85+
this.debouncedSearch(query);
86+
});
87+
}
8688
}
8789

8890
handleSearch = (query) => {

src/components/layout.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class Layout extends React.Component {
5252
const navElement = document.querySelector(
5353
`.contextual-links a.dynamic-link__internal[href*="#${entry.target.id}"]`,
5454
)
55-
console.log(entry);
5655
if (entry.isIntersecting) {
5756
if (navElement && !navElement.classList.contains('border-red-100')) {
5857
document.querySelectorAll('.contextual-links__link a.border-red-100.border-b-2').forEach(previousActive => {

0 commit comments

Comments
 (0)