Configure Query Indexes
Indexes are used in querying for efficiency, and are based on the type of a class. The user may further specify the attributes of the class on which indexes are required. Query Indexes can be configured in the following ways:
Add Query Indexes
Using NCache Web Manager
Launch NCache Web Manager by browsing to
http://localhost:8251
(Windows) or<server-ip>:8251
(Windows + Linux).In the left navigation bar, click on Clustered Caches or Local Caches, based on the cache to which the query index will be added. Against the cache name, click on View Details.
Note
Make sure that the cache is stopped.
This opens up the detailed configuration page for the cache. Go to the Advanced Settings tab and click on Query Indexes in the left bar.
This opens up the Query Indexes page, click on Add.
In the next page, select the assembly which contains the classes that you want to store in cache for querying by clicking on the "..." button.
In the Selected Assemblies box, all serialized classes are displayed. Check the ones you want to index, and click on Add Classes.
Note
NCache Web Manager displays all private members and properties of selected class. Select either private members or properties.
- The added classes will be displayed in List of selected classes. You can remove any classes by clicking on Remove Classes here. Click on OK.
- The added query indexes will be displayed in the Query Indexes page. Click on Save Changes to apply this configuration to the cache.
Using PowerShell
Add-QueryIndex cmdlet enables the user to add query indexes for the objects to be added in the cache.
The following command adds ProductID, ProductName, Category, Supplier and UnitsAvailable attributes from the class Data.Product in query indexes for demoClusteredCache.
Add-QueryIndex demoClusteredCache -AssemblyPath C:\Data.dll -Class Data.Product -Attributes ProductID$ProductName$Category$UnitsAvailable
Manually Editing NCache Configuration
Important
Make sure the cache is stopped before making any configuration changes.
- Specify the query indexes through config.ncconf by adding the
<query-indexes>
and<query-class>
tag under the<cache-settings>
tag. The following example adds attributes of two classes, Product and Customer, as indexes:
<cache-settings ...>
<query-indexes>
<query-class id="Data.Customer" name="Data.Customer">
<query-attributes id="CustomerName" name="CustomerName" data-type="System.String"/>
<query-attributes id="CustomerID" name="CustomerID" data-type="System.Int32"/>
</query-class>
<query-class id="Data.Product" name="Data.Product">
<query-attributes id="ProductName" name="ProductName" data-type="System.String"/>
<query-attributes id="ProductID" name="ProductID" data-type="System.Int32"/>
<query-attributes id="Category" name="Category" data-type="System.String"/>
<query-attributes id="UnitsAvailable" name="UnitsAvailable" data-type="System.Int32"/>
</query-class>
</query-indexes>
</cache-settings>
- Once changes are made, start the cache and restart NCache service.
Removing Query Indexes
Pre-defined query indexes can be removed by the user using the following steps.
Using NCache Web Manager
Launch NCache Web Manager by browsing to
http://localhost:8251
(Windows) or<server-ip>:8251
(Windows + Linux).In the left navigation bar, click on Clustered Caches or Local Caches, based on the cache to which the query index will be added. Against the cache name, click on View Details.
This opens up the detailed configuration page for the cache. Go to the Advanced Settings tab and click on Query Indexes in the left bar.
This opens up the Query Indexes page which shows existing classes for query indexes.
Select the classes to remove and click on Remove.
- Click on Save Changes to apply this configuration to the cache.
Using PowerShell
Remove-QueryIndex cmdlet enables the user to remove pre-defined query indexes for the objects to be added in the cache.
The following command removes query indexing for the class Customers from the cache demoClusteredCache.
Remove-QueryIndex -CacheName demoClusteredCache -Class Data.Customer
Using Tools (Java)
- Open the NCache tools directory using the following command:
$cd ~/%NCHOME%/bin/tools
- Use the
addcompacttype
tool to register custom objects for compact serialization.
./AddqueryindexdemoCache -a ~/Data.jar –c alachisoft.sample.data.Product -L “ProductID$ProductName$Category$Supplier$UnitsAvailable”
./AddqueryindexdemoCache -a ~/Data.jar –c alachisoft.sample.data.Customer -L “CustomerID$CompanyName”
It will add ProductID, ProductName, Category, Supplier and UnitsAvailable attributes from the classes in query indexes for demoCache.
See Also
Create a Cache
Remove Cache
Remove Server Node
Add Test Data