ডকুমেন্টের মধ্যে নির্দিষ্ট স্ট্রিং সার্চ করতে Cloud Firestore-এ টেক্সট সার্চ ফিচার ব্যবহার করুন।
সংস্করণ সংক্রান্ত প্রয়োজনীয়তা
টেক্সট সার্চের জন্য Firestore Enterprise এডিশন ডেটাবেস প্রয়োজন।
শুরু করার আগে
টেক্সট সার্চ করতে, আপনাকে প্রথমে সেইসব ফিল্ডের জন্য টেক্সট ইন্ডেক্স তৈরি করতে হবে যেগুলি আপনি সার্চ করতে চান।
টেক্সট সার্চ চালানো
টেক্সট সার্চ করতে, search(...) স্টেজের
query প্যারামিটারের মধ্যে documentMatches এক্সপ্রেশন ব্যবহার করুন।
এই অপারেশন শুধুমাত্র টেক্সট ইন্ডেক্স সহ ইন্ডেক্স করা ফিল্ডে সার্চ করে। একাধিক ইন্ডেক্স উপলভ্য থাকলে, Cloud Firestore অপারেশনের জন্য ব্যবহার করার জন্য একটি ইন্ডেক্স বেছে নেয়।
Web
const result = await execute(db.pipeline().collection('restaurants') .search({ query: documentMatches('waffles') }));
iOS
let snapshot = try await db.pipeline().collection("restaurants") .search(query: DocumentMatches("waffles")) .execute()
Kotlin
val pipeline = db.pipeline().collection("restaurants") .search(SearchStage.withQuery(documentMatches("waffles")))
Java
Pipeline pipeline = db.pipeline().collection("restaurants") .search(SearchStage.withQuery(documentMatches("waffles")));
Node.js
await db.pipeline().collection('restaurants') .search({ query: documentMatches('waffles') }) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches results = ( client.pipeline() .collection("restaurants") .search(DocumentMatches("waffles")) .execute() )
জাভা
Pipeline.Snapshot results1 = firestore.pipeline().collection("restaurants") .search(Search.withQuery(documentMatches("waffles"))) .execute().get();
Go
snapshot := client.Pipeline(). Collection("restaurants"). Search(firestore.WithSearchQuery(firestore.DocumentMatches("waffles"))). Execute(ctx)
ঠিক সেই শব্দটি সার্চ করা
কোনও নির্দিষ্ট শব্দ সার্চ করতে, শব্দটিকে কোটেশনের (") মধ্যে রাখুন:
Web
const result = await execute(db.pipeline().collection('restaurants') .search({ query: documentMatches('"belgian waffles"') }));
iOS
let snapshot = try await db.pipeline().collection("restaurants") .search(query: DocumentMatches("\"belgian waffles\"")) .execute()
Kotlin
val pipeline = db.pipeline().collection("restaurants") .search(SearchStage.withQuery(documentMatches("\"belgian waffles\"")))
Java
Pipeline pipeline = db.pipeline().collection("restaurants") .search(SearchStage.withQuery(documentMatches("\"belgian waffles\"")));
Node.js
await db.pipeline().collection('restaurants') .search({ query: documentMatches('"belgian waffles"') }) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches results = ( client.pipeline() .collection("restaurants") .search(DocumentMatches('"belgian waffles"')) .execute() )
জাভা
Pipeline.Snapshot results2 = firestore.pipeline().collection("restaurants") .search(Search.withQuery(documentMatches("\"belgian waffles\""))) .execute().get();
Go
snapshot := client.Pipeline(). Collection("restaurants"). Search(firestore.WithSearchQuery(firestore.DocumentMatches("\"belgian waffles\""))). Execute(ctx)
শব্দের কম্বিনেশন সার্চ করা
শব্দের কম্বিনেশন (লজিক্যাল AND) সার্চ করতে, স্পেস দিয়ে শব্দগুলি
আলাদা করুন:
Web
const result = await execute(db.pipeline().collection('restaurants') .search({ query: documentMatches('waffles eggs') }));
iOS
let snapshot = try await db.pipeline().collection("restaurants") .search(query: DocumentMatches("waffles eggs")) .execute()
Kotlin
val pipeline = db.pipeline().collection("restaurants") .search(SearchStage.withQuery(documentMatches("waffles eggs")))
Java
Pipeline pipeline = db.pipeline().collection("restaurants") .search(SearchStage.withQuery(documentMatches("waffles eggs")));
Node.js
await db.pipeline().collection('restaurants') .search({ query: documentMatches('waffles eggs') }) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches results = ( client.pipeline() .collection("restaurants") .search(DocumentMatches("waffles eggs")) .execute() )
জাভা
firestore.collection("restaurants").add(new HashMap<String, Object>() {{ put("name", "Morning Diner"); put("description", "Start your day with waffles and eggs."); }}); Pipeline.Snapshot results3 = firestore.pipeline().collection("restaurants") .search(Search.withQuery(documentMatches("waffles eggs"))) .execute().get();
Go
snapshot := client.Pipeline(). Collection("restaurants"). Search(firestore.WithSearchQuery(firestore.DocumentMatches("waffles eggs"))). Execute(ctx)
কোনও একটি শব্দ বাদ দেওয়া
কোনও শব্দ বাদ দিতে, শব্দটির আগে একটি হাইফেন (-) দিন:
Web
const result = await execute(db.pipeline().collection('restaurants') .search({ query: documentMatches('coffee -waffles') }));
iOS
let snapshot = try await db.pipeline().collection("restaurants") .search(query: DocumentMatches("coffee -waffles")) .execute()
Kotlin
val pipeline = db.pipeline().collection("restaurants") .search(SearchStage.withQuery(documentMatches("waffles eggs")))
Java
Pipeline pipeline = db.pipeline().collection("restaurants") .search(SearchStage.withQuery(documentMatches("coffee -waffles")));
Node.js
await db.pipeline().collection('restaurants') .search({ query: documentMatches('-waffles') }) .execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches results = ( client.pipeline() .collection("restaurants") .search(DocumentMatches("-waffles")) .execute() )
জাভা
firestore.collection("restaurants").add(new HashMap<String, Object>() {{ put("name", "City Coffee"); put("description", "Premium coffee and pastries."); }}); Pipeline.Snapshot results4 = firestore.pipeline().collection("restaurants") .search(Search.withQuery(documentMatches("-waffles"))) .execute().get();
Go
snapshot := client.Pipeline(). Collection("restaurants"). Search(firestore.WithSearchQuery(firestore.DocumentMatches("-waffles"))). Execute(ctx)
এছাড়াও, আপনি কোনও বাক্যাংশ বাদ দিতে পারেন, যেমন, pizza -"New York"।
ফলাফল সাজান
ডিফল্ট হিসেবে, Cloud Firestore ডকুমেন্ট তৈরির সময় অনুযায়ী ফলাফল সাজানো হয়, নতুন থেকে পুরনো। আপনি এর পরিবর্তে সার্চ স্কোর অনুসারে সাজাতে পারেন, তবে এর জন্য প্রতিটি ডকুমেন্টের সঠিক স্কোর গণনা ও তুলনা করার জন্য আরও বেশি কম্পিউটেশন প্রয়োজন:
সার্চ স্কোর অনুযায়ী ফলাফল সাজাতে:
Web
const result = await execute(db.pipeline().collection('restaurants') .search({ query: documentMatches('waffles'), sort: score().descending() }));
iOS
let snapshot = try await db.pipeline().collection("restaurants")
.search(
query: DocumentMatches("waffles"),
sort: [Score().descending()]
)
.execute()Kotlin
val pipeline = db.pipeline().collection("restaurants") .search(SearchStage .withQuery(documentMatches("waffles")) .withSort(score().descending()) )
Node.js
await db.pipeline().collection('restaurants') .search({ query: documentMatches('waffles'), sort: score().descending() }) .execute();
সার্চ স্টেজের মাধ্যমে রিটার্ন করা ডকুমেন্টে ফিল্ড যোগ করা
সার্চ স্টেজ থেকে পাওয়া ডকুমেন্টগুলিতে ফিল্ড যোগ করতে আপনি addFields ব্যবহার করতে পারেন।
সার্চ স্টেজ দ্বারা গণনা করা ভ্যালু রিটার্ন করা এক্সপ্রেশন,
যেমন score(), সার্চ স্টেজের মধ্যে addFields-এ ব্যবহার করা যেতে পারে। এর মাধ্যমে
আউটপুট ডকুমেন্টে সেইসব `ভ্যালু লেখা যায়।
নিম্নলিখিত উদাহরণটি সার্চ স্টেজ থেকে ফেরত আসা ডকুমেন্টে স্কোর ফিল্ড যোগ করে:
Web
const result = await execute(db.pipeline().collection('restaurants') .search({ query: 'menu:waffles', addFields: [ score().as('score'), ] }));
iOS
let snapshot = try await db.pipeline().collection("restaurants") .search( query: DocumentMatches("waffles"), addFields: [ Score().as("score") ] ) .execute()
Kotlin
val pipeline = db.pipeline().collection("restaurants") .search(SearchStage.withQuery(documentMatches("waffles eggs")))
Java
Pipeline pipeline = db.pipeline().collection("restaurants") .search( SearchStage.withQuery(documentMatches("menu:waffles")) .withAddFields(score().alias("score")));
Node.js
await db.pipeline().collection('restaurants') .search({ query: field('menu').matches('waffles'), addFields: [ score().as('score'), ] }).execute();
Python
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches, Score from google.cloud.firestore_v1.pipeline_stages import SearchOptions results = ( client.pipeline() .collection("restaurants") .search( SearchOptions( query=DocumentMatches("menu:waffles"), add_fields=[Score().as_("score")], ) ) .execute() )
জাভা
Pipeline.Snapshot results5 = firestore.pipeline().collection("restaurants") .search(Search.withQuery(field("menu").regexMatch("waffles")) .withAddFields(score().as("score"))) .execute().get();
Go
snapshot := client.Pipeline(). Collection("restaurants"). Search( firestore.WithSearchQuery(firestore.FieldOf("menu").RegexMatch("waffles")), firestore.WithSearchAddFields(firestore.Score().As("score")), ). Execute(ctx)