Coverage for functions \ flipdare \ search \ core \ query_options.py: 92%
40 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1#!/usr/bin/env python
2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
3#
4# This file is part of Flipdare's proprietary software and contains
5# confidential and copyrighted material. Unauthorised copying,
6# modification, distribution, or use of this file is strictly
7# prohibited without prior written permission from Flipdare Pty Ltd.
8#
9# This software includes third-party components licensed under MIT,
10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
11#
14from dataclasses import dataclass
15from typing import override
17from flipdare.constants import (
18 MAX_SEARCH_AUTOCOMPLETE_RESULTS,
19 MAX_SEARCH_AUTOCOMPLETE_RESULTS_PER_PAGE,
20 MAX_SEARCH_RESULTS,
21 MAX_SEARCH_RESULTS_PER_PAGE,
22 MIN_SEARCH_AUTOCOMPLETE_TYPOS,
23 MIN_SEARCH_TYPOS,
24)
27@dataclass
28class QueryOptions:
29 num_typos: int
30 exhaustive_search: bool
31 auto_complete: bool
32 per_page: int
33 limit: int
34 prefix: bool
35 typo_tokens_threshold: int
36 drop_tokens_threshold: int
37 highlight_affix_num_tokens: int
39 @classmethod
40 def standard(cls) -> "QueryOptions":
41 return cls(
42 num_typos=MIN_SEARCH_TYPOS,
43 exhaustive_search=False,
44 auto_complete=False,
45 per_page=MAX_SEARCH_RESULTS_PER_PAGE,
46 limit=MAX_SEARCH_RESULTS,
47 drop_tokens_threshold=1,
48 typo_tokens_threshold=1,
49 highlight_affix_num_tokens=4,
50 prefix=True,
51 )
53 @classmethod
54 def general(cls) -> "QueryOptions":
55 return cls(
56 num_typos=MIN_SEARCH_TYPOS,
57 exhaustive_search=False,
58 auto_complete=False,
59 per_page=MAX_SEARCH_RESULTS_PER_PAGE,
60 limit=MAX_SEARCH_RESULTS,
61 drop_tokens_threshold=1,
62 typo_tokens_threshold=1,
63 highlight_affix_num_tokens=4,
64 prefix=True,
65 )
67 @classmethod
68 def friend(cls) -> "QueryOptions":
69 return cls(
70 num_typos=MIN_SEARCH_TYPOS,
71 exhaustive_search=False,
72 auto_complete=False,
73 per_page=MAX_SEARCH_RESULTS_PER_PAGE,
74 limit=MAX_SEARCH_RESULTS,
75 drop_tokens_threshold=1,
76 typo_tokens_threshold=1,
77 highlight_affix_num_tokens=4,
78 prefix=True,
79 )
81 @classmethod
82 def auto(cls) -> "QueryOptions":
83 return cls(
84 num_typos=MIN_SEARCH_AUTOCOMPLETE_TYPOS,
85 exhaustive_search=True,
86 auto_complete=True,
87 per_page=MAX_SEARCH_AUTOCOMPLETE_RESULTS_PER_PAGE,
88 limit=MAX_SEARCH_AUTOCOMPLETE_RESULTS,
89 drop_tokens_threshold=1,
90 typo_tokens_threshold=1,
91 highlight_affix_num_tokens=4,
92 prefix=True,
93 )
95 @override
96 def __str__(self) -> str:
97 return (
98 f"QueryOptions(num_typos={self.num_typos}, "
99 f"exhaustive_search={self.exhaustive_search}, "
100 f"auto_complete={self.auto_complete}, "
101 f"prefix={self.prefix}, "
102 f"per_page={self.per_page}, "
103 f"limit={self.limit}, "
104 f"typo_tokens_threshold={self.typo_tokens_threshold}, "
105 f"drop_tokens_threshold={self.drop_tokens_threshold}, "
106 f"highlight_affix_num_tokens={self.highlight_affix_num_tokens})"
107 )
109 @override
110 def __repr__(self) -> str:
111 return self.__str__()
113 @override
114 def __eq__(self, other: object) -> bool:
115 if not isinstance(other, QueryOptions):
116 return NotImplemented
117 return (
118 self.num_typos == other.num_typos
119 and self.exhaustive_search == other.exhaustive_search
120 and self.auto_complete == other.auto_complete
121 and self.per_page == other.per_page
122 and self.limit == other.limit
123 and self.prefix == other.prefix
124 and self.typo_tokens_threshold == other.typo_tokens_threshold
125 and self.drop_tokens_threshold == other.drop_tokens_threshold
126 and self.highlight_affix_num_tokens == other.highlight_affix_num_tokens
127 )
129 @override
130 def __hash__(self) -> int:
131 return hash(
132 (
133 self.num_typos,
134 self.exhaustive_search,
135 self.auto_complete,
136 self.per_page,
137 self.limit,
138 self.prefix,
139 self.typo_tokens_threshold,
140 self.drop_tokens_threshold,
141 self.highlight_affix_num_tokens,
142 ),
143 )