Algolia autocomplete modify query before POST - algolia

My problem is that I have a reserve character in my query string that I need to remove before posting data to Algolia's autocomplete widget. The character that I need to remove from my search is a dash ("-"). Basically, when ever the user types in the dash I want to replace it with a space (" ") on the backend post to Algolia for processing.
Is that possible?

Related

Postgres autocomplete and full text search

I need to create suggestion autocomplete for all the columns of a table in a single searchbox using postgres database.
I have a search autocomplete in web page and need to autosuggest the options. All columns are varchar.
For searching I am using the approach like
select * from userschema.user_details where to_tsvector(user_details::text) ## to_tsquery('text:*')
But I am facing an issue getting the options for autocomplete.
Is there a way of searching the tsvector and getting all the options that match a criteria.
Something like getting text* options from all the words of tsvector so that I can use them for autosuggest.
I am thinking of storing the contents of tsvector into a column.
Is there a way of fetching autosuggest words from same?

Relate text to Id once selected from text box with suggestion option in rcp

I currently have a text box that can predict String as typed.I used the snippet here .
There are two seprate questions
Q1)In the snippet the suggestion are passed as item but I want to relate the String to an id to update the database. If I just pass the string to snippet I need to do another query to again retrieve the id which costs resources is there a way to pass objects to the auto suggestion which will select the id of whichever name is chosen from the suggestions.
Q2)Also I dont want user to be adding new values so is there a way to force user to chose one of the values from the suggestion for the text box and not add his own values
This might be a workaround for your Q1.
In the auto-complete shell , use a SWT Table instead of combo widget.Have two columns in the table for string and string Id.Hide the second column so that the user cannot see it.You can use this column to retrieve the ids of corresponding strings.
Or simply store the string and string ids in a hash map and give the key values set of this hash map to the combo items.

Unable to use Sphinx MVA sql_attr_multi

I have a field called "tags" and it has values (say) "Music, Art, Sports, Food" etc. How can I use setFilter function in PHP-Sphinx for this field. I know that it has to be an integer and should be used as an array in PHP. So, if I use a numeric field for tags, what about the delimiters (in this case comma). Currently, I am using "sql_attr_multi" like this…
sql_attr_multi = uint tags from field
I have to filter the search based on any of the keywords the user has selected, Music, Sports, Food etc. As such, only MVA is the right option to do this. But I am just not able to figure out, how to do this. I can store all tag elements as numeric values and make the tags field as int. But what about the comma or how will I convert the whole string (Music, Art, Sports, Food) as an integer. Later, how do I call setFilter using PHP.
Any help is highly appreciated.
Well using a MVA, suggests you already unique-ids for each tag.
Which if you had a seperate table for tags (with a PK), and many-to-many table joining your documents, and tags. (thats a very common way to store tags - in normal form)
If you have a text column containing the text, would be easier to just use a Field. Can easily filter by fields in the main text-query.
crispy creams #tags Food
for example (thats extended mode query)
(But fields can't do Grouping like you can with Attributes)

Is it possible to perform a Sphinx search on one string attribute?

sql_query=SELECT id,headline,summary,body,tags,issues,published_at
FROM sphinx_search
I am working on the search feature of my Web site and I am using Sphinx, Perl and Sphinx::Search. As long as I want to search in all the attributes and I don't restrict it to just one, everything goes well. However when the user searches for a specific tag, I can't just give the result of a fuzzy search, I want to use the power of Sphinx to search only on tags or issues, maybe sometimes the user wants to search on headline and issues.
How can I perform such a task?
You need to put it in Extended Match Mode
https://metacpan.org/module/JJSCHUTZ/Sphinx-Search-0.27.2/lib/Sphinx/Search.pm#SetMatchMode
Then you can use Extended Query syntax
http://sphinxsearch.com/docs/current.html#extended-syntax
Which includes the field search operator
#tags keyword1
(Be careful with sphinx, the word "attribute" has a specific meaning - values attached to the document, useful for sorting/grouping/filtering and returning with the resultset. Whereas I think you are talking about fields. All the columns from the sql_query you dont mark as an attribute, are a field - and full text searchable)

Searching Core Data when field contains ' (single quote) character

Please help because I think I'm going mad.
I have a core data collection that contains many thousand records.
Some of the fields in these records contain terms that have a single
quote. When building the database from XML, we created two fields - a
NAME field and a SORTFIELD field.
The NAME field contains the full term and is used for display purposes
in our application.
The SORTFIELD field contains the same content as the NAME field but is
converted to lowercase and has all single quote characters removed
using the following.
[NSString stringByReplacingOccurrencesOfString:#"'" withString:#""];
When the user enters the string for which they wish to search, we
remove single quotes from the search string entered and convert to
lowercase using the same method as when creating the data. However it
does not find any results.
If the user enters Michael's, the system fails to find any records
The predicate is "SORTFIELD like 'michaels'"
If the user enters Michael' (single quote no 's' character), the
system finds all records starting Michael's
The predicate is "SORTFIELD like 'michael'"
I am sure we are doing something very stupid and appreciate any
pointers on how to resolve this issue as we have gone round and round
in circles.
We have placed many NSLog entries to track actual content of the
search fields and record fields and all display as expected.
Thanks
Mike
I finally resolved the issue on finding that the fields being searched
had a non-displayable character when a single quote existed. For
example Michael's displayed but Michaelx's where x= an extended ascii
character, was the actual contents.
By removing this from the fields we were able to perform the searching
as described in our original posting.
However, I still feel that you should be able to search a Core Data collection for strings that contain single quotes without having to do the 'hack' described.
Welcome any thoughts from others on this.
Thanks
Mike