Reputation: 2097
I was trying Lucene.net for applying fulltext search and was able to use it with the helpof this link http://www.codeproject.com/Articles/320219/Lucene-Net-ultra-fast-search-for-MVC-or-WebForms
but the it has an example only for some simple data
while i m having a scenario where the two entities are linked with one-to-many relation.
class Product
{
public int Id{get;set;}
public int Name{get;set;}
}
class Shop
{
public int Id{get;set;}
public int Name{get;set;}
public List<Product> Products{get;set;}
}
now implementing/(storing this in index as a single table or doc) this is a bit tricky.
Should i create two documents for index?
but then linking would be a problem, if the search was made in Product
and it will return result with only Product
and not shops.
What is the way out of it? or some other way?
--EDIT---
need to store these 1:N related data in single document as i would be giving the search on any of the field from both the entities.
So even after the result is returned by lucene it has the id available for both entities.
Upvotes: 2
Views: 1297
Reputation: 717
One option is to create a field in your index for each product document, which holds all shop ids.
Document (Product)
Name | Shop
------------------------
Super Product XY | 1 5 7
Now, if you only want to search in one shop you could do something like this.
+Name:"Super Product" +Shop:5
In general it absolutely depends on your requirements. Do you need to search over all shops and find out, which shop provides a product or do you want to limit your search to a single or multiple shops.
=== Update ===
If you want to receive the Product-ID and the Shop-ID you can define the Fields ProductID and ShopID as "Field::STORE_YES" (C++ Variant, i don't know the .NET define).
(STORE_YES)|(INDEXED_TOKENIZED)| (STORE_YES)
ProductID | Name | ShopID
--------------------------------------
1 | Super Product XY | 1 5 7
2 | Not good Product | 2 5 6
--------------------------------------
From a found Document object you can read the fields ProductID and ShopID, which gives you all you need. ShopID will return as String, you can split it by space (" ") and you have an array of your ShopIDs.
Upvotes: 2