Feature Request: Add SearxNG Preferences Parameter for Custom Search Engines #4056

Closed
opened 2025-11-11 15:45:17 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @rsea2z on GitHub (Feb 22, 2025).

Is your feature request related to a problem? Please describe.
Yes, it is related to a problem for users in China mainland. When using SearxNG with default settings in Open WebUI, the default search engines configured in SearxNG are often inaccessible due to network restrictions in China. This makes the web search feature within Open WebUI unusable for users in this region. I'm frustrated when I try to use web search in Open WebUI in China and it consistently fails due to unavailable search engines.

Describe the solution you'd like
I would like to have a way to pass a preferences parameter to the SearxNG URL in Open WebUI. This parameter, obtained from the user's SearxNG cookie settings, allows specifying preferred search engines within SearxNG. By including this parameter in the request, Open WebUI can utilize the user's customized SearxNG settings, ensuring that accessible search engines are used, even in regions with network restrictions.

Ideally, the solution would involve adding a new input field in the Open WebUI settings panel, specifically for "SearxNG Preferences Parameter". Users could then copy their preferences string from their SearxNG cookie and paste it into this field. Open WebUI would then automatically append &preferences=[user_provided_preferences] to the SearxNG URL when making search requests.

Describe alternatives you've considered

  1. Extracting preferences from the URL directly: As shown in my first code snippet, parsing the URL for a preferences parameter. This is less user-friendly as it requires users to manually modify the query URL every time.
  2. Hardcoding specific search engines: This is not flexible and defeats the purpose of SearxNG, which is to allow users to choose their preferred engines. It also doesn't address the core issue of regional accessibility.
  3. Automatically detecting user location and applying region-specific settings: This is complex to implement reliably and might raise privacy concerns.

The proposed solution of adding a dedicated "SearxNG Preferences Parameter" input field is the most practical and user-centric approach, allowing users to easily customize their SearxNG experience within Open WebUI to overcome network restrictions.

Additional context
Users in China often customize their SearxNG instances to use search engines that are accessible within the country. These custom settings are typically saved in the preferences cookie in SearxNG. By allowing users to provide their preferences parameter to Open WebUI, we can ensure that the web search feature works effectively for them.

The provided code snippets illustrate two potential implementation approaches:

  1. URL Parameter Extraction: (Less preferred, for demonstration) - Extracting the preferences directly from the query_url.
    # ./retrieval/web/searxng.py
    # -- other code -- #
        # Extract preferences in url
        if "preferences" in query_url:
            preferences = query_url.split("?preferences=")[1].split("&")[0]
        params["preferences"] = preferences
        log.debug(f"searching {query_url}")
        # Legacy query format
        if "<query>" in query_url:
            # Strip all query parameters from the URL
            query_url = query_url.split("?")[0]
    # -- other code -- #
    
  2. Dedicated Input Field: (More preferred) - Adding a preferences parameter to the search_searxng function and a corresponding input field in the UI.
    # ./retrieval/web/searxng.py
    # -- other code -- #
    def search_searxng(
        query_url: str,
        query: str,
        count: int,
        preferences: str, # Added preferences parameter
        filter_list: Optional[list[str]] = None,
        **kwargs,
    ) -> list[SearchResult]:
    # -- other code -- #
        params = {
            "q": query,
            "preferences": preferences, # Using preferences parameter
            "format": "json",
            "pageno": 1,
            "safesearch": safesearch,
            "language": language,
            "time_range": time_range,
            "categories": categories,
            "theme": "simple",
            "image_proxy": 0,
        }
    # -- other code -- #
    

I believe the second approach (Dedicated Input Field) is the better solution for user experience. Thank you for considering this feature request.

Originally created by @rsea2z on GitHub (Feb 22, 2025). **Is your feature request related to a problem? Please describe.** Yes, it is related to a problem for users in China mainland. When using SearxNG with default settings in Open WebUI, the default search engines configured in SearxNG are often inaccessible due to network restrictions in China. This makes the web search feature within Open WebUI unusable for users in this region. I'm frustrated when I try to use web search in Open WebUI in China and it consistently fails due to unavailable search engines. **Describe the solution you'd like** I would like to have a way to pass a `preferences` parameter to the SearxNG URL in Open WebUI. This parameter, obtained from the user's SearxNG cookie settings, allows specifying preferred search engines within SearxNG. By including this parameter in the request, Open WebUI can utilize the user's customized SearxNG settings, ensuring that accessible search engines are used, even in regions with network restrictions. Ideally, the solution would involve adding a new input field in the Open WebUI settings panel, specifically for "SearxNG Preferences Parameter". Users could then copy their `preferences` string from their SearxNG cookie and paste it into this field. Open WebUI would then automatically append `&preferences=[user_provided_preferences]` to the SearxNG URL when making search requests. **Describe alternatives you've considered** 1. **Extracting `preferences` from the URL directly:** As shown in my first code snippet, parsing the URL for a `preferences` parameter. This is less user-friendly as it requires users to manually modify the query URL every time. 2. **Hardcoding specific search engines:** This is not flexible and defeats the purpose of SearxNG, which is to allow users to choose their preferred engines. It also doesn't address the core issue of regional accessibility. 3. **Automatically detecting user location and applying region-specific settings:** This is complex to implement reliably and might raise privacy concerns. The proposed solution of adding a dedicated "SearxNG Preferences Parameter" input field is the most practical and user-centric approach, allowing users to easily customize their SearxNG experience within Open WebUI to overcome network restrictions. **Additional context** Users in China often customize their SearxNG instances to use search engines that are accessible within the country. These custom settings are typically saved in the `preferences` cookie in SearxNG. By allowing users to provide their `preferences` parameter to Open WebUI, we can ensure that the web search feature works effectively for them. The provided code snippets illustrate two potential implementation approaches: 1. **URL Parameter Extraction:** (Less preferred, for demonstration) - Extracting the `preferences` directly from the `query_url`. ```python # ./retrieval/web/searxng.py # -- other code -- # # Extract preferences in url if "preferences" in query_url: preferences = query_url.split("?preferences=")[1].split("&")[0] params["preferences"] = preferences log.debug(f"searching {query_url}") # Legacy query format if "<query>" in query_url: # Strip all query parameters from the URL query_url = query_url.split("?")[0] # -- other code -- # ``` 2. **Dedicated Input Field:** (More preferred) - Adding a `preferences` parameter to the `search_searxng` function and a corresponding input field in the UI. ```python # ./retrieval/web/searxng.py # -- other code -- # def search_searxng( query_url: str, query: str, count: int, preferences: str, # Added preferences parameter filter_list: Optional[list[str]] = None, **kwargs, ) -> list[SearchResult]: # -- other code -- # params = { "q": query, "preferences": preferences, # Using preferences parameter "format": "json", "pageno": 1, "safesearch": safesearch, "language": language, "time_range": time_range, "categories": categories, "theme": "simple", "image_proxy": 0, } # -- other code -- # ``` I believe the second approach (Dedicated Input Field) is the better solution for user experience. Thank you for considering this feature request.
Author
Owner

@rgaricano commented on GitHub (Feb 23, 2025):

another way is throught pipes, e.g. adapting https://openwebui.com/f/atgehrhardt/live_search
defining params of searxng as valves and passing it to searxng function.

@rgaricano commented on GitHub (Feb 23, 2025): another way is throught pipes, e.g. adapting https://openwebui.com/f/atgehrhardt/live_search defining params of searxng as valves and passing it to searxng function.
Author
Owner

@rsea2z commented on GitHub (Feb 23, 2025):

another way is throught pipes, e.g. adapting https://openwebui.com/f/atgehrhardt/live_search
defining params of searxng as valves and passing it to searxng function.

Thanks a lot for your suggestion! Pipes definitely sound like a cool approach, and I checked out the example you linked – it's really insightful!
To be honest though, I'm still hoping for direct support for the preferences parameter in Open WebUI itself. Probably easier for everyone to use without having to mess with plugins and stuff.
That being said, your pipes idea has actually given me some inspiration, and I might try to whip up a pipe in the next few days, just as a temporary fix and maybe to help move things along for this feature! Anyway, really appreciate your quick reply and the helpful idea! Cheers!

@rsea2z commented on GitHub (Feb 23, 2025): > another way is throught pipes, e.g. adapting https://openwebui.com/f/atgehrhardt/live_search > defining params of searxng as valves and passing it to searxng function. > Thanks a lot for your suggestion! Pipes definitely sound like a cool approach, and I checked out the example you linked – it's really insightful! To be honest though, I'm still hoping for direct support for the `preferences` parameter in Open WebUI itself. Probably easier for everyone to use without having to mess with plugins and stuff. That being said, your pipes idea has actually given me some inspiration, and I might try to whip up a pipe in the next few days, just as a temporary fix and maybe to help move things along for this feature! Anyway, really appreciate your quick reply and the helpful idea! Cheers!
Author
Owner

@ivanwong1989 commented on GitHub (Apr 26, 2025):

I would love this as well.

@ivanwong1989 commented on GitHub (Apr 26, 2025): I would love this as well.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#4056