I need to replicate "Search Google for this Image" in my rails app where image search is performed on an image in the app. I am using google-api-ruby-client gem. To test the api I am starting with a simple query search:
Trying this for a regular search term but getting invalid_scope error.
client = Google::APIClient.new application_name: 'xxx', application_version: '1.0'
keypath = Rails.root.join('config', 'privatekey.p12').to_s
key = Google::APIClient::PKCS12.load_key(keypath, 'notasecret')
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/customsearch/v1',
:issuer => 'xxx#developer.gserviceaccount.com',
:signing_key => key
).tap { |auth| auth.fetch_access_token! }
api_method = client.discovered_api('customsearch', 'v1')
result = client.execute(:api_method => api_method, :parameters => {
'q' => 'Hello+World'
})
return result.data
Thoughts?
It looks like your API call is missing the required Custom Search Engine ID. You need to use cx or cref to specify the custom search engine you want to use. If you don't already have CSE ID, you can get one here: https://www.google.com/cse
Once you have the CSE ID, you will need to include it to the parameters. One possible way is just adding it to the hash you already have...
result = client.execute(:api_method => api_method, :parameters => {'cx' => 'YOUR_CSE_ID', 'q'=> 'Hello+World'}
Your actual URI structure should look like:
https://www.googleapis.com/customsearch/v1?key=YOUR_API_KEY&cx=YOUR_CSE_ID&q=Hello+World
Here's another good reference: https://developers.google.com/custom-search/docs/api
Unfortunately I do not have experience with the Custom Search Engine but I did find a link I think could help you get to the right answer. This Google Dev documentation seems pretty good for setting up a custom search engine for your site.
Google Developers - Creating a Custom Search Engine
Related
As stated above in the title I am currently facing issues fetching graph places with PnPJs, using the #pnp/graph graphfi factory interface in SPFx.
I am currently able to fetch data from my events via graphfi as can be seen below:
React.useEffect(() => {
graph = graphfi().using(SPFx(props.context));
getSpecificCalendar();
}, []);
const getSpecificCalendar = async () => {
await graph.me.events().then((e) => setCalendarEvent(e));
}
I have tried to get the places property from the graph object but to no avail. The only properties present are me and users but no option for places.
Esentially what I want to do is to graph.places. The conclusion I have come to is that #pnp/graph does not have any methods to get room data. Any ideas other than what I have tried above would be extremely helpful.
It looks like pnpjs does not have the /places endpoint implemented (yet). You could try using the built-in SPFx graph client for now. Something like:
const client = await props.context.msGraphClientFactory.getClient('3')
const response = await client.api('/places/......').get();
Alternatively, you could implement the /places endpoint yourself and submit a pull request for pnpjs :)
I am currently developing a small web app using MERN. Here I have developed the backend part and frontend part of it. I want to get the response data category-wise. For example, in my database there are details of assets(Laptops, mobiles etc) with attributes like assetName and assetCategory. There's a functionality to search those assets category-wise. In the frontend, I have used a search bar and user can type the category of asset which is wanted to see. Then backend server gives the response of that. I have developed routes and controllers for the backend part and I will show the controller here.
//find assets by category
exports.assetsByCategory = async(req,res) => {
const CATEGORY = req.body.assetCategory;
const asset = await Asset.find({"assetCategory" :{$regex: new RegExp([CATEGORY?.toLowerCase()], "i") }})
.then((assets)=>{
res.json(assets)
}).catch((err)=>{
console.log(err);
res.status(500).send({message:"No assets like that category!",error:err.message})
})
}
The code for this function which is in the frontend part will be shown here.
function searchCategoryBar(e)
{
e.preventDefault();
const searchedCategory = {assetCategory}
console.log(searchedCategory)
axios.get("http://localhost:8070/assets/category",searchedCategory).then((asset)=>{
setAssets(asset.data);
console.log(asset.data);
}).catch((err)=>{
alert(err.message);
})
}
So that, when I type "lap" on the search bar and then the response must be shown the asset list of laptop category. But in here, response shows all the assets lists without category-wise.
Please give me some help to solve this issue, Thank you!
I am making a mobile app using flutter with firebase as my backend.
I have a collection of user document that stores user information. one of the fields is an array of references (reference documents in another collection) which I want to use in an operation like batch that in that would then allow be to read all the documents.
I know batch only allows writes to the database, My second option would be Transaction, which requires writes after reads which I am trying to avoid.
Is there a way to read multiple documents in one operation without having to use Transaction?
Firestore doesn't offer a formal batch read API. As Frank mentions in his comment, there is a way to use IN to fetch multiple documents from a single collection using their IDs. However, all of the documents must be in the same collection, and you can't exceed 10 documents per query. You might as well just get() for each document individually, as the IN query has limitations, and isn't guaranteed to execute any faster than the individual gets. Neither solution is guaranteed to be "consistent", so any one of the documents fetched could be "more fresh" than the others at any given moment in time.
If you know the document IDs and the collection paths of the documents needed to be fetched, you could always use the getAll() method which is exposed in the firebase Admin SDK (at least for Node.js environments).
Then, for example, you could write an HTTPS Callable Function that would accept a list of absolute document paths and perform a "batch get" operation on them using the getAll() method.
e.g.
// Import firebase functionality
const functions = require('firebase-functions');
const admin = require('firebase-admin');
// Configure firebase app
admin.initializeApp(functions.config().firebase);
// HTTPS callable function
exports.getDocs = functions.https.onCall((data, context) => {
const docPathList = data.list; // e.g. ["users/Jkd94kdmdks", "users/8nkdjsld", etc...]
const firestore = admin.firestore();
var docList = [];
for (var i = 0; i <= docPathList.length - 1; i++) {
const docPath = docPathList[i];
const doc = firestore.doc(docPath);
docList.push(doc);
}
// Get all
return firestore.getAll(...docList)
.then(results => {
return { data : results.map(doc => doc.data()) };
})
.catch(err => {
return { error : err };
})
});
Not sure what the limit (if any) is for the number of documents you can fetch using getAll(), but I do know my application is able to fetch at least 50 documents per call successfully using this method.
Firestore has a REST API that allows you to do batch GETs with document paths that may be what you need.
See https://firebase.google.com/docs/firestore/reference/rest/v1beta1/projects.databases.documents/batchGet
I have a Alexa hosted skill. I am trying to find a way to access persistenceAdapter.S3PersistenceAdapter() from some other places ( e.g. angular 2.x). Can this be done, or I have to use other database to replace S3? If that is the case, which database is recommended?
I use some sample code to access S3 from alexa skill. I have no idea how attributesManager work, just copy and paste.
.withPersistenceAdapter(
new persistenceAdapter.S3PersistenceAdapter({bucketName:process.env.S3_PERSISTENCE_BUCKET})
)
and
const attributesManager = handlerInput.attributesManager;
const sessionAttributes = await attributesManager.getPersistentAttributes() || {};
const temperature = sessionAttributes.hasOwnProperty('temperature') ? sessionAttributes.temperature : 0;
S3 isn't a database - S3 is object storage. If a database is what you need, you could use DynamoDB instead. It sounds like it is - you wouldn't normally use S3 for this.
Anyway, you'll not be able to use the ASK SDK in an Angular or other (non Alexa skill) project. But, you could connect to S3 (or DynamoDB) using the AWS SDK.
https://github.com/aws/aws-sdk-js
You have 3x types of attributes for Alexa - request, session and persistent. I noticed your variable is named sessionAttributes but you're doing getPersistentAttributes.
Here's an example of how you'd use the withPersistentAdapter - https://www.talkingtocomputers.com/alexa-skills-kit-ask-sdk-v2#data-persistence
But here's an example if you use DynamoDB. It's simpler IMO:
module.exports.handler = Alexa.SkillBuilders.standard()
.addRequestHandlers(/* your handlers */)
.withTableName(/* your table name (string) */)
.withDynamoDbClient()
.lambda()
}
Then you could do something like (in an async function):
const att = await attributesManager.getPersistentAttributes()
const temperature = att.temperature ? att.temperature : 0
But of course, you need to save the attribute there first, if you want to access it. For example (in an async function):
const att = await attributesManager.getPersistentAttributes()
await attributesManager.setPersistentAttributes( { ...att, temperature: 10 }) // set the value
await attributesManager.savePersistentAttributes() // save it
You can use S3 buckets the syntax looks like this, they do have get,set and save like the persistence attributes as in the example above and more on this you can go here the Amazon Docs at the bottom.
const { S3PersistenceAdapter } = require('ask-sdk-s3-persistence-adapter');
const S3PersistenceAdapter = new S3PersistenceAdapter({ bucketName : 'FooBucket' })
for me it looks like luck of documentation about Content Search API for sitecore.
I have Sitecore instance with all settings for use SOLR search and I would like to have a search for bucket items.
I am confused that Content Search should I use for implement my search logic
ContentSearchManager or SolrContentSearchManager ?
using (var context = SolrContentSearchManager.GetIndex(_searchIndexName).CreateSearchContext())
{
IQueryable<MyClass> query = context.GetQueryable<MyClass>().Where(p => p.MyProd.Contains("name"));
return query;
}
In both cases CreateSearchContext return IProviderSearchContext interface.
I have a filling that sitecore relay on configuration setting and it no difference. Am I right ?
ContentSearchManager is ok for Solr as well. It allows you to switch between Lucene and Solr without too many changes to your code.
I've never used SolrContentSearchManager.