MongoDB Full Text Search

Source: Internet
Author: User

  1. Insert test data with column name and description
  2. > Db.stores.insert (
  3. ... [
  4. ... {_id:1, name: "Java Hut", Description: "Coffee and Cakes"},
  5. ... {_id:2, name: "Burger Buns", Description: "Gourmet Hamburgers"},
  6. ... {_id:3, name: "Coffee Shop", Description: "Just Coffee"},
  7. ... {_id:4, name: "Clothes Clothes Clothes", Description: "Discount clothing"},
  8. ... {_id:5, name: "Java Shopping", Description: "Indonesian Goods"}
  9. ... ]
  10. ... )
  11. Bulkwriteresult ({
  12. "writeerrors": [],
  13. "writeconcernerrors": [],
  14. "ninserted": 5,
  15. "nupserted": 0,
  16. "nmatched": 0,
  17. "nmodified": 0,
  18. "nremoved": 0,
  19. "upserted": []
  20. })
  21. Built on stores so contains the name column and the description are both text
  22. > Db.stores.createIndex ({ name: "text", Description: "Text"})
  23. {
  24. "createdcollectionautomatically": false,
  25. "Numindexesbefore": 1,
  26. "Numindexesafter": 2,
  27. "OK": 1
  28. }
  29. Performing a full-text search will result in keyword segmentation and matching results, which can be measured by a small amount of data.
  30. > Db.stores. find ({$text: {$search: "java Coffee Shop"}})
  31. {"_id": 3, "name": "Coffee Shop", "description": "Just Coffee"}
  32. {"_id": 1, "name": "Java Hut", "description": "Coffee and Cakes"}
  33. {"_id": 5, "name": "Java Shopping", "description": "Indonesian Goods"}

Advantage: Real-time full-text search.

Do not know how performance, do not support highlighting this display, only in the 3.2+ version is supported Chinese word segmentation.

Under the general understanding, the temporary will not use, later use can read the manual in detail:

https://docs.mongodb.com/manual/text-search/

MongoDB Full-Text search

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.