[SOLVED]Problem with searching



  • Hello all!

    I have problem with searching.

    I created next query:
    @ QJsonObject wordObject;
    wordObject["crcKey"] = "somecrc";
    QJsonObject query;
    query["search"] = wordObject;
    QJsonArray objectsTypes;
    objectsTypes.push_back(QString("objects.Word"));
    query["objectTypes"] = objectsTypes;
    EnginioReply* pSearchReply = m_pEnginioClient->search(query);
    QObject::connect(pSearchReply, &EnginioReply::finished,
    [=](EnginioReply* pReply)
    {
    qDebug() << pReply->data()["results"].toArray();
    }@

    I recived all objects with type "objects.Word" but I need only one object where crc value is equal that I setted.

    Where I was wrong?



  • When I did next code:
    @
    QJsonObject query;
    query["objectType"] = QString("objects.Word");
    QJsonObject wordObject;
    wordObject["crcKey"] = "somecrc";
    query["q"] = wordObject;
    qDebug() << query;
    EnginioReply* pSearchReply = m_pEnginioClient->query(query);
    QObject::connect(pSearchReply, &EnginioReply::finished,
    [=](EnginioReply* pReply)
    {
    qDebug() << pReply->data()["results"].toArray();
    }
    @

    The result is the same.



  • Search is a full text search operation. I'm not sure If you want to use it just for a crc comparison. Query probably is a better option.

    Anyway, your search query is a bit miss typed. Please consult https://engin.io/documentation/rest/parameters/fulltext_query to see how the search property should be defined. For example you do not have searched phrase (btw. server should complain about it in a more verbose way). I guess that your search query should look like that:

    {'objectTypes": ["objects.Word"],
    "search": { "phrase": "somecrc", "properties": ["crcKey"] }
    }

    properties are optional. Remember that crcKey has to be indexed (you can change it in the dashboard)



  • I did next code:
    @QJsonObject query;
    query["objectType"] = QString("objects.Word");
    QJsonObject wordObject;
    wordObject["phrase"] = QString("somecrc");
    wordObject["properties"] = QString("crcKey");
    query["search"] = wordObject;
    EnginioReply* pSearchReply = m_pEnginioClient->query(query);
    @
    But result is the same.



  • When I did:
    @
    QJsonObject query;
    query["objectTypes"] = QString("objects.Word");
    QJsonObject wordObject;
    wordObject["phrase"] = word.getCrcKey();
    wordObject["properties"] = QString("somecrc");
    query["search"] = wordObject;
    EnginioReply* pSearchReply = m_pEnginioClient->search(query);
    @
    I received next error:
    @"{"errors": [{"message": "objectTypes parameter is required","reason": "InvalidParameter"}]}"@



  • Are we talking about search() or about query() method? Both have a bit different purpose and different calling conventions.

    Your search() object is bit wrong:

    • objectTypes has to be an array

    otherwise it should be ok. Full text search can go through multiple types.

    instead of
    @
    query["objectTypes"] = QString("objects.Word");
    @

    You could use
    @
    QJsonArray objectTypes;
    objectTypes.append(QString::fromUtf8("objects.Word"));
    query["objectTypes"] = objectTypes;
    @

    I tried to improve the error message https://codereview.qt-project.org/#change,67225



  • I did:
    @
    QJsonArray objectTypes;
    objectTypes.append(QString::fromUtf8("objects.Word"));
    query["objectTypes"] = objectTypes;
    QJsonObject wordObject;
    wordObject["phrase"] = QString("somecrc);
    wordObject["properties"] = QString("crcKey");
    query["search"] = wordObject;
    EnginioReply* pSearchReply = m_pEnginioClient->search(query);
    @
    I recieved next error:
    @"{"errors": [{"message": "Internal server error","reason": "Internal"}]}" @



  • That is interesting...

    Could you remove this line:
    @
    wordObject["properties"] = QString("crcKey");
    @

    or replace by

    @
    QJsonArray properties;
    properties.append(QString::fromUtf8("crcKey"));
    wordObject["properties"] = properties;
    @



  • Yes, now this is work! Thank you!



  • which one works?



  • My final query is:
    @
    QJsonObject query;
    QJsonArray objectTypes;
    objectTypes.append(QString::fromUtf8("objects.Word"));
    query["objectTypes"] = objectTypes;
    QJsonObject wordObject;
    wordObject["phrase"] = QString("somecrc");
    QJsonArray properties;
    properties.append(QString::fromUtf8("crcKey"));
    wordObject["properties"] = properties;
    query["search"] = wordObject;
    EnginioReply* pSearchReply = m_pEnginioClient->search(query);
    @

    Now I got only object that have crc that I setted.



  • great, I will forward your problem the the right person, you should get much nicer error messages in the first place. Thanks for trying enginio!



  • what if we have to search for a record which has phrase A in property A and phrase B in property B in one query?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.