I’m trying to validate that the fields given to sphinx are valid, but I’m having difficulty.
Imagine that valid fields are cat, mouse, dog, puppy.
Valid searches would then be:
- @cat search terms
- @(cat) search terms
- @(cat, dog) search term
- @cat searchterm1 @dog searchterm2
- @(cat, dog) searchterm1 @mouse searchterm2
So, I want to use a regular expression to find terms such as cat, dog, mouse in the above examples, and check them against a list of valid terms.
Thus, a query such as:
@(goat)
Would produce an error because goat is not a valid term.
I’ve gotten so that I can find simple queries such as @cat with this regex: (?:@)([^( ]*)
But I can’t figure out how to find the rest.
I’m using python & django, for what that’s worth.
I ended up doing this a different way, since none of the above worked. First I found the fields like @cat, with this:
Next, I found the more complicated ones, with this:
Next, I checked if the attributes I found were valid, and added them (uniquely to an array):
Thanks all for the help though. I’m very glad to have had it!