ডকুমেন্টের মধ্যে নির্দিষ্ট স্ট্রিং অনুসন্ধান করতে Cloud Firestore টেক্সট সার্চ বৈশিষ্ট্য ব্যবহার করুন।
সংস্করণের প্রয়োজনীয়তা
টেক্সট সার্চের জন্য ফায়ারস্টোর এন্টারপ্রাইজ এডিশন ডেটাবেস প্রয়োজন।
শুরু করার আগে
টেক্সট সার্চ করার জন্য, আপনাকে প্রথমে যে ফিল্ডগুলোতে সার্চ করতে হবে সেগুলোর জন্য টেক্সট ইনডেক্স তৈরি করতে হবে।
টেক্সট সার্চ চালান
টেক্সট সার্চ করার জন্য, search(...) ধাপের query প্যারামিটারের মধ্যে documentMatches এক্সপ্রেশনটি ব্যবহার করুন।
অপারেশনটি শুধুমাত্র টেক্সট ইনডেক্স দ্বারা সূচিবদ্ধ ফিল্ডগুলিতে অনুসন্ধান করে। যদি একাধিক ইনডেক্স উপলব্ধ থাকে, তাহলে Cloud Firestore অপারেশনটির জন্য ব্যবহারের জন্য একটি ইনডেক্স নির্বাচন করে।
Web
const result = await execute(db.pipeline().collection('restaurants') .search({ query: documentMatches('waffles') }));
আইওএস
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")));
নোড.জেএস
await db.pipeline().collection('restaurants') .search({ query: documentMatches('waffles') }) .execute();
পাইথন
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();
যান
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"') }));
আইওএস
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\"")));
নোড.জেএস
await db.pipeline().collection('restaurants') .search({ query: documentMatches('"belgian waffles"') }) .execute();
পাইথন
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();
যান
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') }));
আইওএস
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")));
নোড.জেএস
await db.pipeline().collection('restaurants') .search({ query: documentMatches('waffles eggs') }) .execute();
পাইথন
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();
যান
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') }));
আইওএস
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")));
নোড.জেএস
await db.pipeline().collection('restaurants') .search({ query: documentMatches('-waffles') }) .execute();
পাইথন
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();
যান
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() }));
আইওএস
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()) )
নোড.জেএস
await db.pipeline().collection('restaurants') .search({ query: documentMatches('waffles'), sort: score().descending() }) .execute();
অনুসন্ধান পর্যায়ে প্রাপ্ত নথিগুলিতে ক্ষেত্র যোগ করুন
সার্চ স্টেজ থেকে প্রাপ্ত ডকুমেন্টগুলিতে ফিল্ড যোগ করতে আপনি addFields ব্যবহার করতে পারেন। সার্চ স্টেজে addFields এর মধ্যে score() এর মতো এক্সপ্রেশন, যা সার্চ স্টেজ দ্বারা গণনা করা মান প্রদান করে, সেই মানগুলিকে আউটপুট ডকুমেন্টগুলিতে লেখার জন্য ব্যবহার করা যেতে পারে।
নিম্নলিখিত উদাহরণটি সার্চ পর্যায় থেকে প্রাপ্ত ডকুমেন্টগুলিতে স্কোর ফিল্ডটি যোগ করে:
Web
const result = await execute(db.pipeline().collection('restaurants') .search({ query: 'menu:waffles', addFields: [ score().as('score'), ] }));
আইওএস
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")));
নোড.জেএস
await db.pipeline().collection('restaurants') .search({ query: field('menu').matches('waffles'), addFields: [ score().as('score'), ] }).execute();
পাইথন
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();
যান
snapshot := client.Pipeline(). Collection("restaurants"). Search( firestore.WithSearchQuery(firestore.FieldOf("menu").RegexMatch("waffles")), firestore.WithSearchAddFields(firestore.Score().As("score")), ). Execute(ctx)