-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add serialize function #51
Comments
I tried implementing this but ran into a few limitations:
This is what I've got so far: type SearchParserOffset = (
| SearchParserKeyWordOffset
| SearchParserTextOffset
) & {
offsetStart: number;
offsetEnd: number;
};
type SearchParserKeyWordOffset = {
keyword: string;
value?: string;
};
type SearchParserTextOffset = {
text: string;
};
export const serializeSearchQuery = (offsets: SearchParserOffset[]) => {
let searchQuery = "";
for (const offset of offsets) {
const gapSize = offset.offsetStart - searchQuery.length;
if (gapSize > 0) {
searchQuery += Array.from({ length: gapSize }).fill(" ").join("");
}
if ("text" in offset) {
if (offset.text.includes(" ")) {
if (offset.text.includes(`'`) && !offset.text.includes(`"`)) {
searchQuery += `"${offset.text}"`;
} else {
searchQuery += `'${offset.text.replaceAll(`'`, `\'`)}'`;
}
} else {
searchQuery += offset.text;
}
} else {
searchQuery += offset.keyword + ":" + offset.value;
}
}
return searchQuery;
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be nice to be able to re-build query using offsets.
The text was updated successfully, but these errors were encountered: