I am using python 2.7, jinja2 and google app engine.
I have a database where one of the entities are string in this form:
"test1,test2,test3,test4,test5"
I try to figure a query where I will retrieve all the entities where test1 for example are in the string.
I tried the following where tags is the string property:
category = "test1"
mymodel.gql("WHERE tags in :1", category)
I have this error : BadArgumentError: List expected for "IN" filter
I can imagine that this is logical, since my property is string and not list, but how can I change the query to make it work?
You would have to modify you property to be a StringListProperty rather than string for this to work.
There are not a lot of other choices either. Use FullText Search is or something like WHoosh https://github.com/tallstreet/Whoosh-AppEngine which also does full text search are your other alternatives.
I would personally change it to a StringListProperty.
As the error indicates, the GQL is expecting a list. Try making category a list:
category = ["test1"]
Related
i recently started using the marqo library and i am trying to add document so that marqo can search and return the relevant part of the document but i keep getting error when i run the the code.
i used the
add_document()
method and i pass the document as a string for search but it returns an error. Here is what my code look like;
import marqo
DOCUMENT = 'the document'
mq = marqo.Client(url='http://localhost:8882')
mq.index("my-first-index").add_documents(DOCUMENT)
and when i run it i get a
MarqoWebError
you are getting the error because the add_document() method takes a list of python dictionaries as an argument not a string, so you are to pass the document as a value to any key you assign to it. But it is advisable to add a title and also an id for later referencing. Here is what i mean;
mq.index("my-first-index").add_documents([
{
"Title": the_title_of_your_document,
"Description": your_document,
"_id": your_id,
}]
)
the id can be any string of your choice. You can add as many dictionaries as you want to the list, each dictionary represents a document.
I think the documents need to be a list of dicts. See here https://marqo.pages.dev/API-Reference/documents/
I have a document reference that I am retreiving from a query on my Firestore database. I want to use the DocumentReference as a query parameter for another query. However, when I do that, it says
TypeError: sequence item 1: expected str instance, DocumentReference found
This makes sense, because I am trying to pass a DocumentReference in my update statement:
db.collection("Teams").document(team).update("Dictionary here") # team is a DocumentReference
Is there a way to get the document name from a DocumentReference? Now before you mark this as duplicate: I tried looking at the docs here, and the question here, although the docs were so confusing and the question had no answer.
Any help is appreciated, Thank You in advance!
Yes,split the .refPath. The document "name" is always the last element after the split; something like lodash _.last() can work, or any other technique that identifies the last element in the array.
Note, btw, the refPath is the full path to the document. This is extremely useful (as in: I use it a lot) when you find documents via collectionGroup() - it allows you to parse to find parent document(s)/collection(s) a particular document came from.
Also note: there is a pseudo-field __name__ available. (really an alias of documentID()). In spite of it's name(s), it returns the FULL PATH (i.e. refPath) to the document NOT the documentID by itself.
I think I figured out - by doing team.path.split("/")[1] I could get the document name. Although this might not work for all firestore databases (like subcollections) so if anyone has a better solution, please go ahead. Thanks!
I have an index with a TagField, created like this
create_index([TextField("enc_id"), TextField("title", 2.0), TagField("tags")])
I would add a document like this.
add_document(title = "meh, lol", tags = "python,C")
I search like this. It has a few fields that don't need to be searched, so I limited fields to search.
Query(query_string='meh').limit_fields(title)
What I want is to also filter results by some tags. For example, I have documents with tags like python, C, Java and I only want documents to be returned that has the tag 'C'.
How do I do that?
Finally found it :D.
I basically tried to execute pure redis-cli commands with the python client. Didn't know how :/
But this worked. I can use # in the query string. Just like we do in cli.
Query("#title:meh #tags:{java}")
I'd like to use Google AppEngine full text search to search for items in an index that have their logo set to None
tried
"NOT logo_url:''"
is there any way I write such a query, or do I have to add another property which is has_logo?
You can not filter by non existing values by nature of full text search indexes.
You would need to create a column/property "no_logo" to be able to do this.
As an option you can define some default for empty values. For example just a string "None". Then search like:
logo_url: None
That is how I would do it.
Have you tried with:
NOT logo_url: Null
I'm trying to use whoosh to add search functionality to my blogapp on appengine but I don't understand some stuff.
The blogentries are indexed with title, content and status fields.
I would like to have different type of results on the public page then on the admin page but without the need to have multiple indexes.
On the frontpage I want visitors to be able to search on visible entries only on the title and content fields and in the admin I want to search also on draft entries.
Can i concatenate searches using QueryParser so I can search on multiple fields?
How could I filter on status:visible with MultifieldParser?
EDIT
didn't test it yet but i got an answer on the whoosh mailing list:
# Create a parser that will search in title and content
qp = qparser.MultifieldParser(["title", "content"], ix.schema)
# Parse the user query
q = qp.parse(user_query_string)
# If request is not admin, filter on status:visible
filterq = query.Term("status", u"visible") if not is_admin else None
# Get search results
results = searcher.search(q, filter=filterq)
I know this is not strictly an answer but Google added a full text search api similar to whoosh. Perhaps you should try it.
https://developers.google.com/appengine/docs/python/search/overview